From de1dc507ac8564ec8ff318536194d88e192aee55 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 10 Oct 2017 13:21:06 -0400 Subject: [PATCH] fix findCloseNodes when buckets aren't fully populated --- lbrynet/dht/routingtable.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 5ac8cd129..6564b3647 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -123,7 +123,11 @@ class TreeRoutingTable(object): @rtype: list """ bucketIndex = self._kbucketIndex(key) - closestNodes = self._buckets[bucketIndex].getContacts(constants.k, _rpcNodeID) + + if bucketIndex < len(self._buckets): + closestNodes = self._buckets[bucketIndex].getContacts(count, _rpcNodeID) + else: + closestNodes = [] # This method must return k contacts (even if we have the node # with the specified key as node ID), unless there is less # than k remote nodes in the routing table