reduce routing table ping flood

This commit is contained in:
Victor Shyba 2018-10-01 13:57:39 -03:00
parent 673d259d7a
commit 1adce8b227
2 changed files with 10 additions and 3 deletions

View file

@ -67,7 +67,7 @@ class _Contact:
@property @property
def lastFailed(self): def lastFailed(self):
return self._contactManager._rpc_failures.get((self.address, self.port), [None])[-1] return (self.failures or [None])[-1]
@property @property
def failures(self): def failures(self):

View file

@ -48,6 +48,7 @@ class TreeRoutingTable:
from twisted.internet import reactor from twisted.internet import reactor
getTime = reactor.seconds getTime = reactor.seconds
self._getTime = getTime self._getTime = getTime
self._ongoing_replacements = set()
def get_contacts(self): def get_contacts(self):
contacts = [] contacts = []
@ -134,8 +135,14 @@ class TreeRoutingTable:
to_replace = not_good_contacts[0] to_replace = not_good_contacts[0]
else: else:
to_replace = self._buckets[bucketIndex]._contacts[0] to_replace = self._buckets[bucketIndex]._contacts[0]
if to_replace not in self._ongoing_replacements:
log.debug("pinging %s:%s", to_replace.address, to_replace.port)
self._ongoing_replacements.add(to_replace)
df = to_replace.ping() df = to_replace.ping()
df.addErrback(replaceContact, to_replace) df.addErrback(replaceContact, to_replace)
df.addBoth(lambda _: self._ongoing_replacements.remove(to_replace))
else:
df = defer.succeed(None)
return df return df
else: else:
self.touchKBucketByIndex(bucketIndex) self.touchKBucketByIndex(bucketIndex)