forked from LBRYCommunity/lbry-sdk
fix remaining length of close nodes list
This commit is contained in:
parent
ee90c877c7
commit
e89f3db31b
1 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue