forked from LBRYCommunity/lbry-sdk
Merge branch 'ordex-dht-fix-close-nodes-list-extension'
This commit is contained in:
commit
c39568f488
2 changed files with 13 additions and 8 deletions
|
@ -13,7 +13,7 @@ at anytime.
|
||||||
*
|
*
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
*
|
* Fixed amount of close nodes to add to list in case of extension to neighbouring k-buckets
|
||||||
*
|
*
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
|
@ -135,18 +135,23 @@ 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
|
||||||
if canGoLower:
|
# TODO: add "key" kwarg to getContacts() to sort contacts returned by xor distance
|
||||||
|
# to the key
|
||||||
|
if canGoLower and len(closestNodes) < min(count, constants.k):
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
self._buckets[bucketIndex - i].getContacts(
|
self._buckets[bucketIndex - i].getContacts(get_remain(closestNodes),
|
||||||
constants.k - len(closestNodes), _rpcNodeID))
|
|
||||||
canGoLower = bucketIndex - (i + 1) >= 0
|
|
||||||
if canGoHigher:
|
|
||||||
closestNodes.extend(
|
|
||||||
self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes),
|
|
||||||
_rpcNodeID))
|
_rpcNodeID))
|
||||||
|
canGoLower = bucketIndex - (i + 1) >= 0
|
||||||
|
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)
|
canGoHigher = bucketIndex + (i + 1) < len(self._buckets)
|
||||||
i += 1
|
i += 1
|
||||||
return closestNodes
|
return closestNodes
|
||||||
|
|
Loading…
Add table
Reference in a new issue