diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 62de6afa063..fdd914d2c50 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -4,6 +4,8 @@ - Update to `libp2p-core` `v0.35.0`. +- `DialError::WrongPeerId` now uses `Multiaddr` instead of ambiguous `ConnectedPoint` + - When deriving `NetworkBehaviour` on a custom `struct` where the user does not specify their own `OutEvent` via `#[behaviour(out_event = "MyBehaviourEvent")]` and where the user does not enable `#[behaviour(event_process = true)]`, then the derive macro generates an `OutEvent` definition for diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index f32c2df56bf..15627df3a1d 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1441,7 +1441,7 @@ pub enum DialError { /// The peer identity obtained on the connection did not match the one that was expected. WrongPeerId { obtained: PeerId, - endpoint: ConnectedPoint, + address: Multiaddr, }, /// An I/O error occurred on the connection. ConnectionIo(io::Error), @@ -1454,9 +1454,15 @@ impl From> for DialError { match error { PendingConnectionError::ConnectionLimit(limit) => DialError::ConnectionLimit(limit), PendingConnectionError::Aborted => DialError::Aborted, - PendingConnectionError::WrongPeerId { obtained, endpoint } => { - DialError::WrongPeerId { obtained, endpoint } - } + PendingConnectionError::WrongPeerId { obtained, endpoint } => match endpoint { + ConnectedPoint::Dialer { + address, + role_override: _, + } => DialError::WrongPeerId { obtained, address }, + ConnectedPoint::Listener { .. } => panic!( + "`Listener` endpoint found in `PendingOutboundConnectionError::WrongPeerId`" + ), + }, PendingConnectionError::IO(e) => DialError::ConnectionIo(e), PendingConnectionError::Transport(e) => DialError::Transport(e), } @@ -1482,7 +1488,7 @@ impl fmt::Display for DialError { "Dial error: Pending connection attempt has been aborted." ), DialError::InvalidPeerId(multihash) => write!(f, "Dial error: multihash {:?} is not a PeerId", multihash), - DialError::WrongPeerId { obtained, endpoint} => write!(f, "Dial error: Unexpected peer ID {} at {:?}.", obtained, endpoint), + DialError::WrongPeerId { obtained, address } => write!(f, "Dial error: Unexpected peer ID {} at {}.", obtained, address), DialError::ConnectionIo(e) => write!( f, "Dial error: An I/O error occurred on the connection: {:?}.", e @@ -1623,7 +1629,6 @@ mod tests { use libp2p::yamux; use libp2p_core::multiaddr::multiaddr; use libp2p_core::transport::TransportEvent; - use libp2p_core::Endpoint; use quickcheck::{quickcheck, Arbitrary, Gen, QuickCheck}; use rand::prelude::SliceRandom; use rand::Rng; @@ -2341,15 +2346,9 @@ mod tests { })); assert_eq!(peer_id.unwrap(), other_id); match error { - DialError::WrongPeerId { obtained, endpoint } => { + DialError::WrongPeerId { obtained, address } => { assert_eq!(obtained, *swarm1.local_peer_id()); - assert_eq!( - endpoint, - ConnectedPoint::Dialer { - address: other_addr, - role_override: Endpoint::Dialer, - } - ); + assert_eq!(address, other_addr); } x => panic!("wrong error {:?}", x), }