From 7d6120fb0d6706c4ca76f5b3228747e0749670f5 Mon Sep 17 00:00:00 2001 From: guillaumemichel Date: Wed, 27 Mar 2024 16:57:40 +0100 Subject: [PATCH] findnode(self) now returns multiple peers --- handlers.go | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/handlers.go b/handlers.go index ad4db1bdb..c2d496728 100644 --- a/handlers.go +++ b/handlers.go @@ -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 {