5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-14 03:50:27 +00:00

Merge pull request #10 from kyrias/sG-fixes

sendGraph: Get all peers using nearbyPath argument to getPeers
This commit is contained in:
Michał Zieliński 2015-11-30 22:06:38 +01:00
commit 64791fb8a0

View File

@ -87,7 +87,7 @@ def worker(nodes, get_peer_queue, result, verbose=False):
print('fetch', node) print('fetch', node)
node_ip = node['ip'] node_ip = node['ip']
peers = get_peers(con, node['path']) peers = get_all_peers(con, node['path'])
result.put((peers, node_ip)) result.put((peers, node_ip))
@ -139,43 +139,61 @@ def dump_node_store(con):
return nodes return nodes
def get_peers(con, path): def get_peers(con, path, nearbyPath=''):
peers = set() formatted_path = path
if nearbyPath:
formatted_path = '{:s} (nearby {:s})'.format(path, nearbyPath)
i = 1 i = 1
while i < 3: while i < 4:
if nearbyPath:
res = con.RouterModule_getPeers(path, nearbyPath=nearbyPath)
else:
res = con.RouterModule_getPeers(path) res = con.RouterModule_getPeers(path)
if ('result' in res and res['result'] == 'timeout') or \
('error' in res and res['error'] != 'none'):
failure = ''
if 'error' in res:
failure = res['error']
if 'result' in res:
if len(failure) != 0:
failure += '/'
failure += res['result']
print('get_peers: getPeers failed with {:s} on {:s}, trying again. {:d} tries remaining.' if res['error'] != 'none':
.format(failure, path, 2 - i)) print('get_peers: failed with error `{:s}` on {:s}, trying again. {:d} tries remaining.'
.format(res['error'], formatted_path, 3-i))
elif res['result'] == 'timeout':
print('get_peers: timed out on {:s}, trying again. {:d} tries remaining.'
.format(formatted_path, 3-i))
else:
return res['peers']
i += 1 i += 1
continue
else:
break
if 'result' not in res or res['result'] != 'peers': print('get_peers: timed out on final try, skipping {:s}'
if 'result' in res and res['result'] == 'timeout': .format(formatted_path))
print('get_peers: timed out on final try, skipping.') return []
else:
print('get_peers: failed too many times, skipping. Last response: {:s}'
.format(str(res)))
return peers
for peer in res['peers']:
def get_all_peers(con, path):
peers = set()
keys = set()
res = get_peers(con, path)
peers.update(res)
if not res:
return keys
last_peer = res[-1]
while len(res) > 1:
last_path = (last_peer.split('.', 1)[1]
.rsplit('.', 2)[0])
res = get_peers(con, path, last_path)
if res:
last_peer = res[-1]
peers.update(res)
for peer in peers:
key = peer.split('.', 5)[-1] key = peer.split('.', 5)[-1]
peers |= {key} keys |= {key}
return peers return keys
def get_edges_for_peers(edges, peers, node_ip): def get_edges_for_peers(edges, peers, node_ip):