Merge branch 'ordex-dht-fix-close-nodes-list-extension'

This commit is contained in:
Jack Robison 2017-10-30 13:10:04 -04:00
commit c39568f488
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
2 changed files with 13 additions and 8 deletions

View file

@ -13,7 +13,7 @@ at anytime.
*
### Fixed
*
* Fixed amount of close nodes to add to list in case of extension to neighbouring k-buckets
*
### Deprecated

View file

@ -135,18 +135,23 @@ 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
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(
self._buckets[bucketIndex - i].getContacts(
constants.k - len(closestNodes), _rpcNodeID))
canGoLower = bucketIndex - (i + 1) >= 0
if canGoHigher:
closestNodes.extend(
self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes),
self._buckets[bucketIndex - i].getContacts(get_remain(closestNodes),
_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)
i += 1
return closestNodes