findnode(self) should return multiple peers#968
Conversation
sukunrt
left a comment
There was a problem hiding this comment.
Should we add a test for this?
| } | ||
| if !found { | ||
| closest = append(closest, targetPid) | ||
| closest = dht.betterPeersToQuery(pmes, from, dht.bucketSize) |
There was a problem hiding this comment.
dht.betterPeersToQuery errors if the list contains self.
https://github.com/libp2p/go-libp2p-kad-dht/blob/master/dht.go#L765-L769
if clp == dht.self {
logger.Error("BUG betterPeersToQuery: attempted to return self! this shouldn't happen...")
return nil
}
// Dont send a peer back themselves
if clp == from {
continue
}
It also handles the case that we don't inform the peer about itself.
There was a problem hiding this comment.
This snippet handles the output of routingTable.NearestPeers, which never contains itself.
The peer adds it own peer id, only if its own peer id is the target of the FIND_NODE request at
Lines 263 to 285 in 7d6120f
| if !found { | ||
| closest = append(closest, targetPid) | ||
| } |
There was a problem hiding this comment.
Why do we do this? If the peerID isn't found, should we return it in findPeer?
There was a problem hiding this comment.
dht.betterPeersToQuery never includes itself (nor from) in the results.
Currently if A sends FIND_NODE(B) to B, B will reply [B], and we now want it to return [B, C, D, ...]. In this case targetPid is our own peer id, it wasn't returned by dht.betterPeersToQuery, so we need to add it at this step.
We will be able to get rid of this when the response to FIND_NODE(self) will be not include self.
There was a problem hiding this comment.
But if the target node doesnt exist we will include it in the output, right?
There was a problem hiding this comment.
Peers without addresses are excluded from the response
Lines 292 to 301 in 7d6120f
When receiving a kademlia
FIND_NODErequest for its own peer id, a go-libp2p-kad-dht node will respond with its own peer record only. According to libp2p kademlia spec, it should reply with thekclosest nodes.Depending on libp2p/specs#609, nodes shouldn't even include their own peer records in the response (already known to the requester). This will be implemented in a future PR.