Merge remote-tracking branch 'origin/reduce_routing_table_ping_flood'

This commit is contained in:
Jack Robison 2018-10-08 09:15:30 -04:00
commit 20221e1186
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 11 additions and 4 deletions

View file

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

View file

@ -220,7 +220,7 @@ class Node(MockKademliaHelper):
if not bootstrap_contacts:
log.warning("no bootstrap contacts to ping")
ping_result = yield _ping_contacts(bootstrap_contacts)
shortlist = ping_result.keys()
shortlist = list(ping_result.keys())
if not shortlist:
log.warning("failed to ping %i bootstrap contacts", len(bootstrap_contacts))
defer.returnValue(None)

View file

@ -48,6 +48,7 @@ class TreeRoutingTable:
from twisted.internet import reactor
getTime = reactor.seconds
self._getTime = getTime
self._ongoing_replacements = set()
def get_contacts(self):
contacts = []
@ -134,8 +135,14 @@ class TreeRoutingTable:
to_replace = not_good_contacts[0]
else:
to_replace = self._buckets[bucketIndex]._contacts[0]
df = to_replace.ping()
df.addErrback(replaceContact, to_replace)
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.addErrback(replaceContact, to_replace)
df.addBoth(lambda _: self._ongoing_replacements.remove(to_replace))
else:
df = defer.succeed(None)
return df
else:
self.touchKBucketByIndex(bucketIndex)