mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 08:41:36 +00:00
feat: don't report inbound stream upgrade errors to handler
When an inbound stream upgrade fails, there isn't a whole lot we can do about that in the handler. In fact, for several errors, we wouldn't even know which specific handler to target, for example, `NegotiationFailed`. Similiarly, in case of an IO error during the upgrade, we don't know which handler the stream was eventually meant to be for. Pull-Request: #3605.
This commit is contained in:
@ -29,7 +29,7 @@ use crate::upgrade::SendWrapper;
|
||||
use either::Either;
|
||||
use futures::future;
|
||||
use libp2p_core::{
|
||||
upgrade::{NegotiationError, ProtocolError, SelectUpgrade, UpgradeError},
|
||||
upgrade::{SelectUpgrade, UpgradeError},
|
||||
ConnectedPoint,
|
||||
};
|
||||
use libp2p_identity::PeerId;
|
||||
@ -161,13 +161,6 @@ where
|
||||
self,
|
||||
) -> Either<DialUpgradeError<S1OOI, S1OP>, DialUpgradeError<S2OOI, S2OP>> {
|
||||
match self {
|
||||
DialUpgradeError {
|
||||
info: Either::Left(info),
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
} => Either::Left(DialUpgradeError {
|
||||
info,
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
}),
|
||||
DialUpgradeError {
|
||||
info: Either::Left(info),
|
||||
error: ConnectionHandlerUpgrErr::Timeout,
|
||||
@ -189,13 +182,6 @@ where
|
||||
info,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
|
||||
}),
|
||||
DialUpgradeError {
|
||||
info: Either::Right(info),
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
} => Either::Right(DialUpgradeError {
|
||||
info,
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
}),
|
||||
DialUpgradeError {
|
||||
info: Either::Right(info),
|
||||
error: ConnectionHandlerUpgrErr::Timeout,
|
||||
@ -238,96 +224,18 @@ where
|
||||
>,
|
||||
) {
|
||||
match error {
|
||||
ConnectionHandlerUpgrErr::Timer => {
|
||||
Either::Left(error) => {
|
||||
self.proto1
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i1,
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
error,
|
||||
}));
|
||||
|
||||
}
|
||||
Either::Right(error) => {
|
||||
self.proto2
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i2,
|
||||
error: ConnectionHandlerUpgrErr::Timer,
|
||||
}));
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Timeout => {
|
||||
self.proto1
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i1,
|
||||
error: ConnectionHandlerUpgrErr::Timeout,
|
||||
}));
|
||||
|
||||
self.proto2
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i2,
|
||||
error: ConnectionHandlerUpgrErr::Timeout,
|
||||
}));
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
||||
self.proto1
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i1,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||
NegotiationError::Failed,
|
||||
)),
|
||||
}));
|
||||
|
||||
self.proto2
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i2,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||
NegotiationError::Failed,
|
||||
)),
|
||||
}));
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||
NegotiationError::ProtocolError(e),
|
||||
)) => {
|
||||
let (e1, e2);
|
||||
match e {
|
||||
ProtocolError::IoError(e) => {
|
||||
e1 = NegotiationError::ProtocolError(ProtocolError::IoError(
|
||||
e.kind().into(),
|
||||
));
|
||||
e2 = NegotiationError::ProtocolError(ProtocolError::IoError(e))
|
||||
}
|
||||
ProtocolError::InvalidMessage => {
|
||||
e1 = NegotiationError::ProtocolError(ProtocolError::InvalidMessage);
|
||||
e2 = NegotiationError::ProtocolError(ProtocolError::InvalidMessage)
|
||||
}
|
||||
ProtocolError::InvalidProtocol => {
|
||||
e1 = NegotiationError::ProtocolError(ProtocolError::InvalidProtocol);
|
||||
e2 = NegotiationError::ProtocolError(ProtocolError::InvalidProtocol)
|
||||
}
|
||||
ProtocolError::TooManyProtocols => {
|
||||
e1 = NegotiationError::ProtocolError(ProtocolError::TooManyProtocols);
|
||||
e2 = NegotiationError::ProtocolError(ProtocolError::TooManyProtocols)
|
||||
}
|
||||
}
|
||||
self.proto1
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i1,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e1)),
|
||||
}));
|
||||
self.proto2
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i2,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e2)),
|
||||
}));
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(e))) => {
|
||||
self.proto1
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i1,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
|
||||
}));
|
||||
}
|
||||
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(e))) => {
|
||||
self.proto2
|
||||
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
|
||||
info: i2,
|
||||
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
|
||||
error,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user