mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-29 18:51:22 +00:00
feat(swarm)!: report connections to our own PeerId
in separate error (#3377)
Previously, inbound connections that happened to resolve to our own `PeerId` were reported as `WrongPeerId`. With this patch, we now report those in a dedicated `LocalPeerId` error. Related: #3205.
This commit is contained in:
parent
90af08cb59
commit
9f7145912a
@ -228,7 +228,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
|
|||||||
libp2p_swarm::DialError::ConnectionLimit(_) => {
|
libp2p_swarm::DialError::ConnectionLimit(_) => {
|
||||||
record(OutgoingConnectionErrorError::ConnectionLimit)
|
record(OutgoingConnectionErrorError::ConnectionLimit)
|
||||||
}
|
}
|
||||||
libp2p_swarm::DialError::LocalPeerId => {
|
libp2p_swarm::DialError::LocalPeerId { .. } => {
|
||||||
record(OutgoingConnectionErrorError::LocalPeerId)
|
record(OutgoingConnectionErrorError::LocalPeerId)
|
||||||
}
|
}
|
||||||
libp2p_swarm::DialError::NoAddresses => {
|
libp2p_swarm::DialError::NoAddresses => {
|
||||||
@ -361,6 +361,7 @@ struct IncomingConnectionErrorLabels {
|
|||||||
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum PendingInboundConnectionError {
|
enum PendingInboundConnectionError {
|
||||||
WrongPeerId,
|
WrongPeerId,
|
||||||
|
LocalPeerId,
|
||||||
TransportErrorMultiaddrNotSupported,
|
TransportErrorMultiaddrNotSupported,
|
||||||
TransportErrorOther,
|
TransportErrorOther,
|
||||||
Aborted,
|
Aborted,
|
||||||
@ -373,6 +374,9 @@ impl From<&libp2p_swarm::PendingInboundConnectionError> for PendingInboundConnec
|
|||||||
libp2p_swarm::PendingInboundConnectionError::WrongPeerId { .. } => {
|
libp2p_swarm::PendingInboundConnectionError::WrongPeerId { .. } => {
|
||||||
PendingInboundConnectionError::WrongPeerId
|
PendingInboundConnectionError::WrongPeerId
|
||||||
}
|
}
|
||||||
|
libp2p_swarm::PendingInboundConnectionError::LocalPeerId { .. } => {
|
||||||
|
PendingInboundConnectionError::LocalPeerId
|
||||||
|
}
|
||||||
libp2p_swarm::PendingInboundConnectionError::ConnectionLimit(_) => {
|
libp2p_swarm::PendingInboundConnectionError::ConnectionLimit(_) => {
|
||||||
PendingInboundConnectionError::ConnectionLimit
|
PendingInboundConnectionError::ConnectionLimit
|
||||||
}
|
}
|
||||||
|
@ -1932,7 +1932,7 @@ where
|
|||||||
match error {
|
match error {
|
||||||
DialError::Banned
|
DialError::Banned
|
||||||
| DialError::ConnectionLimit(_)
|
| DialError::ConnectionLimit(_)
|
||||||
| DialError::LocalPeerId
|
| DialError::LocalPeerId { .. }
|
||||||
| DialError::InvalidPeerId { .. }
|
| DialError::InvalidPeerId { .. }
|
||||||
| DialError::WrongPeerId { .. }
|
| DialError::WrongPeerId { .. }
|
||||||
| DialError::Aborted
|
| DialError::Aborted
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
The default values remains 7.
|
The default values remains 7.
|
||||||
If you have previously set `connection_event_buffer_size` you should re-evaluate what a good size for a _per connection_ buffer is.
|
If you have previously set `connection_event_buffer_size` you should re-evaluate what a good size for a _per connection_ buffer is.
|
||||||
See [PR 3188].
|
See [PR 3188].
|
||||||
|
|
||||||
|
- Add `PendingConnectionError::LocalPeerId` to differentiate wrong VS local peer ID errors. See [PR 3377].
|
||||||
|
|
||||||
- Remove `PendingConnectionError:::IO` variant.
|
- Remove `PendingConnectionError:::IO` variant.
|
||||||
This was never constructed.
|
This was never constructed.
|
||||||
@ -35,6 +37,7 @@
|
|||||||
[PR 3272]: https://github.com/libp2p/rust-libp2p/pull/3272
|
[PR 3272]: https://github.com/libp2p/rust-libp2p/pull/3272
|
||||||
[PR 3327]: https://github.com/libp2p/rust-libp2p/pull/3327
|
[PR 3327]: https://github.com/libp2p/rust-libp2p/pull/3327
|
||||||
[PR 3188]: https://github.com/libp2p/rust-libp2p/pull/3188
|
[PR 3188]: https://github.com/libp2p/rust-libp2p/pull/3188
|
||||||
|
[PR 3377]: https://github.com/libp2p/rust-libp2p/pull/3377
|
||||||
[PR 3373]: https://github.com/libp2p/rust-libp2p/pull/3373
|
[PR 3373]: https://github.com/libp2p/rust-libp2p/pull/3373
|
||||||
|
|
||||||
# 0.41.1
|
# 0.41.1
|
||||||
|
@ -96,11 +96,14 @@ pub enum PendingConnectionError<TTransErr> {
|
|||||||
Aborted,
|
Aborted,
|
||||||
|
|
||||||
/// The peer identity obtained on the connection did not
|
/// The peer identity obtained on the connection did not
|
||||||
/// match the one that was expected or is the local one.
|
/// match the one that was expected.
|
||||||
WrongPeerId {
|
WrongPeerId {
|
||||||
obtained: PeerId,
|
obtained: PeerId,
|
||||||
endpoint: ConnectedPoint,
|
endpoint: ConnectedPoint,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// The connection was dropped because it resolved to our own [`PeerId`].
|
||||||
|
LocalPeerId { endpoint: ConnectedPoint },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> PendingConnectionError<T> {
|
impl<T> PendingConnectionError<T> {
|
||||||
@ -114,6 +117,9 @@ impl<T> PendingConnectionError<T> {
|
|||||||
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
||||||
PendingConnectionError::WrongPeerId { obtained, endpoint }
|
PendingConnectionError::WrongPeerId { obtained, endpoint }
|
||||||
}
|
}
|
||||||
|
PendingConnectionError::LocalPeerId { endpoint } => {
|
||||||
|
PendingConnectionError::LocalPeerId { endpoint }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,6 +146,9 @@ where
|
|||||||
"Pending connection: Unexpected peer ID {obtained} at {endpoint:?}."
|
"Pending connection: Unexpected peer ID {obtained} at {endpoint:?}."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
PendingConnectionError::LocalPeerId { endpoint } => {
|
||||||
|
write!(f, "Pending connection: Local peer ID at {endpoint:?}.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,6 +161,7 @@ where
|
|||||||
match self {
|
match self {
|
||||||
PendingConnectionError::Transport(_) => None,
|
PendingConnectionError::Transport(_) => None,
|
||||||
PendingConnectionError::WrongPeerId { .. } => None,
|
PendingConnectionError::WrongPeerId { .. } => None,
|
||||||
|
PendingConnectionError::LocalPeerId { .. } => None,
|
||||||
PendingConnectionError::Aborted => None,
|
PendingConnectionError::Aborted => None,
|
||||||
PendingConnectionError::ConnectionLimit(..) => None,
|
PendingConnectionError::ConnectionLimit(..) => None,
|
||||||
}
|
}
|
||||||
|
@ -686,8 +686,7 @@ where
|
|||||||
// Check peer is not local peer.
|
// Check peer is not local peer.
|
||||||
.and_then(|()| {
|
.and_then(|()| {
|
||||||
if self.local_id == obtained_peer_id {
|
if self.local_id == obtained_peer_id {
|
||||||
Err(PendingConnectionError::WrongPeerId {
|
Err(PendingConnectionError::LocalPeerId {
|
||||||
obtained: obtained_peer_id,
|
|
||||||
endpoint: endpoint.clone(),
|
endpoint: endpoint.clone(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -1580,8 +1580,8 @@ pub enum DialError {
|
|||||||
/// The configured limit for simultaneous outgoing connections
|
/// The configured limit for simultaneous outgoing connections
|
||||||
/// has been reached.
|
/// has been reached.
|
||||||
ConnectionLimit(ConnectionLimit),
|
ConnectionLimit(ConnectionLimit),
|
||||||
/// The peer being dialed is the local peer and thus the dial was aborted.
|
/// The peer identity obtained on the connection matches the local peer.
|
||||||
LocalPeerId,
|
LocalPeerId { endpoint: ConnectedPoint },
|
||||||
/// [`NetworkBehaviour::addresses_of_peer`] returned no addresses
|
/// [`NetworkBehaviour::addresses_of_peer`] returned no addresses
|
||||||
/// for the peer to dial.
|
/// for the peer to dial.
|
||||||
NoAddresses,
|
NoAddresses,
|
||||||
@ -1611,6 +1611,7 @@ impl From<PendingOutboundConnectionError> for DialError {
|
|||||||
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
||||||
DialError::WrongPeerId { obtained, endpoint }
|
DialError::WrongPeerId { obtained, endpoint }
|
||||||
}
|
}
|
||||||
|
PendingConnectionError::LocalPeerId { endpoint } => DialError::LocalPeerId { endpoint },
|
||||||
PendingConnectionError::Transport(e) => DialError::Transport(e),
|
PendingConnectionError::Transport(e) => DialError::Transport(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1621,7 +1622,10 @@ impl fmt::Display for DialError {
|
|||||||
match self {
|
match self {
|
||||||
DialError::ConnectionLimit(err) => write!(f, "Dial error: {err}"),
|
DialError::ConnectionLimit(err) => write!(f, "Dial error: {err}"),
|
||||||
DialError::NoAddresses => write!(f, "Dial error: no addresses for peer."),
|
DialError::NoAddresses => write!(f, "Dial error: no addresses for peer."),
|
||||||
DialError::LocalPeerId => write!(f, "Dial error: tried to dial local peer id."),
|
DialError::LocalPeerId { endpoint } => write!(
|
||||||
|
f,
|
||||||
|
"Dial error: tried to dial local peer id at {endpoint:?}."
|
||||||
|
),
|
||||||
DialError::Banned => write!(f, "Dial error: peer is banned."),
|
DialError::Banned => write!(f, "Dial error: peer is banned."),
|
||||||
DialError::DialPeerConditionFalse(c) => {
|
DialError::DialPeerConditionFalse(c) => {
|
||||||
write!(f, "Dial error: condition {c:?} for dialing peer was false.")
|
write!(f, "Dial error: condition {c:?} for dialing peer was false.")
|
||||||
@ -1671,7 +1675,7 @@ impl error::Error for DialError {
|
|||||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||||
match self {
|
match self {
|
||||||
DialError::ConnectionLimit(err) => Some(err),
|
DialError::ConnectionLimit(err) => Some(err),
|
||||||
DialError::LocalPeerId => None,
|
DialError::LocalPeerId { .. } => None,
|
||||||
DialError::NoAddresses => None,
|
DialError::NoAddresses => None,
|
||||||
DialError::Banned => None,
|
DialError::Banned => None,
|
||||||
DialError::DialPeerConditionFalse(_) => None,
|
DialError::DialPeerConditionFalse(_) => None,
|
||||||
@ -2487,7 +2491,7 @@ mod tests {
|
|||||||
match swarm.poll_next_unpin(cx) {
|
match swarm.poll_next_unpin(cx) {
|
||||||
Poll::Ready(Some(SwarmEvent::OutgoingConnectionError {
|
Poll::Ready(Some(SwarmEvent::OutgoingConnectionError {
|
||||||
peer_id,
|
peer_id,
|
||||||
error: DialError::WrongPeerId { .. },
|
error: DialError::LocalPeerId { .. },
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
assert_eq!(&peer_id.unwrap(), swarm.local_peer_id());
|
assert_eq!(&peer_id.unwrap(), swarm.local_peer_id());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user