mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 19:11:23 +00:00
feat(swarm): make stream uprade errors more ergonomic
The currently provided `ConnectionHandlerUpgrErr` is very hard to use. Not only does it have a long name, it also features 3 levels of nesting which results in a lot of boilerplate. Last but not least, it exposes `multistream-select` as a dependency to all protocols. We fix all of the above by renaming the type to `StreamUpgradeError` and flattening out its interface. Unrecoverable errors during protocol selection are hidden within the `Io` variant. Related: #3759. Pull-Request: #3882.
This commit is contained in:
@ -27,10 +27,10 @@ use futures::future::Either;
|
||||
use futures::prelude::*;
|
||||
use futures::StreamExt;
|
||||
use instant::Instant;
|
||||
use libp2p_core::upgrade::{DeniedUpgrade, NegotiationError, UpgradeError};
|
||||
use libp2p_core::upgrade::DeniedUpgrade;
|
||||
use libp2p_swarm::handler::{
|
||||
ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr,
|
||||
DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive,
|
||||
ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError,
|
||||
FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, StreamUpgradeError,
|
||||
SubstreamProtocol,
|
||||
};
|
||||
use libp2p_swarm::NegotiatedSubstream;
|
||||
@ -526,20 +526,17 @@ impl ConnectionHandler for Handler {
|
||||
handler.on_fully_negotiated_outbound(fully_negotiated_outbound)
|
||||
}
|
||||
ConnectionEvent::DialUpgradeError(DialUpgradeError {
|
||||
error: ConnectionHandlerUpgrErr::Timeout,
|
||||
error: StreamUpgradeError::Timeout,
|
||||
..
|
||||
}) => {
|
||||
log::debug!("Dial upgrade error: Protocol negotiation timeout");
|
||||
}
|
||||
ConnectionEvent::DialUpgradeError(DialUpgradeError {
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
|
||||
error: StreamUpgradeError::Apply(e),
|
||||
..
|
||||
}) => void::unreachable(e),
|
||||
ConnectionEvent::DialUpgradeError(DialUpgradeError {
|
||||
error:
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||
NegotiationError::Failed,
|
||||
)),
|
||||
error: StreamUpgradeError::NegotiationFailed,
|
||||
..
|
||||
}) => {
|
||||
// The protocol is not supported
|
||||
@ -551,10 +548,7 @@ impl ConnectionHandler for Handler {
|
||||
});
|
||||
}
|
||||
ConnectionEvent::DialUpgradeError(DialUpgradeError {
|
||||
error:
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||
NegotiationError::ProtocolError(e),
|
||||
)),
|
||||
error: StreamUpgradeError::Io(e),
|
||||
..
|
||||
}) => {
|
||||
log::debug!("Protocol negotiation failed: {e}")
|
||||
|
Reference in New Issue
Block a user