From 673d1c4d43b0914cae6cf2ecc08c10ad62588d78 Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Wed, 25 Oct 2017 09:02:50 +0800 Subject: [PATCH 1/3] 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 From e89f3db31bb576dd3915fece38434279c8e2037b Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 27 Oct 2017 21:46:17 -0400 Subject: [PATCH 2/3] fix remaining length of close nodes list --- lbrynet/dht/routingtable.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index ec2ee75e0..a23d68370 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -135,17 +135,21 @@ class TreeRoutingTable(object): i = 1 canGoLower = bucketIndex - i >= 0 canGoHigher = bucketIndex + i < len(self._buckets) + + def get_remain(closest): + return min(count, constants.k) - len(closest) + # 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: + if canGoLower and len(closestNodes) < min(count, constants.k): closestNodes.extend( - self._buckets[bucketIndex - i].getContacts(remain, _rpcNodeID)) + self._buckets[bucketIndex - i].getContacts(get_remain(closestNodes), + _rpcNodeID)) canGoLower = bucketIndex - (i + 1) >= 0 - if canGoHigher: - closestNodes.extend( - self._buckets[bucketIndex + i].getContacts(remain, _rpcNodeID)) + if canGoHigher and len(closestNodes) < min(count, constants.k): + closestNodes.extend(self._buckets[bucketIndex + i].getContacts( + get_remain(closestNodes), _rpcNodeID)) canGoHigher = bucketIndex + (i + 1) < len(self._buckets) i += 1 return closestNodes From fdaaa0e6783253073f72bacb048e2820145bed9a Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 27 Oct 2017 21:46:55 -0400 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 10 +--------- lbrynet/dht/routingtable.py | 2 ++ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7557286b4..fbac72659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,16 +13,8 @@ at anytime. * ### Fixed + * Fixed amount of close nodes to add to list in case of extension to neighbouring k-buckets * - * - * Fixed slow startup for nodes with many lbry files - * Fixed setting the external ip on startup - * Fixed session startup not blocking on joining the dht - * Fixed several parsing bugs that prevented replacing dead dht contacts - * 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 a23d68370..1c73c5360 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -142,6 +142,8 @@ 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 + # TODO: add "key" kwarg to getContacts() to sort contacts returned by xor distance + # to the key if canGoLower and len(closestNodes) < min(count, constants.k): closestNodes.extend( self._buckets[bucketIndex - i].getContacts(get_remain(closestNodes),