From 673d1c4d43b0914cae6cf2ecc08c10ad62588d78 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Wed, 25 Oct 2017 09:02:50 +0800 Subject: [PATCH] Extend close nodes list by right amount When a k-bucket does not contain enough close nodes, the DHT will look into neighbouring k-buckets in order to entend the list of returned nodes. However, the list should not be extended beyond its maximum size. Signed-off-by: Antonio Quartulli --- CHANGELOG.md | 1 + lbrynet/dht/routingtable.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 521e31ee0..d11053e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ at anytime. * Fixed lbryid length validation * Fixed an old print statement that polluted logs * Fixed rpc id length for dht requests + * Fixed amount of closed nodes to add to list in case of extension to neighbouring k-buckets ### Deprecated * diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 8f3661f49..ec2ee75e0 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -138,15 +138,14 @@ class TreeRoutingTable(object): # Fill up the node list to k nodes, starting with the closest neighbouring nodes known while len(closestNodes) < min(count, constants.k) and (canGoLower or canGoHigher): # TODO: this may need to be optimized + remain = min(count, constants.k) - len(closestNodes) if canGoLower: closestNodes.extend( - self._buckets[bucketIndex - i].getContacts( - constants.k - len(closestNodes), _rpcNodeID)) + self._buckets[bucketIndex - i].getContacts(remain, _rpcNodeID)) canGoLower = bucketIndex - (i + 1) >= 0 if canGoHigher: closestNodes.extend( - self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes), - _rpcNodeID)) + self._buckets[bucketIndex + i].getContacts(remain, _rpcNodeID)) canGoHigher = bucketIndex + (i + 1) < len(self._buckets) i += 1 return closestNodes