Fix duplicates in returned values of a lookup

This commit is contained in:
kdeme 2020-02-19 13:11:19 +01:00 committed by zah
parent 3dd26e8526
commit 5aebab3f41
2 changed files with 11 additions and 2 deletions

View File

@ -5,6 +5,9 @@ import
import nimcrypto except toHex
logScope:
topics = "discv5"
type
Protocol* = ref object
transp: DatagramTransport
@ -247,12 +250,17 @@ proc lookupWorker(p: Protocol, destNode: Node, target: NodeId): Future[seq[Node]
discard p.routingTable.addNode(n)
proc lookup(p: Protocol, target: NodeId): Future[seq[Node]] {.async.} =
result = p.routingTable.neighbours(target, 16)
## Perform a lookup for the given target, return the closest n nodes to the
## target. Maximum value for n is `BUCKET_SIZE`.
# TODO: Sort the returned nodes on distance
result = p.routingTable.neighbours(target, BUCKET_SIZE)
var asked = initHashSet[NodeId]()
asked.incl(p.localNode.id)
var seen = asked
for node in result:
seen.incl(node.id)
const alpha = 3
const alpha = 3 # Kademlia concurrency factor
var pendingQueries = newSeqOfCap[Future[seq[Node]]](alpha)

View File

@ -43,6 +43,7 @@ suite "Discovery v5 Tests":
for node in nodes:
let discovered = await node.lookupRandom()
check discovered.len < nodes.len
debug "Lookup from random id", node=node.localNode, discovered
# Check for each node if the other nodes shows up in the routing table