diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a12b9b73..af6fc0c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,8 @@ at anytime. * ### Changed - * - * + * keep track of failures for DHT peers for up to ten minutes instead of indefinitely + * skip ignored peers from iterative lookups instead of blocking the peer who returned them to us too ### Added * diff --git a/lbrynet/dht/constants.py b/lbrynet/dht/constants.py index bf48d005c..28b17e74d 100644 --- a/lbrynet/dht/constants.py +++ b/lbrynet/dht/constants.py @@ -29,6 +29,8 @@ rpcTimeout = 5 # number of rpc attempts to make before a timeout results in the node being removed as a contact rpcAttempts = 5 +# time window to count failures (in seconds) +rpcAttemptsPruningTimeWindow = 600 # Delay between iterations of iterative node lookups (for loose parallelism) (in seconds) iterativeLookupDelay = rpcTimeout / 2 diff --git a/lbrynet/dht/contact.py b/lbrynet/dht/contact.py index 51eb10fe1..2df93a675 100644 --- a/lbrynet/dht/contact.py +++ b/lbrynet/dht/contact.py @@ -185,5 +185,12 @@ class ContactManager(object): return contact def is_ignored(self, origin_tuple): - failed_rpc_count = len(self._rpc_failures.get(origin_tuple, [])) + failed_rpc_count = len(self._prune_failures(origin_tuple)) return failed_rpc_count > constants.rpcAttempts + + def _prune_failures(self, origin_tuple): + # Prunes recorded failures to the last time window of attempts + pruning_limit = self._get_time() - constants.rpcAttemptsPruningTimeWindow + pruned = list(filter(lambda t: t >= pruning_limit, self._rpc_failures.get(origin_tuple, []))) + self._rpc_failures[origin_tuple] = pruned + return pruned diff --git a/lbrynet/dht/iterativefind.py b/lbrynet/dht/iterativefind.py index 5b0e9c992..f1158d10d 100644 --- a/lbrynet/dht/iterativefind.py +++ b/lbrynet/dht/iterativefind.py @@ -110,7 +110,7 @@ class _IterativeFind(object): if (contactTriple[1], contactTriple[2]) in ((c.address, c.port) for c in self.already_contacted): continue elif self.node.contact_manager.is_ignored((contactTriple[1], contactTriple[2])): - raise ValueError("contact is ignored") + continue else: found_contact = self.node.contact_manager.make_contact(contactTriple[0], contactTriple[1], contactTriple[2], self.node._protocol)