mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-11-09 16:00:27 +00:00
add uploaded_by, JS map fixes
This commit is contained in:
parent
3478a0023c
commit
26343b47fb
@ -31,22 +31,22 @@ class NodeDB:
|
||||
node.ip, node.label, node.version, now, now,
|
||||
node.label, node.version, now))
|
||||
|
||||
def insert_edge(self, edge):
|
||||
def insert_edge(self, edge, uploaded_by):
|
||||
now = int(time.time())
|
||||
self.cur.execute('''
|
||||
INSERT INTO edges (a, b, first_seen, last_seen)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
INSERT INTO edges (a, b, first_seen, last_seen, uploaded_by)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
ON DUPLICATE KEY
|
||||
UPDATE last_seen = %s''', (
|
||||
edge.a.ip, edge.b.ip, now, now,
|
||||
now))
|
||||
edge.a.ip, edge.b.ip, now, now, uploaded_by,
|
||||
now))
|
||||
|
||||
def insert_graph(self, nodes, edges):
|
||||
def insert_graph(self, nodes, edges, uploaded_by):
|
||||
for n in nodes.itervalues():
|
||||
self.insert_node(n)
|
||||
|
||||
for e in edges:
|
||||
self.insert_edge(e)
|
||||
self.insert_edge(e, uploaded_by)
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ CREATE TABLE `edges` (
|
||||
`b` varchar(39) NOT NULL,
|
||||
`first_seen` int(11) NOT NULL,
|
||||
`last_seen` int(11) NOT NULL,
|
||||
`uploaded_by` varchar(200) NOT NULL,
|
||||
PRIMARY KEY (`a`,`b`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
@ -34,9 +34,11 @@ def insert_graph_data(config, data, mail, ip):
|
||||
if len(nodes) == 0 or len(edges) == 0:
|
||||
return 'No valid nodes or edges'
|
||||
|
||||
uploaded_by = ip
|
||||
|
||||
try:
|
||||
with NodeDB(config) as db:
|
||||
db.insert_graph(nodes, edges)
|
||||
db.insert_graph(nodes, edges, uploaded_by)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
return 'Database failure'
|
||||
|
@ -204,7 +204,7 @@ $(document).ready(function() {
|
||||
|
||||
jQuery.getJSON('/static/graph.json', function(data) {
|
||||
nodes = data.nodes;
|
||||
edges = data.edges;
|
||||
edges = data.edges;
|
||||
|
||||
// Calculate node radiuses
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
@ -222,6 +222,7 @@ $(document).ready(function() {
|
||||
node.textColor = node.color;
|
||||
}
|
||||
|
||||
var newEdges = []
|
||||
// Find node references for edges
|
||||
for (var i = 0; i < edges.length; ++i) {
|
||||
var edge = edges[i];
|
||||
@ -235,13 +236,17 @@ $(document).ready(function() {
|
||||
edge.targetNode = nodes[n];
|
||||
}
|
||||
|
||||
if (!edge.sourceNode || !edge.targetNode)
|
||||
continue;
|
||||
|
||||
edge.sourceNode.edges.push(edge);
|
||||
edge.targetNode.edges.push(edge);
|
||||
edge.sourceNode.peers.push(edge.targetNode);
|
||||
edge.targetNode.peers.push(edge.sourceNode);
|
||||
|
||||
newEdges.push(edge);
|
||||
}
|
||||
|
||||
|
||||
edges = newEdges;
|
||||
|
||||
// Set update time
|
||||
var delta = Math.round(new Date().getTime() / 1000) - data.created;
|
||||
|
Loading…
Reference in New Issue
Block a user