mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 02:51:25 +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:
@ -1580,8 +1580,8 @@ pub enum DialError {
|
||||
/// The configured limit for simultaneous outgoing connections
|
||||
/// has been reached.
|
||||
ConnectionLimit(ConnectionLimit),
|
||||
/// The peer being dialed is the local peer and thus the dial was aborted.
|
||||
LocalPeerId,
|
||||
/// The peer identity obtained on the connection matches the local peer.
|
||||
LocalPeerId { endpoint: ConnectedPoint },
|
||||
/// [`NetworkBehaviour::addresses_of_peer`] returned no addresses
|
||||
/// for the peer to dial.
|
||||
NoAddresses,
|
||||
@ -1611,6 +1611,7 @@ impl From<PendingOutboundConnectionError> for DialError {
|
||||
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
||||
DialError::WrongPeerId { obtained, endpoint }
|
||||
}
|
||||
PendingConnectionError::LocalPeerId { endpoint } => DialError::LocalPeerId { endpoint },
|
||||
PendingConnectionError::Transport(e) => DialError::Transport(e),
|
||||
}
|
||||
}
|
||||
@ -1621,7 +1622,10 @@ impl fmt::Display for DialError {
|
||||
match self {
|
||||
DialError::ConnectionLimit(err) => write!(f, "Dial error: {err}"),
|
||||
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::DialPeerConditionFalse(c) => {
|
||||
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)> {
|
||||
match self {
|
||||
DialError::ConnectionLimit(err) => Some(err),
|
||||
DialError::LocalPeerId => None,
|
||||
DialError::LocalPeerId { .. } => None,
|
||||
DialError::NoAddresses => None,
|
||||
DialError::Banned => None,
|
||||
DialError::DialPeerConditionFalse(_) => None,
|
||||
@ -2487,7 +2491,7 @@ mod tests {
|
||||
match swarm.poll_next_unpin(cx) {
|
||||
Poll::Ready(Some(SwarmEvent::OutgoingConnectionError {
|
||||
peer_id,
|
||||
error: DialError::WrongPeerId { .. },
|
||||
error: DialError::LocalPeerId { .. },
|
||||
..
|
||||
})) => {
|
||||
assert_eq!(&peer_id.unwrap(), swarm.local_peer_id());
|
||||
|
Reference in New Issue
Block a user