Merge branch 'dht_failure_pruning'

This commit is contained in:
Jack Robison 2018-07-13 12:02:30 -04:00
commit 7365bfad9f
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 13 additions and 4 deletions

View file

@ -21,8 +21,8 @@ at anytime.
* *
### Changed ### 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 ### Added
* *

View file

@ -29,6 +29,8 @@ rpcTimeout = 5
# number of rpc attempts to make before a timeout results in the node being removed as a contact # number of rpc attempts to make before a timeout results in the node being removed as a contact
rpcAttempts = 5 rpcAttempts = 5
# time window to count failures (in seconds)
rpcAttemptsPruningTimeWindow = 600
# Delay between iterations of iterative node lookups (for loose parallelism) (in seconds) # Delay between iterations of iterative node lookups (for loose parallelism) (in seconds)
iterativeLookupDelay = rpcTimeout / 2 iterativeLookupDelay = rpcTimeout / 2

View file

@ -185,5 +185,12 @@ class ContactManager(object):
return contact return contact
def is_ignored(self, origin_tuple): 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 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

View file

@ -110,7 +110,7 @@ class _IterativeFind(object):
if (contactTriple[1], contactTriple[2]) in ((c.address, c.port) for c in self.already_contacted): if (contactTriple[1], contactTriple[2]) in ((c.address, c.port) for c in self.already_contacted):
continue continue
elif self.node.contact_manager.is_ignored((contactTriple[1], contactTriple[2])): elif self.node.contact_manager.is_ignored((contactTriple[1], contactTriple[2])):
raise ValueError("contact is ignored") continue
else: else:
found_contact = self.node.contact_manager.make_contact(contactTriple[0], contactTriple[1], found_contact = self.node.contact_manager.make_contact(contactTriple[0], contactTriple[1],
contactTriple[2], self.node._protocol) contactTriple[2], self.node._protocol)