mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 02:51:25 +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:
@ -23,13 +23,12 @@ use futures::future::BoxFuture;
|
||||
use futures::prelude::*;
|
||||
use futures_timer::Delay;
|
||||
use libp2p_core::upgrade::ReadyUpgrade;
|
||||
use libp2p_core::{upgrade::NegotiationError, UpgradeError};
|
||||
use libp2p_swarm::handler::{
|
||||
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
|
||||
};
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
|
||||
NegotiatedSubstream, StreamProtocol, SubstreamProtocol,
|
||||
ConnectionHandler, ConnectionHandlerEvent, KeepAlive, NegotiatedSubstream, StreamProtocol,
|
||||
StreamUpgradeError, SubstreamProtocol,
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
use std::{
|
||||
@ -238,14 +237,14 @@ impl Handler {
|
||||
self.outbound = None; // Request a new substream on the next `poll`.
|
||||
|
||||
let error = match error {
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
||||
StreamUpgradeError::NegotiationFailed => {
|
||||
debug_assert_eq!(self.state, State::Active);
|
||||
|
||||
self.state = State::Inactive { reported: false };
|
||||
return;
|
||||
}
|
||||
// Note: This timeout only covers protocol negotiation.
|
||||
ConnectionHandlerUpgrErr::Timeout => Failure::Timeout,
|
||||
StreamUpgradeError::Timeout => Failure::Timeout,
|
||||
e => Failure::Other { error: Box::new(e) },
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user