-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findnode(self) should return multiple peers #968
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -262,30 +262,26 @@ func (dht *IpfsDHT) handleFindPeer(ctx context.Context, from peer.ID, pmes *pb.M | |||||||||||||||||||||
|
||||||||||||||||||||||
// if looking for self... special case where we send it on CloserPeers. | ||||||||||||||||||||||
targetPid := peer.ID(pmes.GetKey()) | ||||||||||||||||||||||
if targetPid == dht.self { | ||||||||||||||||||||||
closest = []peer.ID{dht.self} | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
closest = dht.betterPeersToQuery(pmes, from, dht.bucketSize) | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Never tell a peer about itself. | ||||||||||||||||||||||
if targetPid != from { | ||||||||||||||||||||||
// Add the target peer to the set of closest peers if | ||||||||||||||||||||||
// not already present in our routing table. | ||||||||||||||||||||||
// | ||||||||||||||||||||||
// Later, when we lookup known addresses for all peers | ||||||||||||||||||||||
// in this set, we'll prune this peer if we don't | ||||||||||||||||||||||
// _actually_ know where it is. | ||||||||||||||||||||||
found := false | ||||||||||||||||||||||
for _, p := range closest { | ||||||||||||||||||||||
if targetPid == p { | ||||||||||||||||||||||
found = true | ||||||||||||||||||||||
break | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if !found { | ||||||||||||||||||||||
closest = append(closest, targetPid) | ||||||||||||||||||||||
closest = dht.betterPeersToQuery(pmes, from, dht.bucketSize) | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Never tell a peer about itself. | ||||||||||||||||||||||
if targetPid != from { | ||||||||||||||||||||||
sukunrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
// Add the target peer to the set of closest peers if | ||||||||||||||||||||||
// not already present in our routing table. | ||||||||||||||||||||||
// | ||||||||||||||||||||||
// Later, when we lookup known addresses for all peers | ||||||||||||||||||||||
// in this set, we'll prune this peer if we don't | ||||||||||||||||||||||
// _actually_ know where it is. | ||||||||||||||||||||||
found := false | ||||||||||||||||||||||
for _, p := range closest { | ||||||||||||||||||||||
if targetPid == p { | ||||||||||||||||||||||
found = true | ||||||||||||||||||||||
break | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if !found { | ||||||||||||||||||||||
closest = append(closest, targetPid) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+282
to
+284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we do this? If the peerID isn't found, should we return it in findPeer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Currently if We will be able to get rid of this when the response to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if the target node doesnt exist we will include it in the output, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Peers without addresses are excluded from the response Lines 292 to 301 in 7d6120f
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if closest == nil { | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dht.betterPeersToQuery
errors if the list contains self.https://github.com/libp2p/go-libp2p-kad-dht/blob/master/dht.go#L765-L769
It also handles the case that we don't inform the peer about itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 atgo-libp2p-kad-dht/handlers.go
Lines 263 to 285 in 7d6120f