diff --git a/exchange/bitswap/network/ipfs_impl.go b/exchange/bitswap/network/ipfs_impl.go index ea98cc87fbf..4415cf8cf85 100644 --- a/exchange/bitswap/network/ipfs_impl.go +++ b/exchange/bitswap/network/ipfs_impl.go @@ -112,7 +112,9 @@ func (bsnet *impl) FindProvidersAsync(ctx context.Context, k util.Key, max int) defer close(out) providers := bsnet.routing.FindProvidersAsync(ctx, k, max) for info := range providers { - bsnet.host.Peerstore().AddAddresses(info.ID, info.Addrs) + if info.ID != bsnet.host.ID() { // dont add addrs for ourselves. + bsnet.host.Peerstore().AddAddresses(info.ID, info.Addrs) + } select { case <-ctx.Done(): return diff --git a/routing/dht/handlers.go b/routing/dht/handlers.go index 59e30d39848..28df3aea6b9 100644 --- a/routing/dht/handlers.go +++ b/routing/dht/handlers.go @@ -236,9 +236,9 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M } log.Infof("received provider %s for %s (addrs: %s)", p, key, pi.Addrs) - for _, maddr := range pi.Addrs { + if pi.ID != dht.self { // dont add own addrs. // add the received addresses to our peerstore. - dht.peerstore.AddAddress(p, maddr) + dht.peerstore.AddPeerInfo(pi) } dht.providers.AddProvider(key, p) } diff --git a/routing/dht/query.go b/routing/dht/query.go index 44dc499263b..6ac8fefe894 100644 --- a/routing/dht/query.go +++ b/routing/dht/query.go @@ -254,6 +254,11 @@ func (r *dhtQueryRunner) queryPeer(cg ctxgroup.ContextGroup, p peer.ID) { } else if len(res.closerPeers) > 0 { log.Debugf("PEERS CLOSER -- worker for: %v (%d closer peers)", p, len(res.closerPeers)) for _, next := range res.closerPeers { + if next.ID == r.query.dht.self { // dont add self. + log.Debugf("PEERS CLOSER -- worker for: %v found self", p) + continue + } + // add their addresses to the dialer's peerstore r.query.dht.peerstore.AddPeerInfo(next) r.addPeerToQuery(cg.Context(), next.ID) diff --git a/routing/dht/routing.go b/routing/dht/routing.go index 4a2cc351860..3c72da49495 100644 --- a/routing/dht/routing.go +++ b/routing/dht/routing.go @@ -223,8 +223,10 @@ func (dht *IpfsDHT) closerPeersSingle(ctx context.Context, key u.Key, p peer.ID) var out []peer.ID for _, pbp := range pmes.GetCloserPeers() { pid := peer.ID(pbp.GetId()) - dht.peerstore.AddAddresses(pid, pbp.Addresses()) - out = append(out, pid) + if pid != dht.self { // dont add self + dht.peerstore.AddAddresses(pid, pbp.Addresses()) + out = append(out, pid) + } } return out, nil }