p2p: update

This commit is contained in:
Felix Lange 2025-04-15 11:19:49 +02:00
parent 071d9a4ca6
commit d2fce766f3

View file

@ -64,35 +64,33 @@ var (
dialOtherError = metrics.NewRegisteredMeter("p2p/dials/error/other", nil) dialOtherError = metrics.NewRegisteredMeter("p2p/dials/error/other", nil)
) )
// markDialError matches errors that occur while setting up a dial connection // markDialError matches errors that occur while setting up a dial connection to the
// to the corresponding meter. // corresponding meter. We don't maintain meters for evert possible error, just for
// markDialError will bump exactly one meter per call. We don't maintain meters // the most interesting ones.
// for evert possible error. If there are multiple levels of wrapped errors, we
// capture the innermost for which we have a meter.
func markDialError(err error) { func markDialError(err error) {
if !metrics.Enabled() { if !metrics.Enabled() {
return return
} }
var phe *protoHandshakeError var reason DiscReason
var handshakeErr *protoHandshakeError
d := errors.As(err, &reason)
switch { switch {
case errors.Is(err, DiscTooManyPeers): case d && reason == DiscTooManyPeers:
dialTooManyPeers.Mark(1) dialTooManyPeers.Mark(1)
case errors.Is(err, DiscAlreadyConnected): case d && reason == DiscAlreadyConnected:
dialAlreadyConnected.Mark(1) dialAlreadyConnected.Mark(1)
case errors.Is(err, DiscSelf): case d && reason == DiscSelf:
dialSelf.Mark(1) dialSelf.Mark(1)
case errors.Is(err, DiscUselessPeer): case d && reason == DiscUselessPeer:
dialUselessPeer.Mark(1) dialUselessPeer.Mark(1)
case errors.Is(err, DiscUnexpectedIdentity): case d && reason == DiscUnexpectedIdentity:
dialUnexpectedIdentity.Mark(1) dialUnexpectedIdentity.Mark(1)
case errors.As(err, &handshakeErr):
dialProtoHandshakeError.Mark(1)
case errors.Is(err, errEncHandshakeError): case errors.Is(err, errEncHandshakeError):
dialEncHandshakeError.Mark(1) dialEncHandshakeError.Mark(1)
case errors.As(err, &phe):
dialProtoHandshakeError.Mark(1)
default: default:
// dialOtherError is a catch-all for any other error, which are not supposed to happen.
// Only here for cross-checking that all errors are captured by the above meters.
dialOtherError.Mark(1) dialOtherError.Mark(1)
} }
} }