mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
p2p: wrap internal error in new error type
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
f5e0eadad2
commit
f2020470f2
2 changed files with 10 additions and 5 deletions
|
|
@ -68,6 +68,7 @@ func markDialError(err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var e *protoHandshakeError
|
||||
switch {
|
||||
case errors.Is(err, DiscTooManyPeers):
|
||||
dialTooManyPeers.Mark(1)
|
||||
|
|
@ -81,7 +82,7 @@ func markDialError(err error) {
|
|||
dialUnexpectedIdentity.Mark(1)
|
||||
case errors.Is(err, errEncHandshakeError):
|
||||
dialEncHandshakeError.Mark(1)
|
||||
case errors.Is(err, errProtoHandshakeError):
|
||||
case errors.As(err, &e):
|
||||
dialProtoHandshakeError.Mark(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,11 +66,15 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
errServerStopped = errors.New("server stopped")
|
||||
errEncHandshakeError = errors.New("rlpx enc error")
|
||||
errProtoHandshakeError = errors.New("rlpx proto error")
|
||||
errServerStopped = errors.New("server stopped")
|
||||
errEncHandshakeError = errors.New("rlpx enc error")
|
||||
)
|
||||
|
||||
type protoHandshakeError struct{ err error }
|
||||
|
||||
func (e *protoHandshakeError) Error() string { return fmt.Sprintf("rlpx proto error: %s", e.err) }
|
||||
func (e *protoHandshakeError) Unwrap() error { return e.err }
|
||||
|
||||
// Server manages all peer connections.
|
||||
type Server struct {
|
||||
// Config fields may not be modified while the server is running.
|
||||
|
|
@ -908,7 +912,7 @@ func (srv *Server) setupConn(c *conn, dialDest *enode.Node) error {
|
|||
if err != nil {
|
||||
clog.Trace("Failed p2p handshake", "err", err)
|
||||
//Wrapping both errors for later inspection
|
||||
return fmt.Errorf("%w: %w", errProtoHandshakeError, err)
|
||||
return &protoHandshakeError{err: err}
|
||||
}
|
||||
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) {
|
||||
clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID))
|
||||
|
|
|
|||
Loading…
Reference in a new issue