5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-25 02:01:35 +00:00

fix infinite loop

This commit is contained in:
Michał Zieliński 2015-11-30 22:25:23 +01:00
parent 64791fb8a0
commit 2bad4d8b39

View File

@ -145,7 +145,8 @@ def get_peers(con, path, nearbyPath=''):
formatted_path = '{:s} (nearby {:s})'.format(path, nearbyPath) formatted_path = '{:s} (nearby {:s})'.format(path, nearbyPath)
i = 1 i = 1
while i < 4: retry = 2
while i < retry + 1:
if nearbyPath: if nearbyPath:
res = con.RouterModule_getPeers(path, nearbyPath=nearbyPath) res = con.RouterModule_getPeers(path, nearbyPath=nearbyPath)
else: else:
@ -154,10 +155,10 @@ def get_peers(con, path, nearbyPath=''):
if res['error'] != 'none': if res['error'] != 'none':
print('get_peers: failed with error `{:s}` on {:s}, trying again. {:d} tries remaining.' print('get_peers: failed with error `{:s}` on {:s}, trying again. {:d} tries remaining.'
.format(res['error'], formatted_path, 3-i)) .format(res['error'], formatted_path, retry-i))
elif res['result'] == 'timeout': elif res['result'] == 'timeout':
print('get_peers: timed out on {:s}, trying again. {:d} tries remaining.' print('get_peers: timed out on {:s}, trying again. {:d} tries remaining.'
.format(formatted_path, 3-i)) .format(formatted_path, retry-i))
else: else:
return res['peers'] return res['peers']
@ -179,13 +180,22 @@ def get_all_peers(con, path):
return keys return keys
last_peer = res[-1] last_peer = res[-1]
checked_paths = set()
while len(res) > 1: while len(res) > 1:
last_path = (last_peer.split('.', 1)[1] last_path = (last_peer.split('.', 1)[1]
.rsplit('.', 2)[0]) .rsplit('.', 2)[0])
if last_path in checked_paths:
break
else:
checked_paths.add(last_path)
res = get_peers(con, path, last_path) res = get_peers(con, path, last_path)
if res: if res:
last_peer = res[-1] last_peer = res[-1]
else:
break
peers.update(res) peers.update(res)