From d18bdf33cecb933a524509d879e3b3d24f861fe3 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 19 Nov 2024 16:35:40 +0100 Subject: [PATCH] bitswap: handle dialing to self --- bitswap/network/ipfs_impl.go | 3 +++ routing/providerquerymanager/providerquerymanager.go | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bitswap/network/ipfs_impl.go b/bitswap/network/ipfs_impl.go index 7b52485f9a..993b644294 100644 --- a/bitswap/network/ipfs_impl.go +++ b/bitswap/network/ipfs_impl.go @@ -359,6 +359,9 @@ func (bsnet *impl) Stop() { } func (bsnet *impl) Connect(ctx context.Context, p peer.AddrInfo) error { + if p.ID == bsnet.host.ID() { + return nil + } return bsnet.host.Connect(ctx, p) } diff --git a/routing/providerquerymanager/providerquerymanager.go b/routing/providerquerymanager/providerquerymanager.go index 6ffd9c178b..435a72dd50 100644 --- a/routing/providerquerymanager/providerquerymanager.go +++ b/routing/providerquerymanager/providerquerymanager.go @@ -8,6 +8,7 @@ import ( "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" peer "github.com/libp2p/go-libp2p/core/peer" + swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -300,7 +301,7 @@ func (pqm *ProviderQueryManager) findProviderWorker() { defer wg.Done() span.AddEvent("FoundProvider", trace.WithAttributes(attribute.Stringer("peer", p.ID))) err := pqm.dialer.Connect(findProviderCtx, p) - if err != nil { + if err != nil && err != swarm.ErrDialToSelf { span.RecordError(err, trace.WithAttributes(attribute.Stringer("peer", p.ID))) log.Debugf("failed to connect to provider %s: %s", p.ID, err) return