Skip bootstrap connection if address resolves to self

This commit is contained in:
anonpenguin 2025-08-14 14:20:08 +03:00
parent 0b60ac0791
commit 7818c6a04e
2 changed files with 18 additions and 0 deletions

View File

@ -23,6 +23,16 @@ func (c *Client) connectToBootstrap(ctx context.Context, addr string) error {
return c.connectToAddress(ctx, ma) 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 { if err := c.host.Connect(ctx, *peerInfo); err != nil {
return fmt.Errorf("failed to connect to peer: %w", err) return fmt.Errorf("failed to connect to peer: %w", err)
} }

View File

@ -154,6 +154,14 @@ func (n *Node) connectToBootstrapPeer(ctx context.Context, addr string) error {
return fmt.Errorf("failed to extract peer info: %w", err) 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 // Log resolved peer info prior to connect
n.logger.ComponentDebug(logging.ComponentNode, "Resolved bootstrap peer", n.logger.ComponentDebug(logging.ComponentNode, "Resolved bootstrap peer",
zap.String("peer_id", peerInfo.ID.String()), zap.String("peer_id", peerInfo.ID.String()),