From 7818c6a04e5083d639cd1a0310d457cb09ca5220 Mon Sep 17 00:00:00 2001 From: anonpenguin Date: Thu, 14 Aug 2025 14:20:08 +0300 Subject: [PATCH] Skip bootstrap connection if address resolves to self --- pkg/client/connect_bootstrap.go | 10 ++++++++++ pkg/node/node.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/client/connect_bootstrap.go b/pkg/client/connect_bootstrap.go index a3b0713..9f7d1f1 100644 --- a/pkg/client/connect_bootstrap.go +++ b/pkg/client/connect_bootstrap.go @@ -23,6 +23,16 @@ func (c *Client) connectToBootstrap(ctx context.Context, addr string) error { return c.connectToAddress(ctx, ma) } + // Avoid dialing ourselves: if the bootstrap address resolves to our own peer ID, skip. + c.logger.Debug(string(peerInfo.ID)) + c.logger.Debug(string(c.host.ID())) + if c.host != nil && peerInfo.ID == c.host.ID() { + c.logger.Debug("Skipping bootstrap address because it resolves to self", + zap.String("addr", addr), + zap.String("peer", peerInfo.ID.String())) + return nil + } + if err := c.host.Connect(ctx, *peerInfo); err != nil { return fmt.Errorf("failed to connect to peer: %w", err) } diff --git a/pkg/node/node.go b/pkg/node/node.go index 74148f7..e78c048 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -154,6 +154,14 @@ func (n *Node) connectToBootstrapPeer(ctx context.Context, addr string) error { return fmt.Errorf("failed to extract peer info: %w", err) } + // Avoid dialing ourselves: if the bootstrap address resolves to our own peer ID, skip. + if n.host != nil && peerInfo.ID == n.host.ID() { + n.logger.ComponentDebug(logging.ComponentNode, "Skipping bootstrap address because it resolves to self", + zap.String("addr", addr), + zap.String("peer_id", peerInfo.ID.String())) + return nil + } + // Log resolved peer info prior to connect n.logger.ComponentDebug(logging.ComponentNode, "Resolved bootstrap peer", zap.String("peer_id", peerInfo.ID.String()),