mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-17 12:01:23 +00:00
*: Rework reporting of invalid and wrong PeerIds (#2441)
Previously, the negotiated PeerId was included in the swarm event and inject_dial_failure’s arguments while the expected one was absent. This patch adds the negotiated PeerId to the DialError and includes the expected one in the notifications. Co-authored-by: Roland Kuhn <rk@rkuhn.info>
This commit is contained in:
@ -81,6 +81,7 @@ use libp2p_core::{
|
||||
EstablishedConnection, IntoConnectionHandler, ListenerId, PendingConnectionError,
|
||||
PendingInboundConnectionError, PendingOutboundConnectionError, Substream,
|
||||
},
|
||||
multihash::Multihash,
|
||||
muxing::StreamMuxerBox,
|
||||
network::{
|
||||
self, peer::ConnectedPeer, ConnectionLimits, Network, NetworkConfig, NetworkEvent,
|
||||
@ -1332,10 +1333,13 @@ pub enum DialError {
|
||||
DialPeerConditionFalse(dial_opts::PeerCondition),
|
||||
/// Pending connection attempt has been aborted.
|
||||
Aborted,
|
||||
/// The provided peer identity is invalid or the peer identity obtained on
|
||||
/// the connection did not match the one that was expected or is otherwise
|
||||
/// invalid.
|
||||
InvalidPeerId,
|
||||
/// The provided peer identity is invalid.
|
||||
InvalidPeerId(Multihash),
|
||||
/// The peer identity obtained on the connection did not match the one that was expected.
|
||||
WrongPeerId {
|
||||
obtained: PeerId,
|
||||
endpoint: ConnectedPoint,
|
||||
},
|
||||
/// An I/O error occurred on the connection.
|
||||
ConnectionIo(io::Error),
|
||||
/// An error occurred while negotiating the transport protocol(s) on a connection.
|
||||
@ -1349,7 +1353,9 @@ impl DialError {
|
||||
(DialError::ConnectionLimit(limit), handler)
|
||||
}
|
||||
network::DialError::LocalPeerId { handler } => (DialError::LocalPeerId, handler),
|
||||
network::DialError::InvalidPeerId { handler } => (DialError::InvalidPeerId, handler),
|
||||
network::DialError::InvalidPeerId { handler, multihash } => {
|
||||
(DialError::InvalidPeerId(multihash), handler)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1359,7 +1365,9 @@ impl From<PendingOutboundConnectionError<io::Error>> for DialError {
|
||||
match error {
|
||||
PendingConnectionError::ConnectionLimit(limit) => DialError::ConnectionLimit(limit),
|
||||
PendingConnectionError::Aborted => DialError::Aborted,
|
||||
PendingConnectionError::InvalidPeerId => DialError::InvalidPeerId,
|
||||
PendingConnectionError::WrongPeerId { obtained, endpoint } => {
|
||||
DialError::WrongPeerId { obtained, endpoint }
|
||||
}
|
||||
PendingConnectionError::IO(e) => DialError::ConnectionIo(e),
|
||||
PendingConnectionError::Transport(e) => DialError::Transport(e),
|
||||
}
|
||||
@ -1384,7 +1392,8 @@ impl fmt::Display for DialError {
|
||||
f,
|
||||
"Dial error: Pending connection attempt has been aborted."
|
||||
),
|
||||
DialError::InvalidPeerId => write!(f, "Dial error: Invalid peer ID."),
|
||||
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::ConnectionIo(e) => write!(
|
||||
f,
|
||||
"Dial error: An I/O error occurred on the connection: {:?}.", e
|
||||
@ -1403,7 +1412,8 @@ impl error::Error for DialError {
|
||||
DialError::Banned => None,
|
||||
DialError::DialPeerConditionFalse(_) => None,
|
||||
DialError::Aborted => None,
|
||||
DialError::InvalidPeerId => None,
|
||||
DialError::InvalidPeerId { .. } => None,
|
||||
DialError::WrongPeerId { .. } => None,
|
||||
DialError::ConnectionIo(_) => None,
|
||||
DialError::Transport(_) => None,
|
||||
}
|
||||
|
Reference in New Issue
Block a user