From ab956d4a8ec238de492866627e6b83d16f12910f Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 10 Oct 2017 13:20:19 -0400 Subject: [PATCH] use count parameter in findCloseNodes --- lbrynet/dht/node.py | 3 ++- lbrynet/dht/routingtable.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index c261a6595..7ea3d3947 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -578,11 +578,12 @@ class Node(object): findValue = rpc != 'findNode' if startupShortlist is None: - shortlist = self._routingTable.findCloseNodes(key, constants.alpha) + shortlist = self._routingTable.findCloseNodes(key, constants.k) if key != self.node_id: # Update the "last accessed" timestamp for the appropriate k-bucket self._routingTable.touchKBucket(key) if len(shortlist) == 0: + log.warning("This node doesnt know any other nodes") # This node doesn't know of any other nodes fakeDf = defer.Deferred() fakeDf.callback([]) diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 636899f32..5ac8cd129 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -131,7 +131,7 @@ class TreeRoutingTable(object): canGoLower = bucketIndex - i >= 0 canGoHigher = bucketIndex + i < len(self._buckets) # Fill up the node list to k nodes, starting with the closest neighbouring nodes known - while len(closestNodes) < constants.k and (canGoLower or canGoHigher): + while len(closestNodes) < min(count, constants.k) and (canGoLower or canGoHigher): # TODO: this may need to be optimized if canGoLower: closestNodes.extend( @@ -140,8 +140,8 @@ class TreeRoutingTable(object): canGoLower = bucketIndex - (i + 1) >= 0 if canGoHigher: closestNodes.extend( - self._buckets[bucketIndex + i].getContacts( - constants.k - len(closestNodes), _rpcNodeID)) + self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes), + _rpcNodeID)) canGoHigher = bucketIndex + (i + 1) < len(self._buckets) i += 1 return closestNodes