Skip to content

Commit

Permalink
Faster and better getConnectedpeers
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Feb 26, 2017
1 parent 0f8de2b commit 2e9737c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Site/Site.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,16 @@ def getRecentPeers(self, need_num):
return found[0:need_num]

def getConnectedPeers(self):
return [peer for peer in self.peers.values() if peer.connection and peer.connection.connected]
back = []
for connection in self.connection_server.connections:
if not connection.connected and time.time() - connection.start_time > 20: # Still not connected after 20s
continue
peer = self.peers.get("%s:%s" % (connection.ip, connection.port))
if peer:
if not peer.connection:
peer.connect(connection)
back.append(peer)
return back

# Cleanup probably dead peers and close connection if too much
def cleanupPeers(self):
Expand Down

0 comments on commit 2e9737c

Please sign in to comment.