use PingQueue to try refresh all contacts

This commit is contained in:
Jack Robison 2018-05-23 18:11:41 -04:00
parent 9920ff59d4
commit 4f72098cad
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 7 additions and 1 deletions

View file

@ -650,14 +650,19 @@ class Node(MockKademliaHelper):
def _refreshNode(self):
""" Periodically called to perform k-bucket refreshes and data
replication/republishing as necessary """
yield self._refreshRoutingTable()
self._dataStore.removeExpiredPeers()
defer.returnValue(None)
def _refreshContacts(self):
return defer.DeferredList(
[self._protocol._ping_queue.enqueue_maybe_ping(contact) for contact in self.contacts]
)
@defer.inlineCallbacks
def _refreshRoutingTable(self):
nodeIDs = self._routingTable.getRefreshList(0, True)
yield self._refreshContacts()
while nodeIDs:
searchID = nodeIDs.pop()
yield self.iterativeFindNode(searchID)

View file

@ -85,6 +85,7 @@ class PingQueue(object):
def enqueue_maybe_ping(self, contact):
return self._semaphore.run(self._add_contact, contact)
class KademliaProtocol(protocol.DatagramProtocol):
""" Implements all low-level network-related functions of a Kademlia node """