mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-31 09:21:29 +00:00
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
|
i = 1
|
||||||
canGoLower = bucketIndex - i >= 0
|
canGoLower = bucketIndex - i >= 0
|
||||||
canGoHigher = bucketIndex + i < len(self._buckets)
|
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
|
# 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):
|
while len(closestNodes) < min(count, constants.k) and (canGoLower or canGoHigher):
|
||||||
# TODO: this may need to be optimized
|
# TODO: this may need to be optimized
|
||||||
remain = min(count, constants.k) - len(closestNodes)
|
if canGoLower and len(closestNodes) < min(count, constants.k):
|
||||||
if canGoLower:
|
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
self._buckets[bucketIndex - i].getContacts(remain, _rpcNodeID))
|
self._buckets[bucketIndex - i].getContacts(get_remain(closestNodes),
|
||||||
|
_rpcNodeID))
|
||||||
canGoLower = bucketIndex - (i + 1) >= 0
|
canGoLower = bucketIndex - (i + 1) >= 0
|
||||||
if canGoHigher:
|
if canGoHigher and len(closestNodes) < min(count, constants.k):
|
||||||
closestNodes.extend(
|
closestNodes.extend(self._buckets[bucketIndex + i].getContacts(
|
||||||
self._buckets[bucketIndex + i].getContacts(remain, _rpcNodeID))
|
get_remain(closestNodes), _rpcNodeID))
|
||||||
canGoHigher = bucketIndex + (i + 1) < len(self._buckets)
|
canGoHigher = bucketIndex + (i + 1) < len(self._buckets)
|
||||||
i += 1
|
i += 1
|
||||||
return closestNodes
|
return closestNodes
|
||||||
|
|
Loading…
Add table
Reference in a new issue