Skip to content

Commit

Permalink
Merge pull request #968 from libp2p/fix/findnode_self_response
Browse files Browse the repository at this point in the history
findnode(self) should return multiple peers
  • Loading branch information
guillaumemichel committed Apr 3, 2024
2 parents 1b5d0b6 + 7d6120f commit 7fc6a1d
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// 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)
}
}

if closest == nil {
Expand Down

0 comments on commit 7fc6a1d

Please sign in to comment.