Connect first to best peers based on ping time

This commit is contained in:
shortcutme 2017-03-02 23:39:52 +01:00
parent 36db8a4dc9
commit 2efb6cf4f1
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 3 additions and 1 deletions

View File

@ -157,7 +157,9 @@ class WorkerManager(object):
if type(peers) is set:
peers = list(peers)
random.shuffle(peers)
# Sort by ping
peers.sort(key = lambda peer: peer.connection.last_ping_delay if peer.connection and len(peer.connection.waiting_requests) == 0 else 9999)
for peer in peers: # One worker for every peer
if peers and peer not in peers:
continue # If peers defined and peer not valid