|
|
@ -601,7 +601,6 @@ func (r *Router) openConnection(ctx context.Context, conn Connection) { |
|
|
|
r.logger.Error("peer handshake failed", "endpoint", conn, "err", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := r.filterPeersID(ctx, peerInfo.NodeID); err != nil { |
|
|
|
r.logger.Debug("peer filtered by node ID", "node", peerInfo.NodeID, "err", err) |
|
|
|
return |
|
|
@ -688,11 +687,17 @@ func (r *Router) connectPeer(ctx context.Context, address NodeAddress) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
_, _, err = r.handshakePeer(ctx, conn, address.NodeID) |
|
|
|
peerInfo, _, err := r.handshakePeer(ctx, conn, address.NodeID) |
|
|
|
var errRejected ErrRejected |
|
|
|
switch { |
|
|
|
case errors.Is(err, context.Canceled): |
|
|
|
conn.Close() |
|
|
|
return |
|
|
|
case errors.As(err, &errRejected) && errRejected.IsIncompatible(): |
|
|
|
r.logger.Error("peer rejected due to incompatibility", "node", peerInfo.NodeID, "err", err) |
|
|
|
r.peerManager.Errored(peerInfo.NodeID, err) |
|
|
|
conn.Close() |
|
|
|
return |
|
|
|
case err != nil: |
|
|
|
r.logger.Error("failed to handshake with peer", "peer", address, "err", err) |
|
|
|
if err = r.peerManager.DialFailed(address); err != nil { |
|
|
@ -795,7 +800,6 @@ func (r *Router) handshakePeer( |
|
|
|
if err != nil { |
|
|
|
return peerInfo, peerKey, err |
|
|
|
} |
|
|
|
|
|
|
|
if err = peerInfo.Validate(); err != nil { |
|
|
|
return peerInfo, peerKey, fmt.Errorf("invalid handshake NodeInfo: %w", err) |
|
|
|
} |
|
|
@ -807,6 +811,13 @@ func (r *Router) handshakePeer( |
|
|
|
return peerInfo, peerKey, fmt.Errorf("expected to connect with peer %q, got %q", |
|
|
|
expectID, peerInfo.NodeID) |
|
|
|
} |
|
|
|
if err := r.nodeInfo.CompatibleWith(peerInfo); err != nil { |
|
|
|
return peerInfo, peerKey, ErrRejected{ |
|
|
|
err: err, |
|
|
|
id: peerInfo.ID(), |
|
|
|
isIncompatible: true, |
|
|
|
} |
|
|
|
} |
|
|
|
return peerInfo, peerKey, nil |
|
|
|
} |
|
|
|
|
|
|
|