From 5c7d27910435bfa57f124f0bdb8d235cc28b14f1 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 12 Jul 2018 18:24:59 -0300 Subject: [PATCH] prune failures during is_ignored calls --- lbrynet/dht/constants.py | 2 ++ lbrynet/dht/contact.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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