From 2a47385b62efa4c519f67c7094f8d3f56bc556b5 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 10 Oct 2017 13:16:26 -0400 Subject: [PATCH] add rpcAttempts and replacementCacheSize constants --- lbrynet/dht/constants.py | 6 ++++++ lbrynet/dht/routingtable.py | 7 ++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lbrynet/dht/constants.py b/lbrynet/dht/constants.py index 1cee46311..b3d19022b 100644 --- a/lbrynet/dht/constants.py +++ b/lbrynet/dht/constants.py @@ -21,9 +21,15 @@ alpha = 3 #: Maximum number of contacts stored in a bucket; this should be an even number k = 8 +#: Maximum number of contacts stored in the replacement cache +replacementCacheSize = 8 + #: Timeout for network operations (in seconds) rpcTimeout = 5 +# number of rpc attempts to make before a timeout results in the node being removed as a contact +rpcAttempts = 5 + # Delay between iterations of iterative node lookups (for loose parallelism) (in seconds) iterativeLookupDelay = rpcTimeout / 2 diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index c03dd0fd0..636899f32 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -320,10 +320,7 @@ class OptimizedTreeRoutingTable(TreeRoutingTable): self._replacementCache[bucketIndex] = [] if contact in self._replacementCache[bucketIndex]: self._replacementCache[bucketIndex].remove(contact) - # TODO: Using k to limit the size of the contact - # replacement cache - maybe define a separate value for - # this in constants.py? - elif len(self._replacementCache[bucketIndex]) >= constants.k: + elif len(self._replacementCache[bucketIndex]) >= constants.replacementCacheSize: self._replacementCache[bucketIndex].pop(0) self._replacementCache[bucketIndex].append(contact) @@ -340,7 +337,7 @@ class OptimizedTreeRoutingTable(TreeRoutingTable): except ValueError: return contact.failedRPCs += 1 - if contact.failedRPCs >= 5: + if contact.failedRPCs >= constants.rpcAttempts: self._buckets[bucketIndex].removeContact(contactID) # Replace this stale contact with one from our replacement cache, if we have any if bucketIndex in self._replacementCache: