From 7443d0a65922d905666ad0149af9894262dfe058 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 13 Mar 2023 10:58:38 +0100 Subject: [PATCH 01/16] Don't report inbound errors on stream upgrades to handler --- protocols/dcutr/src/handler/relayed.rs | 34 ++----- protocols/relay/src/behaviour/handler.rs | 24 +---- protocols/relay/src/priv_client/handler.rs | 22 +---- protocols/request-response/src/handler.rs | 20 +--- swarm/src/behaviour/toggle.rs | 21 ++-- swarm/src/connection.rs | 31 +++++- swarm/src/handler.rs | 7 +- swarm/src/handler/either.rs | 49 ++------- swarm/src/handler/multi.rs | 109 ++------------------- swarm/src/handler/select.rs | 84 ++-------------- 10 files changed, 90 insertions(+), 311 deletions(-) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index aefaaeec933..deaf0dc5653 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -30,7 +30,7 @@ use libp2p_core::upgrade::{DeniedUpgrade, NegotiationError, UpgradeError}; use libp2p_core::ConnectedPoint; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, + ListenUpgradeError, ListenUpgradeErrorKind, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, @@ -215,42 +215,22 @@ impl Handler { >, ) { match error { - ConnectionHandlerUpgrErr::Timeout => { + ListenUpgradeErrorKind::Timeout => { self.queued_events.push_back(ConnectionHandlerEvent::Custom( Event::InboundNegotiationFailed { error: ConnectionHandlerUpgrErr::Timeout, }, )); } - ConnectionHandlerUpgrErr::Timer => { - self.queued_events.push_back(ConnectionHandlerEvent::Custom( - Event::InboundNegotiationFailed { - error: ConnectionHandlerUpgrErr::Timer, - }, - )); - } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { - // The remote merely doesn't support the DCUtR protocol. - // This is no reason to close the connection, which may - // successfully communicate with other protocols already. - self.keep_alive = KeepAlive::No; - self.queued_events.push_back(ConnectionHandlerEvent::Custom( - Event::InboundNegotiationFailed { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - NegotiationError::Failed, - )), - }, - )); - } - _ => { + ListenUpgradeErrorKind::Failed(e) => { // Anything else is considered a fatal error or misbehaviour of // the remote peer and results in closing the connection. - self.pending_error = Some(error.map_upgrade_err(|e| { - e.map_err(|e| match e { + self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply( + match e { Either::Left(e) => Either::Left(e), Either::Right(v) => void::unreachable(v), - }) - })); + }, + ))); } } } diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 3acbda0eff5..0e00ba88662 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -34,7 +34,7 @@ use libp2p_core::{upgrade, ConnectedPoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, + ListenUpgradeError, ListenUpgradeErrorKind, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, ConnectionId, KeepAlive, @@ -480,26 +480,10 @@ impl Handler { >, ) { let non_fatal_error = match error { - ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::Failed, - )) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::Failed, - )), - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::ProtocolError(e), - )) => { - self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( - upgrade::UpgradeError::Select(upgrade::NegotiationError::ProtocolError(e)), - )); - return; - } - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Apply( - inbound_hop::UpgradeError::Fatal(error), - )) => { + ListenUpgradeErrorKind::Timeout => ConnectionHandlerUpgrErr::Timeout, // TODO: non-fatal-error can only be timeout, should we even report that? + ListenUpgradeErrorKind::Failed(inbound_hop::UpgradeError::Fatal(e)) => { self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( - upgrade::UpgradeError::Apply(Either::Left(error)), + upgrade::UpgradeError::Apply(Either::Left(e)), )); return; } diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 3d7bc6c4d1e..91edf7af014 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -33,7 +33,7 @@ use libp2p_core::{upgrade, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, + ListenUpgradeError, ListenUpgradeErrorKind, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, @@ -305,24 +305,8 @@ impl Handler { >, ) { let non_fatal_error = match error { - ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::Failed, - )) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::Failed, - )), - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( - upgrade::NegotiationError::ProtocolError(e), - )) => { - self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( - upgrade::UpgradeError::Select(upgrade::NegotiationError::ProtocolError(e)), - )); - return; - } - ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Apply( - inbound_stop::UpgradeError::Fatal(error), - )) => { + ListenUpgradeErrorKind::Timeout => ConnectionHandlerUpgrErr::Timeout, // TODO: non-fatal-error can only be timeout, should we even report that? + ListenUpgradeErrorKind::Failed(inbound_stop::UpgradeError::Fatal(error)) => { self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( upgrade::UpgradeError::Apply(Either::Left(error)), )); diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 50cd6adb055..c1b963b9cb0 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -25,7 +25,7 @@ use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, + ListenUpgradeError, ListenUpgradeErrorKind, }; pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; @@ -172,22 +172,12 @@ where >, ) { match error { - ConnectionHandlerUpgrErr::Timeout => { + ListenUpgradeErrorKind::Timeout => { self.pending_events.push_back(Event::InboundTimeout(info)) } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { - // The local peer merely doesn't support the protocol(s) requested. - // This is no reason to close the connection, which may - // successfully communicate with other protocols already. - // An event is reported to permit user code to react to the fact that - // the local peer does not support the requested protocol(s). - self.pending_events - .push_back(Event::InboundUnsupportedProtocols(info)); - } - _ => { - // Anything else is considered a fatal error or misbehaviour of - // the remote peer and results in closing the connection. - self.pending_error = Some(error); + ListenUpgradeErrorKind::Failed(e) => { + self.pending_error = + Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e))); } } } diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 395e380490f..fc1f25e118d 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -21,9 +21,9 @@ use crate::behaviour::FromSwarm; use crate::connection::ConnectionId; use crate::handler::{ - AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, - ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - KeepAlive, ListenUpgradeError, SubstreamProtocol, + AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, + FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, ListenUpgradeError, + ListenUpgradeErrorKind, SubstreamProtocol, }; use crate::upgrade::SendWrapper; use crate::{ @@ -252,14 +252,11 @@ where }; let err = match err { - ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, - ConnectionHandlerUpgrErr::Upgrade(err) => { - ConnectionHandlerUpgrErr::Upgrade(err.map_err(|err| match err { - Either::Left(e) => e, - Either::Right(v) => void::unreachable(v), - })) - } + ListenUpgradeErrorKind::Timeout => ListenUpgradeErrorKind::Timeout, + ListenUpgradeErrorKind::Failed(e) => ListenUpgradeErrorKind::Failed(match e { + Either::Left(e) => e, + Either::Right(v) => void::unreachable(v), + }), }; inner.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { @@ -397,7 +394,7 @@ mod tests { handler.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: Either::Right(()), - error: ConnectionHandlerUpgrErr::Timeout, + error: ListenUpgradeErrorKind::Timeout, })); } } diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index b42bdde9620..8999c79ffa3 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -29,7 +29,7 @@ pub use error::{ use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, DialUpgradeError, FullyNegotiatedInbound, - FullyNegotiatedOutbound, ListenUpgradeError, + FullyNegotiatedOutbound, ListenUpgradeError, ListenUpgradeErrorKind, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper}; use crate::{ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol}; @@ -263,9 +263,34 @@ where )); continue; } - Poll::Ready(Some((info, Err(error)))) => { + Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timer)))) => { + unreachable!() + } + Poll::Ready(Some(( + _, + Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e))), + ))) => { + log::debug!("failed to upgrade inbound stream: {e}"); + continue; + } + Poll::Ready(Some((info, Err(ConnectionHandlerUpgrErr::Timeout)))) => { + handler.on_connection_event(ConnectionEvent::ListenUpgradeError( + ListenUpgradeError { + info, + error: ListenUpgradeErrorKind::Timeout, + }, + )); + continue; + } + Poll::Ready(Some(( + info, + Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error))), + ))) => { handler.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { info, error }, + ListenUpgradeError { + info, + error: ListenUpgradeErrorKind::Failed(error), + }, )); continue; } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 6c0ccc068b7..30024912e78 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -250,7 +250,12 @@ pub struct DialUpgradeError { /// that upgrading an inbound substream to the given protocol has failed. pub struct ListenUpgradeError { pub info: IOI, - pub error: ConnectionHandlerUpgrErr, + pub error: ListenUpgradeErrorKind, +} + +pub enum ListenUpgradeErrorKind { + Failed(E), + Timeout, } /// Configuration of inbound or outbound substream protocol(s) diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index 92d82371163..1327daa1714 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -22,13 +22,12 @@ use crate::handler::IntoConnectionHandler; use crate::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound, - InboundUpgradeSend, KeepAlive, ListenUpgradeError, SubstreamProtocol, + InboundUpgradeSend, KeepAlive, ListenUpgradeError, ListenUpgradeErrorKind, SubstreamProtocol, }; use crate::upgrade::SendWrapper; -use crate::ConnectionHandlerUpgrErr; use either::Either; use futures::future; -use libp2p_core::{ConnectedPoint, UpgradeError}; +use libp2p_core::ConnectedPoint; use libp2p_identity::PeerId; use std::task::{Context, Poll}; @@ -125,59 +124,31 @@ where fn transpose(self) -> Either, ListenUpgradeError> { match self { ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(error))), + error: ListenUpgradeErrorKind::Failed(Either::Left(error)), info: Either::Left(info), } => Either::Left(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)), + error: ListenUpgradeErrorKind::Failed(error), info, }), ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(error))), + error: ListenUpgradeErrorKind::Failed(Either::Right(error)), info: Either::Right(info), } => Either::Right(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)), + error: ListenUpgradeErrorKind::Failed(error), info, }), ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(error)), + error: ListenUpgradeErrorKind::Timeout, info: Either::Left(info), } => Either::Left(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(error)), + error: ListenUpgradeErrorKind::Timeout, info, }), ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(error)), + error: ListenUpgradeErrorKind::Timeout, info: Either::Right(info), } => Either::Right(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(error)), - info, - }), - ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timer, - info: Either::Left(info), - } => Either::Left(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timer, - info, - }), - ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timer, - info: Either::Right(info), - } => Either::Right(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timer, - info, - }), - ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timeout, - info: Either::Left(info), - } => Either::Left(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timeout, - info, - }), - ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timeout, - info: Either::Right(info), - } => Either::Right(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Timeout, + error: ListenUpgradeErrorKind::Timeout, info, }), _ => unreachable!(), diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 146a2a96895..866bff0e92c 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -24,14 +24,14 @@ #[allow(deprecated)] use crate::handler::IntoConnectionHandler; use crate::handler::{ - AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, - ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - KeepAlive, ListenUpgradeError, SubstreamProtocol, + AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, + FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, ListenUpgradeError, + ListenUpgradeErrorKind, SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; use futures::{future::BoxFuture, prelude::*}; -use libp2p_core::upgrade::{NegotiationError, ProtocolError, ProtocolName, UpgradeError}; +use libp2p_core::upgrade::ProtocolName; use libp2p_core::ConnectedPoint; use libp2p_identity::PeerId; use rand::Rng; @@ -95,118 +95,25 @@ where >, ) { match error { - ConnectionHandlerUpgrErr::Timer => { + ListenUpgradeErrorKind::Timeout => { for (k, h) in &mut self.handlers { if let Some(i) = info.take(k) { h.on_connection_event(ConnectionEvent::ListenUpgradeError( ListenUpgradeError { info: i, - error: ConnectionHandlerUpgrErr::Timer, + error: ListenUpgradeErrorKind::Timeout, }, )); } } } - ConnectionHandlerUpgrErr::Timeout => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Timeout, - }, - )); - } - } - } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - NegotiationError::Failed, - )), - }, - )); - } - } - } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - NegotiationError::ProtocolError(e), - )) => match e { - ProtocolError::IoError(e) => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - let e = NegotiationError::ProtocolError(ProtocolError::IoError( - e.kind().into(), - )); - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - e, - )), - }, - )); - } - } - } - ProtocolError::InvalidMessage => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - let e = NegotiationError::ProtocolError(ProtocolError::InvalidMessage); - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - e, - )), - }, - )); - } - } - } - ProtocolError::InvalidProtocol => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - let e = NegotiationError::ProtocolError(ProtocolError::InvalidProtocol); - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - e, - )), - }, - )); - } - } - } - ProtocolError::TooManyProtocols => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - let e = - NegotiationError::ProtocolError(ProtocolError::TooManyProtocols); - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select( - e, - )), - }, - )); - } - } - } - }, - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply((k, e))) => { + ListenUpgradeErrorKind::Failed((k, e)) => { if let Some(h) = self.handlers.get_mut(&k) { if let Some(i) = info.take(&k) { h.on_connection_event(ConnectionEvent::ListenUpgradeError( ListenUpgradeError { info: i, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)), + error: ListenUpgradeErrorKind::Failed(e), }, )); } diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index edb9a9154b1..ebb99c6f420 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -23,13 +23,14 @@ use crate::handler::IntoConnectionHandler; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - InboundUpgradeSend, KeepAlive, ListenUpgradeError, OutboundUpgradeSend, SubstreamProtocol, + InboundUpgradeSend, KeepAlive, ListenUpgradeError, ListenUpgradeErrorKind, OutboundUpgradeSend, + SubstreamProtocol, }; 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; @@ -238,96 +239,31 @@ where >, ) { match error { - ConnectionHandlerUpgrErr::Timer => { + ListenUpgradeErrorKind::Timeout => { self.proto1 .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: i1, - error: ConnectionHandlerUpgrErr::Timer, + error: ListenUpgradeErrorKind::Timeout, })); self.proto2 .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: i2, - error: ConnectionHandlerUpgrErr::Timer, + error: ListenUpgradeErrorKind::Timeout, })); } - ConnectionHandlerUpgrErr::Timeout => { + ListenUpgradeErrorKind::Failed(Either::Left(e)) => { 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)), + error: ListenUpgradeErrorKind::Failed(e), })); } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(e))) => { + ListenUpgradeErrorKind::Failed(Either::Right(e)) => { self.proto2 .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: i2, - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)), + error: ListenUpgradeErrorKind::Failed(e), })); } } From 0a29baeafa13683470cc9880b565da5fac520fb2 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 13 Mar 2023 11:12:00 +0100 Subject: [PATCH 02/16] Don't report timeout --- protocols/dcutr/src/handler/relayed.rs | 29 +++++----------- protocols/relay/src/behaviour/handler.rs | 23 ++++--------- protocols/relay/src/priv_client/handler.rs | 23 ++++--------- protocols/request-response/src/handler.rs | 16 +++------ swarm/src/behaviour/toggle.rs | 39 ++-------------------- swarm/src/connection.rs | 29 ++++++---------- swarm/src/handler.rs | 7 +--- swarm/src/handler/either.rs | 30 +++-------------- swarm/src/handler/multi.rs | 37 ++++++-------------- swarm/src/handler/select.rs | 24 +++---------- 10 files changed, 63 insertions(+), 194 deletions(-) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index deaf0dc5653..9a0af35abef 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -30,7 +30,7 @@ use libp2p_core::upgrade::{DeniedUpgrade, NegotiationError, UpgradeError}; use libp2p_core::ConnectedPoint; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, ListenUpgradeErrorKind, + ListenUpgradeError, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, @@ -214,25 +214,14 @@ impl Handler { ::InboundProtocol, >, ) { - match error { - ListenUpgradeErrorKind::Timeout => { - self.queued_events.push_back(ConnectionHandlerEvent::Custom( - Event::InboundNegotiationFailed { - error: ConnectionHandlerUpgrErr::Timeout, - }, - )); - } - ListenUpgradeErrorKind::Failed(e) => { - // Anything else is considered a fatal error or misbehaviour of - // the remote peer and results in closing the connection. - self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply( - match e { - Either::Left(e) => Either::Left(e), - Either::Right(v) => void::unreachable(v), - }, - ))); - } - } + // Anything else is considered a fatal error or misbehaviour of + // the remote peer and results in closing the connection. + self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply( + match error { + Either::Left(e) => Either::Left(e), + Either::Right(v) => void::unreachable(v), + }, + ))); } fn on_dial_upgrade_error( diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 0e00ba88662..05fa1ca1337 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -34,7 +34,7 @@ use libp2p_core::{upgrade, ConnectedPoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, ListenUpgradeErrorKind, + ListenUpgradeError, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, ConnectionId, KeepAlive, @@ -474,25 +474,16 @@ impl Handler { fn on_listen_upgrade_error( &mut self, - ListenUpgradeError { error, .. }: ListenUpgradeError< + ListenUpgradeError { + error: inbound_hop::UpgradeError::Fatal(error), + .. + }: ListenUpgradeError< ::InboundOpenInfo, ::InboundProtocol, >, ) { - let non_fatal_error = match error { - ListenUpgradeErrorKind::Timeout => ConnectionHandlerUpgrErr::Timeout, // TODO: non-fatal-error can only be timeout, should we even report that? - ListenUpgradeErrorKind::Failed(inbound_hop::UpgradeError::Fatal(e)) => { - self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( - upgrade::UpgradeError::Apply(Either::Left(e)), - )); - return; - } - }; - - self.queued_events.push_back(ConnectionHandlerEvent::Custom( - Event::CircuitReqReceiveFailed { - error: non_fatal_error, - }, + self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( + upgrade::UpgradeError::Apply(Either::Left(error)), )); } diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 91edf7af014..bafafba9d36 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -33,7 +33,7 @@ use libp2p_core::{upgrade, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, ListenUpgradeErrorKind, + ListenUpgradeError, }; use libp2p_swarm::{ ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, @@ -299,25 +299,16 @@ impl Handler { fn on_listen_upgrade_error( &mut self, - ListenUpgradeError { error, .. }: ListenUpgradeError< + ListenUpgradeError { + error: inbound_stop::UpgradeError::Fatal(error), + .. + }: ListenUpgradeError< ::InboundOpenInfo, ::InboundProtocol, >, ) { - let non_fatal_error = match error { - ListenUpgradeErrorKind::Timeout => ConnectionHandlerUpgrErr::Timeout, // TODO: non-fatal-error can only be timeout, should we even report that? - ListenUpgradeErrorKind::Failed(inbound_stop::UpgradeError::Fatal(error)) => { - self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( - upgrade::UpgradeError::Apply(Either::Left(error)), - )); - return; - } - }; - - self.queued_events.push_back(ConnectionHandlerEvent::Custom( - Event::InboundCircuitReqFailed { - error: non_fatal_error, - }, + self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade( + upgrade::UpgradeError::Apply(Either::Left(error)), )); } diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index c1b963b9cb0..d5ad5cdfce2 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -25,7 +25,7 @@ use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, ListenUpgradeErrorKind, + ListenUpgradeError, }; pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; @@ -166,20 +166,14 @@ where } fn on_listen_upgrade_error( &mut self, - ListenUpgradeError { info, error }: ListenUpgradeError< + ListenUpgradeError { error, .. }: ListenUpgradeError< ::InboundOpenInfo, ::InboundProtocol, >, ) { - match error { - ListenUpgradeErrorKind::Timeout => { - self.pending_events.push_back(Event::InboundTimeout(info)) - } - ListenUpgradeErrorKind::Failed(e) => { - self.pending_error = - Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e))); - } - } + self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply( + error, + ))); } } diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index fc1f25e118d..accae700323 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -23,7 +23,7 @@ use crate::connection::ConnectionId; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, ListenUpgradeError, - ListenUpgradeErrorKind, SubstreamProtocol, + SubstreamProtocol, }; use crate::upgrade::SendWrapper; use crate::{ @@ -252,11 +252,8 @@ where }; let err = match err { - ListenUpgradeErrorKind::Timeout => ListenUpgradeErrorKind::Timeout, - ListenUpgradeErrorKind::Failed(e) => ListenUpgradeErrorKind::Failed(match e { - Either::Left(e) => e, - Either::Right(v) => void::unreachable(v), - }), + Either::Left(e) => e, + Either::Right(v) => void::unreachable(v), }; inner.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { @@ -368,33 +365,3 @@ where } } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::dummy; - - /// A disabled [`ToggleConnectionHandler`] can receive listen upgrade errors in - /// the following two cases: - /// - /// 1. Protocol negotiation on an incoming stream failed with no protocol - /// being agreed on. - /// - /// 2. When combining [`ConnectionHandler`] implementations a single - /// [`ConnectionHandler`] might be notified of an inbound upgrade error - /// unrelated to its own upgrade logic. For example when nesting a - /// [`ToggleConnectionHandler`] in a - /// [`ConnectionHandlerSelect`](crate::connection_handler::ConnectionHandlerSelect) - /// the former might receive an inbound upgrade error even when disabled. - /// - /// [`ToggleConnectionHandler`] should ignore the error in both of these cases. - #[test] - fn ignore_listen_upgrade_error_when_disabled() { - let mut handler = ToggleConnectionHandler:: { inner: None }; - - handler.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { - info: Either::Right(()), - error: ListenUpgradeErrorKind::Timeout, - })); - } -} diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 8999c79ffa3..3fa5d151bee 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -29,7 +29,7 @@ pub use error::{ use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, DialUpgradeError, FullyNegotiatedInbound, - FullyNegotiatedOutbound, ListenUpgradeError, ListenUpgradeErrorKind, + FullyNegotiatedOutbound, ListenUpgradeError, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper}; use crate::{ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol}; @@ -267,31 +267,22 @@ where unreachable!() } Poll::Ready(Some(( - _, - Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e))), + info, + Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error))), ))) => { - log::debug!("failed to upgrade inbound stream: {e}"); - continue; - } - Poll::Ready(Some((info, Err(ConnectionHandlerUpgrErr::Timeout)))) => { handler.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info, - error: ListenUpgradeErrorKind::Timeout, - }, + ListenUpgradeError { info, error }, )); continue; } Poll::Ready(Some(( - info, - Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error))), + _, + Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e))), ))) => { - handler.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info, - error: ListenUpgradeErrorKind::Failed(error), - }, - )); + log::debug!("failed to upgrade inbound stream: {e}"); + continue; + } + Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timeout)))) => { continue; } } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 30024912e78..b2d720bc9c9 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -250,12 +250,7 @@ pub struct DialUpgradeError { /// that upgrading an inbound substream to the given protocol has failed. pub struct ListenUpgradeError { pub info: IOI, - pub error: ListenUpgradeErrorKind, -} - -pub enum ListenUpgradeErrorKind { - Failed(E), - Timeout, + pub error: IP::Error, } /// Configuration of inbound or outbound substream protocol(s) diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index 1327daa1714..ece9ac44aa7 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -22,7 +22,7 @@ use crate::handler::IntoConnectionHandler; use crate::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, FullyNegotiatedInbound, - InboundUpgradeSend, KeepAlive, ListenUpgradeError, ListenUpgradeErrorKind, SubstreamProtocol, + InboundUpgradeSend, KeepAlive, ListenUpgradeError, SubstreamProtocol, }; use crate::upgrade::SendWrapper; use either::Either; @@ -124,33 +124,13 @@ where fn transpose(self) -> Either, ListenUpgradeError> { match self { ListenUpgradeError { - error: ListenUpgradeErrorKind::Failed(Either::Left(error)), + error: Either::Left(error), info: Either::Left(info), - } => Either::Left(ListenUpgradeError { - error: ListenUpgradeErrorKind::Failed(error), - info, - }), + } => Either::Left(ListenUpgradeError { error, info }), ListenUpgradeError { - error: ListenUpgradeErrorKind::Failed(Either::Right(error)), + error: Either::Right(error), info: Either::Right(info), - } => Either::Right(ListenUpgradeError { - error: ListenUpgradeErrorKind::Failed(error), - info, - }), - ListenUpgradeError { - error: ListenUpgradeErrorKind::Timeout, - info: Either::Left(info), - } => Either::Left(ListenUpgradeError { - error: ListenUpgradeErrorKind::Timeout, - info, - }), - ListenUpgradeError { - error: ListenUpgradeErrorKind::Timeout, - info: Either::Right(info), - } => Either::Right(ListenUpgradeError { - error: ListenUpgradeErrorKind::Timeout, - info, - }), + } => Either::Right(ListenUpgradeError { error, info }), _ => unreachable!(), } } diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 866bff0e92c..81d2595c120 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -26,7 +26,7 @@ use crate::handler::IntoConnectionHandler; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, ListenUpgradeError, - ListenUpgradeErrorKind, SubstreamProtocol, + SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; @@ -89,35 +89,20 @@ where fn on_listen_upgrade_error( &mut self, - ListenUpgradeError { error, mut info }: ListenUpgradeError< + ListenUpgradeError { + error: (key, error), + mut info, + }: ListenUpgradeError< ::InboundOpenInfo, ::InboundProtocol, >, ) { - match error { - ListenUpgradeErrorKind::Timeout => { - for (k, h) in &mut self.handlers { - if let Some(i) = info.take(k) { - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ListenUpgradeErrorKind::Timeout, - }, - )); - } - } - } - ListenUpgradeErrorKind::Failed((k, e)) => { - if let Some(h) = self.handlers.get_mut(&k) { - if let Some(i) = info.take(&k) { - h.on_connection_event(ConnectionEvent::ListenUpgradeError( - ListenUpgradeError { - info: i, - error: ListenUpgradeErrorKind::Failed(e), - }, - )); - } - } + if let Some(h) = self.handlers.get_mut(&key) { + if let Some(i) = info.take(&key) { + h.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { + info: i, + error, + })); } } } diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index ebb99c6f420..eb31d59fcc9 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -23,8 +23,7 @@ use crate::handler::IntoConnectionHandler; use crate::handler::{ AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - InboundUpgradeSend, KeepAlive, ListenUpgradeError, ListenUpgradeErrorKind, OutboundUpgradeSend, - SubstreamProtocol, + InboundUpgradeSend, KeepAlive, ListenUpgradeError, OutboundUpgradeSend, SubstreamProtocol, }; use crate::upgrade::SendWrapper; use either::Either; @@ -239,31 +238,18 @@ where >, ) { match error { - ListenUpgradeErrorKind::Timeout => { + Either::Left(error) => { self.proto1 .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: i1, - error: ListenUpgradeErrorKind::Timeout, - })); - - self.proto2 - .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { - info: i2, - error: ListenUpgradeErrorKind::Timeout, - })); - } - ListenUpgradeErrorKind::Failed(Either::Left(e)) => { - self.proto1 - .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { - info: i1, - error: ListenUpgradeErrorKind::Failed(e), + error, })); } - ListenUpgradeErrorKind::Failed(Either::Right(e)) => { + Either::Right(error) => { self.proto2 .on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: i2, - error: ListenUpgradeErrorKind::Failed(e), + error, })); } } From fad8b5b248736e7b94d11a5e1599db034153195c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 13 Mar 2023 11:13:59 +0100 Subject: [PATCH 03/16] Remove unnecessary comment --- protocols/dcutr/src/handler/relayed.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index 9a0af35abef..071b1b8d13b 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -214,8 +214,6 @@ impl Handler { ::InboundProtocol, >, ) { - // Anything else is considered a fatal error or misbehaviour of - // the remote peer and results in closing the connection. self.pending_error = Some(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply( match error { Either::Left(e) => Either::Left(e), From 04bee5784a7463b7cd15938404043d2db86ebfe5 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 13 Mar 2023 11:14:29 +0100 Subject: [PATCH 04/16] Reorder code --- swarm/src/connection.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 3fa5d151bee..01866ca9c53 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -263,9 +263,6 @@ where )); continue; } - Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timer)))) => { - unreachable!() - } Poll::Ready(Some(( info, Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error))), @@ -275,6 +272,9 @@ where )); continue; } + Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timer)))) => { + unreachable!() + } Poll::Ready(Some(( _, Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e))), From 982718c8e1f39104fc63abf7901862a59bef9d9d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:06:46 +0100 Subject: [PATCH 05/16] Log timeout of inbound stream --- swarm/src/connection.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 01866ca9c53..4709241a254 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -283,6 +283,7 @@ where continue; } Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timeout)))) => { + log::debug!("inbound stream upgrade timed out"); continue; } } From 931d4d1145bc9e53678bb457feeab9fc6c8bee47 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:10:41 +0100 Subject: [PATCH 06/16] Remove `ConnectionHandlerUpgrErr::Timer` variant --- protocols/gossipsub/src/handler.rs | 4 +--- protocols/relay/src/behaviour/handler.rs | 4 ---- protocols/relay/src/priv_client/handler.rs | 2 -- swarm/CHANGELOG.md | 8 ++++++++ swarm/src/connection.rs | 3 --- swarm/src/dummy.rs | 1 - swarm/src/handler.rs | 7 ------- swarm/src/handler/select.rs | 14 -------------- 8 files changed, 9 insertions(+), 34 deletions(-) diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 2c921286553..c0a45c92f5c 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -293,9 +293,7 @@ impl ConnectionHandler for Handler { if let Some(error) = self.upgrade_errors.pop_front() { let reported_error = match error { // Timeout errors get mapped to NegotiationTimeout and we close the connection. - ConnectionHandlerUpgrErr::Timeout | ConnectionHandlerUpgrErr::Timer => { - Some(HandlerError::NegotiationTimeout) - } + ConnectionHandlerUpgrErr::Timeout => Some(HandlerError::NegotiationTimeout), // There was an error post negotiation, close the connection. ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => Some(e), ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(negotiation_error)) => { diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 05fa1ca1337..44a8ed9d1be 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -502,10 +502,6 @@ impl Handler { ConnectionHandlerUpgrErr::Timeout, proto::Status::CONNECTION_FAILED, ), - ConnectionHandlerUpgrErr::Timer => ( - ConnectionHandlerUpgrErr::Timer, - proto::Status::CONNECTION_FAILED, - ), ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( upgrade::NegotiationError::Failed, )) => { diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index bafafba9d36..74e16c685e3 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -326,7 +326,6 @@ impl Handler { OutboundOpenInfo::Reserve { mut to_listener } => { let non_fatal_error = match error { ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( upgrade::NegotiationError::Failed, )) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( @@ -389,7 +388,6 @@ impl Handler { OutboundOpenInfo::Connect { send_back } => { let non_fatal_error = match error { ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( upgrade::NegotiationError::Failed, )) => ConnectionHandlerUpgrErr::Upgrade(upgrade::UpgradeError::Select( diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index df04507376e..f3831b346b7 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.43.0 - unreleased + +- Remove `ConnectionHandlerUpgrErr::Timer` variant. + This variant was never constructed and thus dead code. + See [PR 3605]. + +[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 + # 0.42.0 - Allow `NetworkBehaviour`s to manage connections. diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 4709241a254..04abce5f64a 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -272,9 +272,6 @@ where )); continue; } - Poll::Ready(Some((_, Err(ConnectionHandlerUpgrErr::Timer)))) => { - unreachable!() - } Poll::Ready(Some(( _, Err(ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e))), diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 9396344ca30..851f3eea8ea 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -133,7 +133,6 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { }) => void::unreachable(protocol), ConnectionEvent::DialUpgradeError(DialUpgradeError { info: _, error }) => match error { ConnectionHandlerUpgrErr::Timeout => unreachable!(), - ConnectionHandlerUpgrErr::Timer => unreachable!(), ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => void::unreachable(e), ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(_)) => { unreachable!("Denied upgrade does not support any protocols") diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 914f2f7ecb4..7e90056467f 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -436,8 +436,6 @@ impl pub enum ConnectionHandlerUpgrErr { /// The opening attempt timed out before the negotiation was fully completed. Timeout, - /// There was an error in the timer used. - Timer, /// Error while upgrading the substream to the protocol we want. Upgrade(UpgradeError), } @@ -450,7 +448,6 @@ impl ConnectionHandlerUpgrErr { { match self { ConnectionHandlerUpgrErr::Timeout => ConnectionHandlerUpgrErr::Timeout, - ConnectionHandlerUpgrErr::Timer => ConnectionHandlerUpgrErr::Timer, ConnectionHandlerUpgrErr::Upgrade(e) => ConnectionHandlerUpgrErr::Upgrade(f(e)), } } @@ -465,9 +462,6 @@ where ConnectionHandlerUpgrErr::Timeout => { write!(f, "Timeout error while opening a substream") } - ConnectionHandlerUpgrErr::Timer => { - write!(f, "Timer error while opening a substream") - } ConnectionHandlerUpgrErr::Upgrade(err) => { write!(f, "Upgrade: ")?; crate::print_error_chain(f, err) @@ -483,7 +477,6 @@ where fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self { ConnectionHandlerUpgrErr::Timeout => None, - ConnectionHandlerUpgrErr::Timer => None, ConnectionHandlerUpgrErr::Upgrade(_) => None, } } diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index eb31d59fcc9..9be6428ba57 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -161,13 +161,6 @@ where self, ) -> Either, DialUpgradeError> { 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, From 76e0ac79fbacc8f8b9ae1dac6bfb70cff5b846b7 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:13:05 +0100 Subject: [PATCH 07/16] Remove `libpp2::relay::Event::CircuitReqReceiveFailed` --- misc/metrics/src/relay.rs | 4 ---- protocols/relay/CHANGELOG.md | 8 ++++++++ protocols/relay/src/behaviour.rs | 13 ------------- protocols/relay/src/behaviour/handler.rs | 8 -------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/misc/metrics/src/relay.rs b/misc/metrics/src/relay.rs index 479a518eeaf..6122e6d0468 100644 --- a/misc/metrics/src/relay.rs +++ b/misc/metrics/src/relay.rs @@ -54,7 +54,6 @@ enum EventType { ReservationReqDenied, ReservationReqDenyFailed, ReservationTimedOut, - CircuitReqReceiveFailed, CircuitReqDenied, CircuitReqDenyFailed, CircuitReqOutboundConnectFailed, @@ -75,9 +74,6 @@ impl From<&libp2p_relay::Event> for EventType { EventType::ReservationReqDenyFailed } libp2p_relay::Event::ReservationTimedOut { .. } => EventType::ReservationTimedOut, - libp2p_relay::Event::CircuitReqReceiveFailed { .. } => { - EventType::CircuitReqReceiveFailed - } libp2p_relay::Event::CircuitReqDenied { .. } => EventType::CircuitReqDenied, libp2p_relay::Event::CircuitReqOutboundConnectFailed { .. } => { EventType::CircuitReqOutboundConnectFailed diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 1f1592af41e..1a990694674 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.16.0 + +- Remove `Event::CircuitReqReceiveFailed` variant. + This variant is no longer constructed. + See [PR 3605]. + +[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 + # 0.15.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index e8000966738..be1d853b686 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -151,10 +151,6 @@ pub enum Event { }, /// An inbound reservation has timed out. ReservationTimedOut { src_peer_id: PeerId }, - CircuitReqReceiveFailed { - src_peer_id: PeerId, - error: ConnectionHandlerUpgrErr, - }, /// An inbound circuit request has been denied. CircuitReqDenied { src_peer_id: PeerId, @@ -539,15 +535,6 @@ impl NetworkBehaviour for Behaviour { }; self.queued_actions.push_back(action.into()); } - handler::Event::CircuitReqReceiveFailed { error } => { - self.queued_actions.push_back( - NetworkBehaviourAction::GenerateEvent(Event::CircuitReqReceiveFailed { - src_peer_id: event_source, - error, - }) - .into(), - ); - } handler::Event::CircuitReqDenied { circuit_id, dst_peer_id, diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 44a8ed9d1be..88839f731dd 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -166,10 +166,6 @@ pub enum Event { inbound_circuit_req: inbound_hop::CircuitReq, endpoint: ConnectedPoint, }, - /// Receiving an inbound circuit request failed. - CircuitReqReceiveFailed { - error: ConnectionHandlerUpgrErr, - }, /// An inbound circuit request has been denied. CircuitReqDenied { circuit_id: Option, @@ -255,10 +251,6 @@ impl fmt::Debug for Event { .debug_struct("Event::CircuitReqReceived") .field("endpoint", endpoint) .finish(), - Event::CircuitReqReceiveFailed { error } => f - .debug_struct("Event::CircuitReqReceiveFailed") - .field("error", error) - .finish(), Event::CircuitReqDenied { circuit_id, dst_peer_id, From b38841fe54c8424a0aabf4659ba6c2255039e9c3 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:14:18 +0100 Subject: [PATCH 08/16] Remove `libp2p::relay::Event::InboundCircuitReqFailed` --- protocols/relay/CHANGELOG.md | 4 ++-- protocols/relay/src/priv_client.rs | 8 -------- protocols/relay/src/priv_client/handler.rs | 4 ---- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 1a990694674..e36e4cad52c 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,7 +1,7 @@ # 0.16.0 -- Remove `Event::CircuitReqReceiveFailed` variant. - This variant is no longer constructed. +- Remove `Event::CircuitReqReceiveFailed` and `Event::InboundCircuitReqFailed` variants. + These variants are no longer constructed. See [PR 3605]. [PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index 63140936791..745fb2438b8 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -80,10 +80,6 @@ pub enum Event { src_peer_id: PeerId, limit: Option, }, - InboundCircuitReqFailed { - relay_peer_id: PeerId, - error: ConnectionHandlerUpgrErr, - }, /// An inbound circuit request has been denied. InboundCircuitReqDenied { src_peer_id: PeerId }, /// Denying an inbound circuit request failed. @@ -284,10 +280,6 @@ impl NetworkBehaviour for Behaviour { handler::Event::InboundCircuitEstablished { src_peer_id, limit } => { Event::InboundCircuitEstablished { src_peer_id, limit } } - handler::Event::InboundCircuitReqFailed { error } => Event::InboundCircuitReqFailed { - relay_peer_id: event_source, - error, - }, handler::Event::InboundCircuitReqDenied { src_peer_id } => { Event::InboundCircuitReqDenied { src_peer_id } } diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 74e16c685e3..82409f77dc7 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -97,10 +97,6 @@ pub enum Event { src_peer_id: PeerId, limit: Option, }, - /// An inbound circuit request has failed. - InboundCircuitReqFailed { - error: ConnectionHandlerUpgrErr, - }, /// An inbound circuit request has been denied. InboundCircuitReqDenied { src_peer_id: PeerId }, /// Denying an inbound circuit request failed. From cea2a3d86f59ec03bf43025288c2bc1c51fba119 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:18:18 +0100 Subject: [PATCH 09/16] Remove `libp2p_request_response::InboundFailure::UnsupportedProtocols` --- protocols/request-response/CHANGELOG.md | 8 +++++++ protocols/request-response/src/handler.rs | 13 ---------- protocols/request-response/src/lib.rs | 29 ----------------------- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index b75aa841ad2..be38b44bfd3 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.25.0 - unreleased + +- Remove `InboundFailure::UnsupportedProtocols`. + This variant is no longer constructed. + See [PR 3605]. + +[PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605 + # 0.24.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index d5ad5cdfce2..07a1389cc6e 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -209,11 +209,6 @@ where OutboundTimeout(RequestId), /// An outbound request failed to negotiate a mutually supported protocol. OutboundUnsupportedProtocols(RequestId), - /// An inbound request timed out while waiting for the request - /// or sending the response. - InboundTimeout(RequestId), - /// An inbound request failed to negotiate a mutually supported protocol. - InboundUnsupportedProtocols(RequestId), } impl fmt::Debug for Event { @@ -250,14 +245,6 @@ impl fmt::Debug for Event { .debug_tuple("Event::OutboundUnsupportedProtocols") .field(request_id) .finish(), - Event::InboundTimeout(request_id) => f - .debug_tuple("Event::InboundTimeout") - .field(request_id) - .finish(), - Event::InboundUnsupportedProtocols(request_id) => f - .debug_tuple("Event::InboundUnsupportedProtocols") - .field(request_id) - .finish(), } } } diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 707be901bba..91ac5f938e7 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -910,22 +910,6 @@ where }, )); } - handler::Event::InboundTimeout(request_id) => { - // Note: `Event::InboundTimeout` is emitted both for timing - // out to receive the request and for timing out sending the response. In the former - // case the request is never added to `pending_outbound_responses` and thus one can - // not assert the request_id to be present before removing it. - self.remove_pending_outbound_response(&peer, connection, request_id); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - Event::InboundFailure { - peer, - request_id, - error: InboundFailure::Timeout, - }, - )); - } handler::Event::OutboundUnsupportedProtocols(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( @@ -942,19 +926,6 @@ where }, )); } - handler::Event::InboundUnsupportedProtocols(request_id) => { - // Note: No need to call `self.remove_pending_outbound_response`, - // `Event::Request` was never emitted for this request and - // thus request was never added to `pending_outbound_responses`. - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - Event::InboundFailure { - peer, - request_id, - error: InboundFailure::UnsupportedProtocols, - }, - )); - } } } From 27bb8ec6202a51cd3a4cf799bb273e02ee063caa Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 15 Mar 2023 11:19:52 +0100 Subject: [PATCH 10/16] Add unreleased tag --- protocols/relay/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index e36e4cad52c..80903bda424 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.16.0 +# 0.16.0 - unreleased - Remove `Event::CircuitReqReceiveFailed` and `Event::InboundCircuitReqFailed` variants. These variants are no longer constructed. From 4010813d8af92053d56d97595782b26e8fa7708f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 21 Mar 2023 18:54:28 +0100 Subject: [PATCH 11/16] Add changelog entry --- protocols/gossipsub/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index b3accf6ef18..150ad0e581b 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -3,7 +3,11 @@ - Signed messages now use sequential integers in the sequence number field. See [PR 3551]. +- Gracefully disable handler upon upgrade errors instead of closing the entire connection. + See [PR 3625]. + [PR 3551]: https://github.com/libp2p/rust-libp2p/pull/3551 +[PR 3625]: https://github.com/libp2p/rust-libp2p/pull/3625 # 0.44.1 From 6d43cff2c4fc5708bf010999a1f6e73683410d13 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 16:50:25 +0100 Subject: [PATCH 12/16] Fix perf protocol --- protocols/perf/src/client/handler.rs | 9 +-------- protocols/perf/src/server/handler.rs | 12 ++---------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index f75a43f0a4e..9c16e06d186 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -138,14 +138,7 @@ impl ConnectionHandler for Handler { result: Err(error), })), ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { - match error { - ConnectionHandlerUpgrErr::Timeout => {} - ConnectionHandlerUpgrErr::Timer => {} - ConnectionHandlerUpgrErr::Upgrade(error) => match error { - libp2p_core::UpgradeError::Select(_) => {} - libp2p_core::UpgradeError::Apply(v) => void::unreachable(v), - }, - } + void::unreachable(error) } } } diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index 2946b6d4a4c..b168d0cff24 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -30,8 +30,7 @@ use libp2p_swarm::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, ListenUpgradeError, }, - ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, - SubstreamProtocol, + ConnectionHandler, ConnectionHandlerEvent, KeepAlive, SubstreamProtocol, }; use log::error; use void::Void; @@ -106,14 +105,7 @@ impl ConnectionHandler for Handler { } ConnectionEvent::AddressChange(_) => {} ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { - match error { - ConnectionHandlerUpgrErr::Timeout => {} - ConnectionHandlerUpgrErr::Timer => {} - ConnectionHandlerUpgrErr::Upgrade(error) => match error { - libp2p_core::UpgradeError::Select(_) => {} - libp2p_core::UpgradeError::Apply(v) => void::unreachable(v), - }, - } + void::unreachable(error) } } } From 40a3d3df328c2f3af9e8d7cf3b5c04b3ce0b8839 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 24 Mar 2023 15:08:23 +0100 Subject: [PATCH 13/16] Remove wrong changelog entry --- protocols/gossipsub/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 150ad0e581b..b3accf6ef18 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -3,11 +3,7 @@ - Signed messages now use sequential integers in the sequence number field. See [PR 3551]. -- Gracefully disable handler upon upgrade errors instead of closing the entire connection. - See [PR 3625]. - [PR 3551]: https://github.com/libp2p/rust-libp2p/pull/3551 -[PR 3625]: https://github.com/libp2p/rust-libp2p/pull/3625 # 0.44.1 From 7f47dda064b1da55e4b201edbc2d93fa1d804f42 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sun, 16 Apr 2023 11:25:37 +0200 Subject: [PATCH 14/16] Fix compile errors --- protocols/gossipsub/src/handler.rs | 2 +- swarm/src/handler.rs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 609bb81a306..59ccb726577 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -525,7 +525,7 @@ impl ConnectionHandler for Handler { handler.on_fully_negotiated_outbound(fully_negotiated_outbound) } ConnectionEvent::DialUpgradeError(DialUpgradeError { - error: ConnectionHandlerUpgrErr::Timeout | ConnectionHandlerUpgrErr::Timer, + error: ConnectionHandlerUpgrErr::Timeout, .. }) => { log::debug!("Dial upgrade error: Protocol negotiation timeout"); diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index a4dee8cf213..b3810b9711b 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -229,15 +229,11 @@ impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> /// Whether the event concerns an inbound stream. pub fn is_inbound(&self) -> bool { - // Note: This will get simpler with https://github.com/libp2p/rust-libp2p/pull/3605. match self { - ConnectionEvent::FullyNegotiatedInbound(_) - | ConnectionEvent::ListenUpgradeError(ListenUpgradeError { - error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(_)), // Only `Select` is relevant, the others may be for other handlers too. - .. - }) => true, + ConnectionEvent::FullyNegotiatedInbound(_) | ConnectionEvent::ListenUpgradeError(_) => { + true + } ConnectionEvent::FullyNegotiatedOutbound(_) - | ConnectionEvent::ListenUpgradeError(_) | ConnectionEvent::AddressChange(_) | ConnectionEvent::DialUpgradeError(_) => false, } From 5c89fd745181d09a14248d91d577cf5503b1a5e6 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 4 May 2023 10:24:01 +0200 Subject: [PATCH 15/16] Fix compile errors --- protocols/perf/src/server/handler.rs | 3 +-- swarm/src/handler/multi.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index da42d76d150..d279c0d1700 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -30,8 +30,7 @@ use libp2p_swarm::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, ListenUpgradeError, }, - ConnectionHandler, ConnectionHandlerEvent, KeepAlive,StreamProtocol, - SubstreamProtocol, + ConnectionHandler, ConnectionHandlerEvent, KeepAlive, StreamProtocol, SubstreamProtocol, }; use log::error; use void::Void; diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index ecde1ecbf0b..a90dc528ca2 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -31,7 +31,6 @@ use crate::handler::{ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; use futures::{future::BoxFuture, prelude::*}; -use libp2p_core::upgrade::ProtocolName; use libp2p_core::ConnectedPoint; use libp2p_identity::PeerId; use rand::Rng; From 956b814c9057dd6547a5d19003e81c546b6cab89 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 4 May 2023 10:24:58 +0200 Subject: [PATCH 16/16] Update changelog --- protocols/request-response/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 0963a3c83d5..b2adb03c67b 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -4,8 +4,8 @@ See [PR 3715]. - Remove deprecated `RequestResponse` prefixed items. See [PR 3702]. -- Remove `InboundFailure::UnsupportedProtocols`. - This variant is no longer constructed. +- Remove `InboundFailure::UnsupportedProtocols` and `InboundFailure::InboundTimeout`. + These variants are no longer constructed. See [PR 3605]. [PR 3605]: https://github.com/libp2p/rust-libp2p/pull/3605