feat(swarm)!: introduce ListenError (#3375)

In case an error happens for an outgoing connection, `Pool` reports an `OutgoingConnectionError`. This one is mapped to a `DialError` and reported via `SwarmEvent::OutgoingConnectionError` and `FromSwarm::DialFailure`.

For incoming connections, we didn't quite do the same thing. For one, `SwarmEvent::IncomingConnectionError` directly contained a `PendingInboundConnectionError`. Two, `FromSwarm::ListenFailure` did not include an error at all.

With this patch, we now introduce a `ListenError` enum which we use in `SwarmEvent::IncomingConnectionError` and we pass a reference to it along in `FromSwarm::ListenFailure`.
This commit is contained in:
Thomas Eizinger
2023-01-27 10:23:55 +11:00
committed by GitHub
parent e55202200c
commit d1336a7d81
6 changed files with 124 additions and 43 deletions

View File

@ -214,37 +214,35 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
match error {
libp2p_core::transport::TransportError::MultiaddrNotSupported(
_,
) => record(
OutgoingConnectionErrorError::TransportMultiaddrNotSupported,
),
) => {
record(OutgoingConnectionError::TransportMultiaddrNotSupported)
}
libp2p_core::transport::TransportError::Other(_) => {
record(OutgoingConnectionErrorError::TransportOther)
record(OutgoingConnectionError::TransportOther)
}
};
}
}
libp2p_swarm::DialError::Banned => record(OutgoingConnectionErrorError::Banned),
libp2p_swarm::DialError::Banned => record(OutgoingConnectionError::Banned),
libp2p_swarm::DialError::ConnectionLimit(_) => {
record(OutgoingConnectionErrorError::ConnectionLimit)
record(OutgoingConnectionError::ConnectionLimit)
}
libp2p_swarm::DialError::LocalPeerId { .. } => {
record(OutgoingConnectionErrorError::LocalPeerId)
record(OutgoingConnectionError::LocalPeerId)
}
libp2p_swarm::DialError::NoAddresses => {
record(OutgoingConnectionErrorError::NoAddresses)
record(OutgoingConnectionError::NoAddresses)
}
libp2p_swarm::DialError::DialPeerConditionFalse(_) => {
record(OutgoingConnectionErrorError::DialPeerConditionFalse)
}
libp2p_swarm::DialError::Aborted => {
record(OutgoingConnectionErrorError::Aborted)
record(OutgoingConnectionError::DialPeerConditionFalse)
}
libp2p_swarm::DialError::Aborted => record(OutgoingConnectionError::Aborted),
libp2p_swarm::DialError::InvalidPeerId { .. } => {
record(OutgoingConnectionErrorError::InvalidPeerId)
record(OutgoingConnectionError::InvalidPeerId)
}
libp2p_swarm::DialError::WrongPeerId { .. } => {
record(OutgoingConnectionErrorError::WrongPeerId)
record(OutgoingConnectionError::WrongPeerId)
}
};
}
@ -325,7 +323,7 @@ impl From<&libp2p_core::ConnectedPoint> for Role {
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
struct OutgoingConnectionErrorLabels {
peer: PeerStatus,
error: OutgoingConnectionErrorError,
error: OutgoingConnectionError,
}
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Copy, Debug)]
@ -335,7 +333,7 @@ enum PeerStatus {
}
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
enum OutgoingConnectionErrorError {
enum OutgoingConnectionError {
Banned,
ConnectionLimit,
LocalPeerId,
@ -350,12 +348,12 @@ enum OutgoingConnectionErrorError {
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
struct IncomingConnectionErrorLabels {
error: PendingInboundConnectionError,
error: IncomingConnectionError,
protocols: String,
}
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
enum PendingInboundConnectionError {
enum IncomingConnectionError {
WrongPeerId,
LocalPeerId,
TransportErrorMultiaddrNotSupported,
@ -364,27 +362,21 @@ enum PendingInboundConnectionError {
ConnectionLimit,
}
impl From<&libp2p_swarm::PendingInboundConnectionError> for PendingInboundConnectionError {
fn from(error: &libp2p_swarm::PendingInboundConnectionError) -> Self {
impl From<&libp2p_swarm::ListenError> for IncomingConnectionError {
fn from(error: &libp2p_swarm::ListenError) -> Self {
match error {
libp2p_swarm::PendingInboundConnectionError::WrongPeerId { .. } => {
PendingInboundConnectionError::WrongPeerId
libp2p_swarm::ListenError::WrongPeerId { .. } => IncomingConnectionError::WrongPeerId,
libp2p_swarm::ListenError::ConnectionLimit(_) => {
IncomingConnectionError::ConnectionLimit
}
libp2p_swarm::PendingInboundConnectionError::LocalPeerId { .. } => {
PendingInboundConnectionError::LocalPeerId
}
libp2p_swarm::PendingInboundConnectionError::ConnectionLimit(_) => {
PendingInboundConnectionError::ConnectionLimit
}
libp2p_swarm::PendingInboundConnectionError::Transport(
libp2p_swarm::ListenError::LocalPeerId { .. } => IncomingConnectionError::LocalPeerId,
libp2p_swarm::ListenError::Transport(
libp2p_core::transport::TransportError::MultiaddrNotSupported(_),
) => PendingInboundConnectionError::TransportErrorMultiaddrNotSupported,
libp2p_swarm::PendingInboundConnectionError::Transport(
) => IncomingConnectionError::TransportErrorMultiaddrNotSupported,
libp2p_swarm::ListenError::Transport(
libp2p_core::transport::TransportError::Other(_),
) => PendingInboundConnectionError::TransportErrorOther,
libp2p_swarm::PendingInboundConnectionError::Aborted => {
PendingInboundConnectionError::Aborted
}
) => IncomingConnectionError::TransportErrorOther,
libp2p_swarm::ListenError::Aborted => IncomingConnectionError::Aborted,
}
}
}