mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-11-22 12:50:27 +00:00
Use multiple nodes
This commit is contained in:
parent
380e7bb3dd
commit
2203cc1138
99
makeGraph.py
99
makeGraph.py
@ -11,18 +11,62 @@ import json
|
|||||||
import time
|
import time
|
||||||
import httplib2
|
import httplib2
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
def __init__(self, ip):
|
||||||
|
self.ip = ip
|
||||||
|
self.version = -1
|
||||||
|
self.label = ip[-4:]
|
||||||
|
|
||||||
cjdns = admin.connect()
|
def __lt__(self, b):
|
||||||
root = admin.whoami(cjdns)
|
return self.ip < b.ip
|
||||||
rootIP = root['IP']
|
|
||||||
|
|
||||||
G = pgv.AGraph(strict=True, directed=False, size='10!')
|
class Edge:
|
||||||
G.add_node(rootIP, label=rootIP[-4:])
|
def __init__(self, a, b):
|
||||||
|
self.a, self.b = sorted([a, b])
|
||||||
|
|
||||||
nodes = deque()
|
all_nodes = dict()
|
||||||
nodes.append(rootIP)
|
all_edges = []
|
||||||
|
these_nodes = dict()
|
||||||
|
these_edges = []
|
||||||
|
|
||||||
while len(nodes) != 0:
|
def add_node(node):
|
||||||
|
if not node in all_nodes:
|
||||||
|
all_nodes[node.ip] = node
|
||||||
|
if not node in these_nodes:
|
||||||
|
these_nodes[node.ip] = node
|
||||||
|
|
||||||
|
def add_edge(e):
|
||||||
|
all_edges.append(e)
|
||||||
|
these_edges.append(e)
|
||||||
|
|
||||||
|
def has_edge(a, b):
|
||||||
|
a, b = sorted([a, b])
|
||||||
|
|
||||||
|
for e in these_edges:
|
||||||
|
if e.a.ip == a and e.b.ip == b:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
for port in range(11244, 11245 + 35):
|
||||||
|
# for port in range(11247, 11248):
|
||||||
|
# G = pgv.AGraph(strict=True, directed=False, size='10!')
|
||||||
|
print port,
|
||||||
|
these_nodes = dict()
|
||||||
|
these_edges = []
|
||||||
|
cjdns = admin.connect('127.0.0.1', port, 'lmykvh031jl0h90wg9sp6vx1k76pkmu')
|
||||||
|
root = admin.whoami(cjdns)
|
||||||
|
rootIP = root['IP']
|
||||||
|
print rootIP
|
||||||
|
|
||||||
|
# if not rootIP in G.nodes():
|
||||||
|
# G.add_node(rootIP, label=rootIP[-4:])
|
||||||
|
add_node(Node(rootIP))
|
||||||
|
|
||||||
|
nodes = deque()
|
||||||
|
nodes.append(rootIP)
|
||||||
|
|
||||||
|
while len(nodes) != 0:
|
||||||
parentIP = nodes.popleft()
|
parentIP = nodes.popleft()
|
||||||
resp = cjdns.NodeStore_nodeForAddr(parentIP)
|
resp = cjdns.NodeStore_nodeForAddr(parentIP)
|
||||||
numLinks = 0
|
numLinks = 0
|
||||||
@ -31,11 +75,16 @@ while len(nodes) != 0:
|
|||||||
link = resp['result']
|
link = resp['result']
|
||||||
if 'linkCount' in link:
|
if 'linkCount' in link:
|
||||||
numLinks = int(resp['result']['linkCount'])
|
numLinks = int(resp['result']['linkCount'])
|
||||||
G.get_node(parentIP).attr['version'] = resp['result']['protocolVersion']
|
# G.get_node(parentIP).attr['version'] = resp['result']['protocolVersion']
|
||||||
|
all_nodes[parentIP].version = resp['result']['protocolVersion']
|
||||||
|
|
||||||
for i in range(0, numLinks):
|
for i in range(0, numLinks):
|
||||||
resp = cjdns.NodeStore_getLink(parentIP, i)
|
resp = cjdns.NodeStore_getLink(parentIP, i)
|
||||||
childLink = resp['result']
|
childLink = resp['result']
|
||||||
|
|
||||||
|
if not 'child' in childLink:
|
||||||
|
print 'No child'
|
||||||
|
continue
|
||||||
childIP = childLink['child']
|
childIP = childLink['child']
|
||||||
|
|
||||||
# Check to see if its one hop away from parent node
|
# Check to see if its one hop away from parent node
|
||||||
@ -43,17 +92,35 @@ while len(nodes) != 0:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# If its a new node then we want to follow it
|
# If its a new node then we want to follow it
|
||||||
if not childIP in G.nodes():
|
# if not childIP in G.nodes():
|
||||||
G.add_node(childIP, label=childIP[-4:])
|
if not childIP in these_nodes:
|
||||||
G.get_node(childIP).attr['version'] = 0
|
add_node(Node(childIP))
|
||||||
|
|
||||||
|
# G.add_node(childIP, label=childIP[-4:])
|
||||||
|
# G.get_node(childIP).attr['version'] = 0
|
||||||
nodes.append(childIP)
|
nodes.append(childIP)
|
||||||
|
|
||||||
# If there is not a link between the nodes we should put one there
|
# If there is not a link between the nodes we should put one there
|
||||||
if not G.has_edge(childIP, parentIP):
|
# if not G.has_edge(childIP, parentIP):
|
||||||
G.add_edge(parentIP, childIP, len=1.0)
|
if not has_edge(childIP, parentIP):
|
||||||
|
# all_edges.append(Edge(all_nodes[childIP], all_nodes[parentIP]))
|
||||||
|
add_edge(Edge(these_nodes[childIP], these_nodes[parentIP]))
|
||||||
|
# G.add_edge(parentIP, childIP, len=1.0)
|
||||||
|
# cjdns.disconnect()
|
||||||
|
|
||||||
print 'Number of nodes:', G.number_of_nodes()
|
print (len(these_nodes), len(these_edges))
|
||||||
print 'Number of edges:', G.number_of_edges()
|
# print 'Number of nodes:', G.number_of_nodes()
|
||||||
|
# print 'Number of edges:', G.number_of_edges()
|
||||||
|
|
||||||
|
print "Total", (len(all_nodes), len(all_edges))
|
||||||
|
|
||||||
|
G = pgv.AGraph(strict=True, directed=False, size='10!')
|
||||||
|
|
||||||
|
for n in all_nodes.values():
|
||||||
|
G.add_node(n.ip, label=n.label)
|
||||||
|
|
||||||
|
for e in all_edges:
|
||||||
|
G.add_edge(e.a.ip, e.b.ip, len=1.0)
|
||||||
|
|
||||||
G.layout(prog='neato', args='-Gepsilon=0.0001 -Gmaxiter=100000') # neato, fdp, dot
|
G.layout(prog='neato', args='-Gepsilon=0.0001 -Gmaxiter=100000') # neato, fdp, dot
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ function drawNetwork() {
|
|||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
var node = nodes[i];
|
var node = nodes[i];
|
||||||
|
|
||||||
if (node.radius > 2 || node.selected || node.hover) {
|
if (node.radius > 4 || node.selected || node.hover) {
|
||||||
var fontSize = 4 + node.radius * 0.4;
|
var fontSize = 4 + node.radius * 0.4;
|
||||||
|
|
||||||
drawText(ctx, node.x, node.y - node.radius - 1,
|
drawText(ctx, node.x, node.y - node.radius - 1,
|
||||||
@ -135,8 +135,8 @@ function markPeers(node, depth) {
|
|||||||
|
|
||||||
// var colors = ['#000000', '#333333', '#555555', '#777777', '#999999', '#BBBBBB', '#DDDDDD'];
|
// var colors = ['#000000', '#333333', '#555555', '#777777', '#999999', '#BBBBBB', '#DDDDDD'];
|
||||||
// var colors = ['#000000', '#29BBFF', '#09E844', '#FFBD0F', '#FF5E14', '#FF3C14', '#FF7357', '#FF9782', '#FFC8BD', '#FFE6E0'];
|
// var colors = ['#000000', '#29BBFF', '#09E844', '#FFBD0F', '#FF5E14', '#FF3C14', '#FF7357', '#FF9782', '#FFC8BD', '#FFE6E0'];
|
||||||
var colors = ['#000000', '#096EE8', '#09E8B8', '#36E809', '#ADE809', '#E8B809', '#E87509', '#E83A09'];
|
var colors = ['#000000', '#096EE8', '#09E8B8', '#36E809', '#ADE809', '#E8B809', '#E87509', '#E83A09', '#E86946', '#E8AC9B', '#E8C9C1'];
|
||||||
var txtCol = ['#000000', '#032247', '#034537', '#0E3D02', '#354703', '#403203', '#3D1F02', '#3B0E02'];
|
var txtCol = ['#000000', '#032247', '#034537', '#0E3D02', '#354703', '#403203', '#3D1F02', '#3B0E02', '#3B0E02', '#3B0E02', '#3B0E02'];
|
||||||
// var colors = ['#000000', '#064F8F', '#068F81', '#068F38', '#218F06', '#6F8F06', '#8F7806', '#8F5106'];
|
// var colors = ['#000000', '#064F8F', '#068F81', '#068F38', '#218F06', '#6F8F06', '#8F7806', '#8F5106'];
|
||||||
// var colors = ['#FFFFFF', '#29BBFF', '#17FF54', '#FFBD0F', '#FF3C14', '#590409'];
|
// var colors = ['#FFFFFF', '#29BBFF', '#17FF54', '#FFBD0F', '#FF3C14', '#590409'];
|
||||||
node.color = (depth >= colors.length) ? '#FFFFFF' : colors[depth];
|
node.color = (depth >= colors.length) ? '#FFFFFF' : colors[depth];
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
html, body {
|
html, body {
|
||||||
font-family: 'Source Sans Pro';
|
font-family: 'Source Sans Pro';
|
||||||
background: #F5F5F5;
|
background: #F5F5F5;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#header {
|
#header {
|
||||||
@ -99,7 +100,8 @@ li {
|
|||||||
/*bottom: 0;*/
|
/*bottom: 0;*/
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
/*overflow-y: scroll;*/
|
/*overflow-y: auto;*/
|
||||||
|
/*overflow: hidden;*/
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +137,11 @@ h2 {
|
|||||||
color: #29BBFF;
|
color: #29BBFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#node-info {
|
||||||
|
/*position: absolute;*/
|
||||||
|
/*overflow-y: scroll;*/
|
||||||
|
/*background: rgba(220, 220, 220, 0.8);*/
|
||||||
|
}
|
||||||
#node-info table {
|
#node-info table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user