Extend close nodes list by right amount
When a k-bucket does not contain enough close nodes, the DHT will look into neighbouring k-buckets in order to entend the list of returned nodes. However, the list should not be extended beyond its maximum size. Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
This commit is contained in:
parent
c63d368e1c
commit
673d1c4d43
2 changed files with 4 additions and 4 deletions
|
@ -20,6 +20,7 @@ at anytime.
|
||||||
* Fixed lbryid length validation
|
* Fixed lbryid length validation
|
||||||
* Fixed an old print statement that polluted logs
|
* Fixed an old print statement that polluted logs
|
||||||
* Fixed rpc id length for dht requests
|
* Fixed rpc id length for dht requests
|
||||||
|
* Fixed amount of closed nodes to add to list in case of extension to neighbouring k-buckets
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
*
|
*
|
||||||
|
|
|
@ -138,15 +138,14 @@ class TreeRoutingTable(object):
|
||||||
# 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:
|
if canGoLower:
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
self._buckets[bucketIndex - i].getContacts(
|
self._buckets[bucketIndex - i].getContacts(remain, _rpcNodeID))
|
||||||
constants.k - len(closestNodes), _rpcNodeID))
|
|
||||||
canGoLower = bucketIndex - (i + 1) >= 0
|
canGoLower = bucketIndex - (i + 1) >= 0
|
||||||
if canGoHigher:
|
if canGoHigher:
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes),
|
self._buckets[bucketIndex + i].getContacts(remain, _rpcNodeID))
|
||||||
_rpcNodeID))
|
|
||||||
canGoHigher = bucketIndex + (i + 1) < len(self._buckets)
|
canGoHigher = bucketIndex + (i + 1) < len(self._buckets)
|
||||||
i += 1
|
i += 1
|
||||||
return closestNodes
|
return closestNodes
|
||||||
|
|
Loading…
Reference in a new issue