5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-09 16:00:27 +00:00
This commit is contained in:
Arceliar 2021-05-23 12:52:59 -05:00
parent ee6b45de16
commit de7cdee064

View File

@ -15,9 +15,18 @@ else:
socktype = socket.AF_UNIX socktype = socket.AF_UNIX
sockaddr = "/var/run/yggdrasil.sock" sockaddr = "/var/run/yggdrasil.sock"
def getNodeInfoRequest(key):
return '{{"keepalive":true, "request":"getNodeInfo", "key":"{}"}}'.format(key)
def getSelfRequest(key):
return '{{"keepalive":true, "request":"debugGetSelf", "key":"{}"}}'.format(key)
def getPeersRequest(key): def getPeersRequest(key):
return '{{"keepalive":true, "request":"debugGetPeers", "key":"{}"}}'.format(key) return '{{"keepalive":true, "request":"debugGetPeers", "key":"{}"}}'.format(key)
def getDHTRequest(key):
return '{{"keepalive":true, "request":"debugGetDHT", "key":"{}"}}'.format(key)
def doRequest(req): def doRequest(req):
try: try:
ygg = socket.socket(socktype, socket.SOCK_STREAM) ygg = socket.socket(socktype, socket.SOCK_STREAM)
@ -31,7 +40,7 @@ def doRequest(req):
visited = set() # Add nodes after a successful lookup response visited = set() # Add nodes after a successful lookup response
rumored = set() # Add rumors about nodes to ping rumored = set() # Add rumors about nodes to ping
timedout = set() timedout = set()
def handleResponse(publicKey, data): def handleNodeInfoResponse(publicKey, data):
global visited global visited
global rumored global rumored
global timedout global timedout
@ -40,21 +49,24 @@ def handleResponse(publicKey, data):
if 'response' not in data: return if 'response' not in data: return
out = dict() out = dict()
for addr,v in data['response'].iteritems(): for addr,v in data['response'].iteritems():
if 'keys' not in v: continue
peers = v['keys']
for key in peers:
if key in visited: continue
if key in timedout: continue
rumored.add(key)
out['address'] = addr out['address'] = addr
out['peers'] = peers out['nodeinfo'] = v
break selfInfo = doRequest(getSelfRequest(publicKey))
selfInfo = doRequest('{{"keepalive":true, "request":"debugGetSelf", "key":"{}"}}'.format(publicKey))
if 'response' in selfInfo: if 'response' in selfInfo:
for _,v in selfInfo['response'].iteritems(): for _,v in selfInfo['response'].iteritems():
if 'coords' in v: if 'coords' in v:
out['coords'] = v['coords'] out['coords'] = v['coords']
dhtInfo = doRequest('{{"keepalive":true, "request":"debugGetDHT", "key":"{}"}}'.format(key)) peerInfo = doRequest(getPeersRequest(publicKey))
if 'response' in peerInfo:
for _,v in peerInfo['response'].iteritems():
if 'keys' not in v: continue
peers = v['keys']
for key in peers:
if key in visited: continue
if key in timedout: continue
rumored.add(key)
out['peers'] = peers
dhtInfo = doRequest(getDHTRequest(publicKey))
if 'response' in dhtInfo: if 'response' in dhtInfo:
for _,v in dhtInfo['response'].iteritems(): for _,v in dhtInfo['response'].iteritems():
if 'keys' in v: if 'keys' in v:
@ -63,11 +75,7 @@ def handleResponse(publicKey, data):
if key in visited: continue if key in visited: continue
if key in timedout: continue if key in timedout: continue
rumored.add(key) rumored.add(key)
out['dht'] = v['keys'] out['dht'] = dht
nodeInfo = doRequest('{{"keepalive":true, "request":"getNodeInfo", "key":"{}"}}'.format(publicKey))
if 'response' in nodeInfo:
for _,v in nodeInfo['response'].iteritems():
out['nodeinfo'] = v
out['time'] = time.time() out['time'] = time.time()
if len(visited) > 0: sys.stdout.write(",\n") if len(visited) > 0: sys.stdout.write(",\n")
sys.stdout.write('"{}": {}'.format(publicKey, json.dumps(out))) sys.stdout.write('"{}": {}'.format(publicKey, json.dumps(out)))
@ -86,7 +94,7 @@ for k,v in selfInfo['response']['self'].iteritems(): rumored.add(v['key'])
print '{"yggnodes": {' print '{"yggnodes": {'
while len(rumored) > 0: while len(rumored) > 0:
for k in rumored: for k in rumored:
handleResponse(k, doRequest(getPeersRequest(v['key']))) handleNodeInfoResponse(k, doRequest(getNodeInfoRequest(v['key'])))
break break
rumored.remove(k) rumored.remove(k)
print '\n}}' print '\n}}'