fix findCloseNodes when buckets aren't fully populated

This commit is contained in:
Jack Robison 2017-10-10 13:21:06 -04:00
parent ab956d4a8e
commit de1dc507ac
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF

View file

@ -123,7 +123,11 @@ class TreeRoutingTable(object):
@rtype: list @rtype: list
""" """
bucketIndex = self._kbucketIndex(key) 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 # This method must return k contacts (even if we have the node
# with the specified key as node ID), unless there is less # with the specified key as node ID), unless there is less
# than k remote nodes in the routing table # than k remote nodes in the routing table