mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 13:49:07 +00:00
Skip bootstrap connection if address resolves to self
This commit is contained in:
parent
0b60ac0791
commit
7818c6a04e
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user