use count parameter in findCloseNodes
This commit is contained in:
parent
7c50e26bd7
commit
ab956d4a8e
2 changed files with 5 additions and 4 deletions
|
@ -578,11 +578,12 @@ class Node(object):
|
||||||
findValue = rpc != 'findNode'
|
findValue = rpc != 'findNode'
|
||||||
|
|
||||||
if startupShortlist is None:
|
if startupShortlist is None:
|
||||||
shortlist = self._routingTable.findCloseNodes(key, constants.alpha)
|
shortlist = self._routingTable.findCloseNodes(key, constants.k)
|
||||||
if key != self.node_id:
|
if key != self.node_id:
|
||||||
# Update the "last accessed" timestamp for the appropriate k-bucket
|
# Update the "last accessed" timestamp for the appropriate k-bucket
|
||||||
self._routingTable.touchKBucket(key)
|
self._routingTable.touchKBucket(key)
|
||||||
if len(shortlist) == 0:
|
if len(shortlist) == 0:
|
||||||
|
log.warning("This node doesnt know any other nodes")
|
||||||
# This node doesn't know of any other nodes
|
# This node doesn't know of any other nodes
|
||||||
fakeDf = defer.Deferred()
|
fakeDf = defer.Deferred()
|
||||||
fakeDf.callback([])
|
fakeDf.callback([])
|
||||||
|
|
|
@ -131,7 +131,7 @@ class TreeRoutingTable(object):
|
||||||
canGoLower = bucketIndex - i >= 0
|
canGoLower = bucketIndex - i >= 0
|
||||||
canGoHigher = bucketIndex + i < len(self._buckets)
|
canGoHigher = bucketIndex + i < len(self._buckets)
|
||||||
# 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) < 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:
|
if canGoLower:
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
|
@ -140,8 +140,8 @@ class TreeRoutingTable(object):
|
||||||
canGoLower = bucketIndex - (i + 1) >= 0
|
canGoLower = bucketIndex - (i + 1) >= 0
|
||||||
if canGoHigher:
|
if canGoHigher:
|
||||||
closestNodes.extend(
|
closestNodes.extend(
|
||||||
self._buckets[bucketIndex + i].getContacts(
|
self._buckets[bucketIndex + i].getContacts(constants.k - len(closestNodes),
|
||||||
constants.k - len(closestNodes), _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…
Add table
Reference in a new issue