From 1adce8b227a0031e2d3aabc48a1f0276bdbd73f6 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 1 Oct 2018 13:57:39 -0300 Subject: [PATCH] reduce routing table ping flood --- lbrynet/dht/contact.py | 2 +- lbrynet/dht/routingtable.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lbrynet/dht/contact.py b/lbrynet/dht/contact.py index bc25fc5d5..99c84532b 100644 --- a/lbrynet/dht/contact.py +++ b/lbrynet/dht/contact.py @@ -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): diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 0d5deaa0a..9498b33be 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -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)