use maybe_ping for refreshing stale buckets and storing peers
-move store refresh to its own looping call
This commit is contained in:
parent
945da5985e
commit
9582b7fcf5
1 changed files with 6 additions and 6 deletions
|
@ -36,7 +36,6 @@ def expand_peer(compact_peer_info):
|
||||||
return (peer_node_id, host, port)
|
return (peer_node_id, host, port)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def rpcmethod(func):
|
def rpcmethod(func):
|
||||||
""" Decorator to expose Node methods as remote procedure calls
|
""" Decorator to expose Node methods as remote procedure calls
|
||||||
|
|
||||||
|
@ -132,6 +131,7 @@ class Node(MockKademliaHelper):
|
||||||
self.port = udpPort
|
self.port = udpPort
|
||||||
self._change_token_lc = self.get_looping_call(self.change_token)
|
self._change_token_lc = self.get_looping_call(self.change_token)
|
||||||
self._refresh_node_lc = self.get_looping_call(self._refreshNode)
|
self._refresh_node_lc = self.get_looping_call(self._refreshNode)
|
||||||
|
self._refresh_contacts_lc = self.get_looping_call(self._refreshContacts)
|
||||||
|
|
||||||
# Create k-buckets (for storing contacts)
|
# Create k-buckets (for storing contacts)
|
||||||
if routingTableClass is None:
|
if routingTableClass is None:
|
||||||
|
@ -164,6 +164,7 @@ class Node(MockKademliaHelper):
|
||||||
# stop LoopingCalls:
|
# stop LoopingCalls:
|
||||||
yield self.safe_stop_looping_call(self._refresh_node_lc)
|
yield self.safe_stop_looping_call(self._refresh_node_lc)
|
||||||
yield self.safe_stop_looping_call(self._change_token_lc)
|
yield self.safe_stop_looping_call(self._change_token_lc)
|
||||||
|
yield self.safe_stop_looping_call(self._refresh_contacts_lc)
|
||||||
if self._listeningPort is not None:
|
if self._listeningPort is not None:
|
||||||
yield self._listeningPort.stopListening()
|
yield self._listeningPort.stopListening()
|
||||||
self._listeningPort = None
|
self._listeningPort = None
|
||||||
|
@ -283,6 +284,7 @@ class Node(MockKademliaHelper):
|
||||||
self.safe_start_looping_call(self._change_token_lc, constants.tokenSecretChangeInterval)
|
self.safe_start_looping_call(self._change_token_lc, constants.tokenSecretChangeInterval)
|
||||||
# Start refreshing k-buckets periodically, if necessary
|
# Start refreshing k-buckets periodically, if necessary
|
||||||
self.safe_start_looping_call(self._refresh_node_lc, constants.checkRefreshInterval)
|
self.safe_start_looping_call(self._refresh_node_lc, constants.checkRefreshInterval)
|
||||||
|
self.safe_start_looping_call(self._refresh_contacts_lc, 60)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def contacts(self):
|
def contacts(self):
|
||||||
|
@ -664,20 +666,18 @@ class Node(MockKademliaHelper):
|
||||||
|
|
||||||
def _refreshContacts(self):
|
def _refreshContacts(self):
|
||||||
return defer.DeferredList(
|
return defer.DeferredList(
|
||||||
[contact.ping() for contact in self.contacts], consumeErrors=True
|
[self._protocol._ping_queue.enqueue_maybe_ping(contact, delay=0) for contact in self.contacts]
|
||||||
)
|
)
|
||||||
|
|
||||||
def _refreshStoringPeers(self):
|
def _refreshStoringPeers(self):
|
||||||
storing_contacts = self._dataStore.getStoringContacts()
|
storing_contacts = self._dataStore.getStoringContacts()
|
||||||
return defer.DeferredList(
|
return defer.DeferredList(
|
||||||
[self._protocol._ping_queue.enqueue_maybe_ping(contact) for contact in storing_contacts],
|
[self._protocol._ping_queue.enqueue_maybe_ping(contact, delay=0) for contact in storing_contacts]
|
||||||
consumeErrors=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _refreshRoutingTable(self):
|
def _refreshRoutingTable(self):
|
||||||
nodeIDs = self._routingTable.getRefreshList(0, True)
|
nodeIDs = self._routingTable.getRefreshList(0, False)
|
||||||
yield self._refreshContacts()
|
|
||||||
while nodeIDs:
|
while nodeIDs:
|
||||||
searchID = nodeIDs.pop()
|
searchID = nodeIDs.pop()
|
||||||
yield self.iterativeFindNode(searchID)
|
yield self.iterativeFindNode(searchID)
|
||||||
|
|
Loading…
Add table
Reference in a new issue