From 9c5c369744b0bb5546c773fa8e942bf44db057eb Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Mon, 18 Mar 2024 20:12:44 +0800 Subject: [PATCH 1/7] mark {In, Out}boundOpenInfo as deprecated --- protocols/dcutr/src/handler/relayed.rs | 18 +++++++++--------- protocols/gossipsub/src/handler.rs | 12 ++++++------ protocols/identify/src/handler.rs | 12 ++++++------ protocols/kad/src/handler.rs | 12 ++++++------ protocols/perf/src/client/handler.rs | 10 +++++----- protocols/perf/src/server/handler.rs | 8 ++++---- protocols/ping/src/handler.rs | 6 +++--- protocols/relay/src/behaviour/handler.rs | 12 ++++++------ protocols/relay/src/priv_client/handler.rs | 10 +++++----- protocols/request-response/src/handler.rs | 14 +++++++------- protocols/stream/src/handler.rs | 8 ++++---- swarm/src/behaviour/toggle.rs | 6 ++++-- swarm/src/connection.rs | 20 ++++++++++++-------- swarm/src/connection/pool.rs | 1 + swarm/src/dummy.rs | 8 ++++---- swarm/src/handler.rs | 3 +++ swarm/src/handler/either.rs | 1 + swarm/src/handler/map_in.rs | 1 + swarm/src/handler/map_out.rs | 1 + swarm/src/handler/multi.rs | 2 ++ swarm/src/handler/one_shot.rs | 8 ++++---- swarm/src/handler/pending.rs | 8 ++++---- swarm/src/handler/select.rs | 2 ++ swarm/tests/connection_close.rs | 8 ++++---- 24 files changed, 104 insertions(+), 87 deletions(-) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index eba58f89313..75c27dcf4b3 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -60,7 +60,7 @@ pub struct Handler { queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, >, @@ -95,7 +95,7 @@ impl Handler { protocol: output, .. }: FullyNegotiatedInbound< ::InboundProtocol, - ::InboundOpenInfo, + (), >, ) { match output { @@ -125,7 +125,7 @@ impl Handler { protocol: stream, .. }: FullyNegotiatedOutbound< ::OutboundProtocol, - ::OutboundOpenInfo, + (), >, ) { assert!( @@ -149,7 +149,7 @@ impl Handler { fn on_listen_upgrade_error( &mut self, ListenUpgradeError { error, .. }: ListenUpgradeError< - ::InboundOpenInfo, + (), ::InboundProtocol, >, ) { @@ -159,7 +159,7 @@ impl Handler { fn on_dial_upgrade_error( &mut self, DialUpgradeError { error, .. }: DialUpgradeError< - ::OutboundOpenInfo, + (), ::OutboundProtocol, >, ) { @@ -185,7 +185,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self.endpoint { ConnectedPoint::Dialer { .. } => { SubstreamProtocol::new(Either::Left(ReadyUpgrade::new(PROTOCOL_NAME)), ()) @@ -226,7 +226,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { // Return queued events. if let Some(event) = self.queued_events.pop_front() { @@ -287,8 +287,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index e91f81776e7..7be302349d9 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -195,7 +195,7 @@ impl EnabledHandler { &mut self, FullyNegotiatedOutbound { protocol, .. }: FullyNegotiatedOutbound< ::OutboundProtocol, - ::OutboundOpenInfo, + (), >, ) { let (substream, peer_kind) = protocol; @@ -218,7 +218,7 @@ impl EnabledHandler { ) -> Poll< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, > { @@ -395,7 +395,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type OutboundProtocol = ProtocolConfig; - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self { Handler::Enabled(handler) => { SubstreamProtocol::new(either::Either::Left(handler.listen_protocol.clone()), ()) @@ -432,7 +432,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { match self { Handler::Enabled(handler) => handler.poll(cx), @@ -455,8 +455,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match self { diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index f9b77e0b63a..e556789587f 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -152,7 +152,7 @@ impl Handler { protocol: output, .. }: FullyNegotiatedInbound< ::InboundProtocol, - ::InboundOpenInfo, + (), >, ) { match output { @@ -191,7 +191,7 @@ impl Handler { protocol: output, .. }: FullyNegotiatedOutbound< ::OutboundProtocol, - ::OutboundOpenInfo, + (), >, ) { match output { @@ -287,7 +287,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new( SelectUpgrade::new( ReadyUpgrade::new(PROTOCOL_NAME), @@ -318,7 +318,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll> { + ) -> Poll> { if let Some(event) = self.events.pop() { return Poll::Ready(event); } @@ -384,8 +384,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 5e7c2e21b8b..ef0eb90f62e 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -472,7 +472,7 @@ impl Handler { info: (), }: FullyNegotiatedOutbound< ::OutboundProtocol, - ::OutboundOpenInfo, + (), >, ) { if let Some(sender) = self.pending_streams.pop_front() { @@ -494,7 +494,7 @@ impl Handler { &mut self, FullyNegotiatedInbound { protocol, .. }: FullyNegotiatedInbound< ::InboundProtocol, - ::InboundOpenInfo, + (), >, ) { // If `self.allow_listening` is false, then we produced a `DeniedUpgrade` and `protocol` @@ -599,7 +599,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self.mode { Mode::Server => SubstreamProtocol::new(Either::Left(self.protocol_config.clone()), ()), Mode::Client => SubstreamProtocol::new(Either::Right(upgrade::DeniedUpgrade), ()), @@ -711,7 +711,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { match &mut self.protocol_status { @@ -782,8 +782,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index 2a2c5499fc2..4f5532f54c0 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -56,7 +56,7 @@ pub struct Handler { queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, >, @@ -90,7 +90,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -107,8 +107,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { @@ -156,7 +156,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index ddfe8f881e5..3866f94f3f8 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -68,7 +68,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = Void; type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), ()) } @@ -81,8 +81,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + Void, >, ) { match event { @@ -120,7 +120,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { match self.inbound.poll_unpin(cx) { diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 5e6fc2cd2cf..cefe856e56c 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -178,7 +178,7 @@ impl Handler { fn on_dial_upgrade_error( &mut self, DialUpgradeError { error, .. }: DialUpgradeError< - ::OutboundOpenInfo, + (), ::OutboundProtocol, >, ) { @@ -328,8 +328,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 958c6a9b906..4fd52d222a1 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -337,7 +337,7 @@ pub struct Handler { queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, >, @@ -441,7 +441,7 @@ impl Handler { fn on_dial_upgrade_error( &mut self, DialUpgradeError { error, .. }: DialUpgradeError< - ::OutboundOpenInfo, + (), ::OutboundProtocol, >, ) { @@ -486,7 +486,7 @@ impl ConnectionHandler for Handler { type OutboundProtocol = ReadyUpgrade; type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()) } @@ -591,7 +591,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { // Return queued events. if let Some(event) = self.queued_events.pop_front() { @@ -871,8 +871,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 662d63cc742..ea1d910f54f 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -101,7 +101,7 @@ pub struct Handler { queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, >, @@ -235,7 +235,7 @@ impl ConnectionHandler for Handler { type OutboundProtocol = ReadyUpgrade; type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(STOP_PROTOCOL_NAME), ()) } @@ -262,7 +262,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { // Reservations @@ -423,8 +423,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 2d45e0d7dc3..e5721337e47 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -127,7 +127,7 @@ where info: (), }: FullyNegotiatedInbound< ::InboundProtocol, - ::InboundOpenInfo, + (), >, ) { let mut codec = self.codec.clone(); @@ -175,7 +175,7 @@ where info: (), }: FullyNegotiatedOutbound< ::OutboundProtocol, - ::OutboundOpenInfo, + (), >, ) { let message = self @@ -211,7 +211,7 @@ where fn on_dial_upgrade_error( &mut self, DialUpgradeError { error, info: () }: DialUpgradeError< - ::OutboundOpenInfo, + (), ::OutboundProtocol, >, ) { @@ -247,7 +247,7 @@ where fn on_listen_upgrade_error( &mut self, ListenUpgradeError { error, .. }: ListenUpgradeError< - ::InboundOpenInfo, + (), ::InboundProtocol, >, ) { @@ -372,7 +372,7 @@ where type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new( Protocol { protocols: self.inbound_protocols.clone(), @@ -465,8 +465,8 @@ where event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/stream/src/handler.rs b/protocols/stream/src/handler.rs index f63b93c1761..50f418934d3 100644 --- a/protocols/stream/src/handler.rs +++ b/protocols/stream/src/handler.rs @@ -53,7 +53,7 @@ impl ConnectionHandler for Handler { fn listen_protocol( &self, - ) -> swarm::SubstreamProtocol { + ) -> swarm::SubstreamProtocol { swarm::SubstreamProtocol::new( Upgrade { supported_protocols: Shared::lock(&self.shared).supported_inbound_protocols(), @@ -68,7 +68,7 @@ impl ConnectionHandler for Handler { ) -> Poll< swarm::ConnectionHandlerEvent< Self::OutboundProtocol, - Self::OutboundOpenInfo, + (), Self::ToBehaviour, >, > { @@ -104,8 +104,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index e81c5343701..449eaab5b04 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -194,7 +194,8 @@ pub struct ToggleConnectionHandler { impl ToggleConnectionHandler where TInner: ConnectionHandler, -{ +{ + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_fully_negotiated_inbound( &mut self, FullyNegotiatedInbound { @@ -224,7 +225,7 @@ where panic!("Unexpected Either::Right in enabled `on_fully_negotiated_inbound`.") } } - + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { info, error: err }: ListenUpgradeError< @@ -258,6 +259,7 @@ where } } +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for ToggleConnectionHandler where TInner: ConnectionHandler, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 15c49bb7bd5..724c06d27a2 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -117,6 +117,7 @@ where /// The underlying handler. handler: THandler, /// Futures that upgrade incoming substreams. + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. negotiating_in: FuturesUnordered< StreamUpgrade< THandler::InboundOpenInfo, @@ -125,6 +126,7 @@ where >, >, /// Futures that upgrade outgoing substreams. + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. negotiating_out: FuturesUnordered< StreamUpgrade< THandler::OutboundOpenInfo, @@ -149,6 +151,7 @@ where /// /// The upgrade timeout is already ticking here so this may fail in case the remote is not quick /// enough in providing us with a new stream. + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. requested_substreams: FuturesUnordered< SubstreamRequested, >, @@ -159,6 +162,7 @@ where stream_counter: ActiveStreamCounter, } +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl fmt::Debug for Connection where THandler: ConnectionHandler + fmt::Debug, @@ -1149,7 +1153,7 @@ mod tests { fn listen_protocol( &self, - ) -> SubstreamProtocol { + ) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()).with_timeout(self.upgrade_timeout) } @@ -1158,8 +1162,8 @@ mod tests { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + () >, ) { match event { @@ -1195,7 +1199,7 @@ mod tests { ) -> Poll< ConnectionHandlerEvent< Self::OutboundProtocol, - Self::OutboundOpenInfo, + (), Self::ToBehaviour, >, > { @@ -1221,7 +1225,7 @@ mod tests { fn listen_protocol( &self, - ) -> SubstreamProtocol { + ) -> SubstreamProtocol { SubstreamProtocol::new( ManyProtocolsUpgrade { protocols: Vec::from_iter(self.active_protocols.clone()), @@ -1235,8 +1239,8 @@ mod tests { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { @@ -1270,7 +1274,7 @@ mod tests { ) -> Poll< ConnectionHandlerEvent< Self::OutboundProtocol, - Self::OutboundOpenInfo, + (), Self::ToBehaviour, >, > { diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 9bcd1b446d3..5a4880bc8fa 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -548,6 +548,7 @@ where /// Polls the connection pool for events. #[tracing::instrument(level = "debug", name = "Pool::poll", skip(self, cx))] + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll> where THandler: ConnectionHandler + 'static, diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 86df676443b..b86b9d628e1 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -69,7 +69,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { type InboundOpenInfo = (); type OutboundOpenInfo = Void; - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -81,7 +81,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { Poll::Pending } @@ -91,8 +91,8 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + Void, >, ) { match event { diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 31d2c91e391..a312f72d03e 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -97,6 +97,7 @@ use std::{error, fmt, io, task::Context, task::Poll, time::Duration}; /// Implementors of this trait should keep in mind that the connection can be closed at any time. /// When a connection is closed gracefully, the substreams used by the handler may still /// continue reading data until the remote closes its side of the connection. +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. pub trait ConnectionHandler: Send + 'static { /// A type representing the message(s) a [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour) can send to a [`ConnectionHandler`] via [`ToSwarm::NotifyHandler`](crate::behaviour::ToSwarm::NotifyHandler) type FromBehaviour: fmt::Debug + Send + 'static; @@ -107,8 +108,10 @@ pub trait ConnectionHandler: Send + 'static { /// The outbound upgrade for the protocol(s) used by the handler. type OutboundProtocol: OutboundUpgradeSend; /// The type of additional information returned from `listen_protocol`. + #[deprecated] type InboundOpenInfo: Send + 'static; /// The type of additional information passed to an `OutboundSubstreamRequest`. + #[deprecated] type OutboundOpenInfo: Send + 'static; /// The [`InboundUpgrade`](libp2p_core::upgrade::InboundUpgrade) to apply on inbound diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index a5aab9b5fee..063d349a96e 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -73,6 +73,7 @@ where /// Implementation of a [`ConnectionHandler`] that represents either of two [`ConnectionHandler`] /// implementations. +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for Either where L: ConnectionHandler, diff --git a/swarm/src/handler/map_in.rs b/swarm/src/handler/map_in.rs index 9316ef4d2ce..4f209ae1c8e 100644 --- a/swarm/src/handler/map_in.rs +++ b/swarm/src/handler/map_in.rs @@ -42,6 +42,7 @@ impl MapInEvent ConnectionHandler for MapInEvent where diff --git a/swarm/src/handler/map_out.rs b/swarm/src/handler/map_out.rs index f877bfa6f64..224194afae0 100644 --- a/swarm/src/handler/map_out.rs +++ b/swarm/src/handler/map_out.rs @@ -39,6 +39,7 @@ impl MapOutEvent { } } +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for MapOutEvent where TConnectionHandler: ConnectionHandler, diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 96a77626c01..df62a21b05a 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -81,6 +81,7 @@ where Ok(m) } + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { @@ -102,6 +103,7 @@ where } } +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for MultiHandler where K: Clone + Debug + Hash + Eq + Send + 'static, diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index b1fc41e9098..df0f3b0812b 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -120,7 +120,7 @@ where type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { self.listen_protocol.clone() } @@ -132,7 +132,7 @@ where &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { if !self.events_out.is_empty() { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( @@ -163,8 +163,8 @@ where event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/swarm/src/handler/pending.rs b/swarm/src/handler/pending.rs index 23b9adcfd90..2b64439ffde 100644 --- a/swarm/src/handler/pending.rs +++ b/swarm/src/handler/pending.rs @@ -47,7 +47,7 @@ impl ConnectionHandler for PendingConnectionHandler { type OutboundOpenInfo = Void; type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ()) } @@ -59,7 +59,7 @@ impl ConnectionHandler for PendingConnectionHandler { &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { Poll::Pending } @@ -69,8 +69,8 @@ impl ConnectionHandler for PendingConnectionHandler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + Void, >, ) { match event { diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index e049252d448..ed1addf1a69 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -145,6 +145,7 @@ where TProto1: ConnectionHandler, TProto2: ConnectionHandler, { + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { @@ -174,6 +175,7 @@ where } } +#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for ConnectionHandlerSelect where TProto1: ConnectionHandler, diff --git a/swarm/tests/connection_close.rs b/swarm/tests/connection_close.rs index 4efe8d17e49..e23e138b442 100644 --- a/swarm/tests/connection_close.rs +++ b/swarm/tests/connection_close.rs @@ -101,7 +101,7 @@ impl ConnectionHandler for HandlerWithState { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -113,7 +113,7 @@ impl ConnectionHandler for HandlerWithState { &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { Poll::Pending } @@ -138,8 +138,8 @@ impl ConnectionHandler for HandlerWithState { _: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { } From 48a98299d507d97bdde19da8d9a943cded37fd7f Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Mon, 2 Dec 2024 14:43:31 +0800 Subject: [PATCH 2/7] remove Void type and suppress 'deprecated' warning --- protocols/autonat/src/v2/client/handler/dial_back.rs | 1 + protocols/autonat/src/v2/client/handler/dial_request.rs | 2 ++ protocols/autonat/src/v2/server/handler/dial_back.rs | 1 + protocols/autonat/src/v2/server/handler/dial_request.rs | 1 + protocols/perf/src/server/handler.rs | 4 ++-- swarm/benches/connection_handler.rs | 2 ++ swarm/src/dummy.rs | 6 +++--- swarm/src/handler/pending.rs | 4 ++-- 8 files changed, 14 insertions(+), 7 deletions(-) diff --git a/protocols/autonat/src/v2/client/handler/dial_back.rs b/protocols/autonat/src/v2/client/handler/dial_back.rs index ef544a4c77a..36c28377ec2 100644 --- a/protocols/autonat/src/v2/client/handler/dial_back.rs +++ b/protocols/autonat/src/v2/client/handler/dial_back.rs @@ -27,6 +27,7 @@ impl Handler { } } +#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = Infallible; type ToBehaviour = IncomingNonce; diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index fff83ad9453..a5d806b04bb 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -69,6 +69,7 @@ pub enum DialBackError { } pub struct Handler { + #[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, @@ -113,6 +114,7 @@ impl Handler { } } +#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = DialRequest; type ToBehaviour = ToBehaviour; diff --git a/protocols/autonat/src/v2/server/handler/dial_back.rs b/protocols/autonat/src/v2/server/handler/dial_back.rs index 61593da318d..d06f6e44ca1 100644 --- a/protocols/autonat/src/v2/server/handler/dial_back.rs +++ b/protocols/autonat/src/v2/server/handler/dial_back.rs @@ -38,6 +38,7 @@ impl Handler { } } +#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = (); type ToBehaviour = ToBehaviour; diff --git a/protocols/autonat/src/v2/server/handler/dial_request.rs b/protocols/autonat/src/v2/server/handler/dial_request.rs index 5058e0f3f42..2f3dbb4815e 100644 --- a/protocols/autonat/src/v2/server/handler/dial_request.rs +++ b/protocols/autonat/src/v2/server/handler/dial_request.rs @@ -70,6 +70,7 @@ where } } +#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler where R: RngCore + Send + Clone + 'static, diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index 746cf7fe2a0..6c49804f5a8 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -86,7 +86,7 @@ impl ConnectionHandler for Handler { Self::InboundProtocol, Self::OutboundProtocol, (), - Void, + Infallible, >, ) { match event { @@ -130,7 +130,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { match self.inbound.poll_unpin(cx) { diff --git a/swarm/benches/connection_handler.rs b/swarm/benches/connection_handler.rs index a5e47528308..5ea90a3e5e7 100644 --- a/swarm/benches/connection_handler.rs +++ b/swarm/benches/connection_handler.rs @@ -268,6 +268,8 @@ struct SpinningHandler { protocols: &'static [StreamProtocol], } +// TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. +#[allow(deprecated)] impl ConnectionHandler for SpinningHandler { type FromBehaviour = Infallible; diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index def505bca91..526008d696d 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -71,7 +71,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { type InboundProtocol = DeniedUpgrade; type OutboundProtocol = DeniedUpgrade; type InboundOpenInfo = (); - type OutboundOpenInfo = Infallible; + type OutboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) @@ -87,7 +87,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { Poll::Pending } @@ -98,7 +98,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { Self::InboundProtocol, Self::OutboundProtocol, (), - Void, + (), >, ) { match event { diff --git a/swarm/src/handler/pending.rs b/swarm/src/handler/pending.rs index 3b6d4369949..a1c832b7870 100644 --- a/swarm/src/handler/pending.rs +++ b/swarm/src/handler/pending.rs @@ -65,7 +65,7 @@ impl ConnectionHandler for PendingConnectionHandler { &mut self, _: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { Poll::Pending } @@ -76,7 +76,7 @@ impl ConnectionHandler for PendingConnectionHandler { Self::InboundProtocol, Self::OutboundProtocol, (), - Void, + Infallible, >, ) { match event { From e213fc4ed136226300162c48afc6c24835877689 Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Mon, 2 Dec 2024 14:55:52 +0800 Subject: [PATCH 3/7] use concrete type to suppress warning instead --- protocols/autonat/src/v2/client/handler/dial_back.rs | 9 ++++----- .../autonat/src/v2/client/handler/dial_request.rs | 12 +++++------- protocols/autonat/src/v2/server/handler/dial_back.rs | 9 ++++----- .../autonat/src/v2/server/handler/dial_request.rs | 9 ++++----- swarm/benches/connection_handler.rs | 9 ++++----- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/protocols/autonat/src/v2/client/handler/dial_back.rs b/protocols/autonat/src/v2/client/handler/dial_back.rs index 36c28377ec2..fce01b2392c 100644 --- a/protocols/autonat/src/v2/client/handler/dial_back.rs +++ b/protocols/autonat/src/v2/client/handler/dial_back.rs @@ -27,7 +27,6 @@ impl Handler { } } -#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = Infallible; type ToBehaviour = IncomingNonce; @@ -36,7 +35,7 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(DIAL_BACK_PROTOCOL), ()) } @@ -44,7 +43,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { match self.inbound.poll_next_unpin(cx) { @@ -72,8 +71,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index a5d806b04bb..e01a5f6c934 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -69,11 +69,10 @@ pub enum DialBackError { } pub struct Handler { - #[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. queued_events: VecDeque< ConnectionHandlerEvent< ::OutboundProtocol, - ::OutboundOpenInfo, + (), ::ToBehaviour, >, >, @@ -114,7 +113,6 @@ impl Handler { } } -#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = DialRequest; type ToBehaviour = ToBehaviour; @@ -123,7 +121,7 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -131,7 +129,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); @@ -166,8 +164,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/autonat/src/v2/server/handler/dial_back.rs b/protocols/autonat/src/v2/server/handler/dial_back.rs index d06f6e44ca1..09b2e6a42de 100644 --- a/protocols/autonat/src/v2/server/handler/dial_back.rs +++ b/protocols/autonat/src/v2/server/handler/dial_back.rs @@ -38,7 +38,6 @@ impl Handler { } } -#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler { type FromBehaviour = (); type ToBehaviour = ToBehaviour; @@ -47,7 +46,7 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -55,7 +54,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { if let Poll::Ready(result) = self.outbound.poll_unpin(cx) { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( @@ -80,8 +79,8 @@ impl ConnectionHandler for Handler { event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/protocols/autonat/src/v2/server/handler/dial_request.rs b/protocols/autonat/src/v2/server/handler/dial_request.rs index 2f3dbb4815e..109daba10d8 100644 --- a/protocols/autonat/src/v2/server/handler/dial_request.rs +++ b/protocols/autonat/src/v2/server/handler/dial_request.rs @@ -70,7 +70,6 @@ where } } -#[allow(deprecated)] // TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. impl ConnectionHandler for Handler where R: RngCore + Send + Clone + 'static, @@ -82,7 +81,7 @@ where type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(DIAL_REQUEST_PROTOCOL), ()) } @@ -90,7 +89,7 @@ where &mut self, cx: &mut Context<'_>, ) -> Poll< - ConnectionHandlerEvent, + ConnectionHandlerEvent, > { loop { match self.inbound.poll_unpin(cx) { @@ -121,8 +120,8 @@ where event: ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { match event { diff --git a/swarm/benches/connection_handler.rs b/swarm/benches/connection_handler.rs index 5ea90a3e5e7..d68c27e9375 100644 --- a/swarm/benches/connection_handler.rs +++ b/swarm/benches/connection_handler.rs @@ -268,7 +268,6 @@ struct SpinningHandler { protocols: &'static [StreamProtocol], } -// TODO: Remove when {In,Out}boundOpenInfo is fully deprecated. #[allow(deprecated)] impl ConnectionHandler for SpinningHandler { type FromBehaviour = Infallible; @@ -285,7 +284,7 @@ impl ConnectionHandler for SpinningHandler { fn listen_protocol( &self, - ) -> libp2p_swarm::SubstreamProtocol { + ) -> libp2p_swarm::SubstreamProtocol { libp2p_swarm::SubstreamProtocol::new(Upgrade(self.protocols), ()) } @@ -295,7 +294,7 @@ impl ConnectionHandler for SpinningHandler { ) -> std::task::Poll< libp2p_swarm::ConnectionHandlerEvent< Self::OutboundProtocol, - Self::OutboundOpenInfo, + (), Self::ToBehaviour, >, > { @@ -324,8 +323,8 @@ impl ConnectionHandler for SpinningHandler { _event: libp2p_swarm::handler::ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, + (), + (), >, ) { } From 191ab0e45557ef0713f800901b41cfae6cd66da2 Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Tue, 10 Dec 2024 18:24:41 +0800 Subject: [PATCH 4/7] remove unnecessary allow-deprecated --- swarm/benches/connection_handler.rs | 1 - swarm/src/connection.rs | 4 ++-- swarm/src/handler.rs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/swarm/benches/connection_handler.rs b/swarm/benches/connection_handler.rs index d68c27e9375..86edc963489 100644 --- a/swarm/benches/connection_handler.rs +++ b/swarm/benches/connection_handler.rs @@ -268,7 +268,6 @@ struct SpinningHandler { protocols: &'static [StreamProtocol], } -#[allow(deprecated)] impl ConnectionHandler for SpinningHandler { type FromBehaviour = Infallible; diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index ac054791a1b..60f279266f8 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -155,9 +155,9 @@ where max_negotiating_inbound_streams: usize, /// Contains all upgrades that are waiting for a new outbound substream. /// - /// The upgrade timeout is already ticking here so this may fail in case the remote is not quick + /// The upgrade timeout is already ticking here so this may fail in case the remote is not /// quick enough in providing us with a new stream. - #[allow(deprecated)] + #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. requested_substreams: FuturesUnordered< SubstreamRequested, >, diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index d3256797c46..9a3ea2493c2 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -113,10 +113,10 @@ pub trait ConnectionHandler: Send + 'static { /// The outbound upgrade for the protocol(s) used by the handler. type OutboundProtocol: OutboundUpgradeSend; /// The type of additional information returned from `listen_protocol`. - #[deprecated] + #[deprecated = "Track data in ConnectionHandler instead."] type InboundOpenInfo: Send + 'static; /// The type of additional information passed to an `OutboundSubstreamRequest`. - #[deprecated] + #[deprecated = "Track data in ConnectionHandler instead."] type OutboundOpenInfo: Send + 'static; /// The [`InboundUpgrade`](libp2p_core::upgrade::InboundUpgrade) to apply on inbound From 4a795f529ec868ea63aba00c9a1f6224b61acdd9 Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Tue, 10 Dec 2024 19:25:41 +0800 Subject: [PATCH 5/7] remove empty tuple with default generic type --- .../src/v2/client/handler/dial_back.rs | 13 ++----- .../src/v2/client/handler/dial_request.rs | 13 ++----- .../src/v2/server/handler/dial_back.rs | 13 ++----- .../src/v2/server/handler/dial_request.rs | 13 ++----- protocols/dcutr/src/handler/relayed.rs | 23 +++-------- protocols/gossipsub/src/handler.rs | 14 ++----- protocols/identify/src/handler.rs | 19 ++-------- protocols/kad/src/handler.rs | 19 ++-------- protocols/perf/src/client/handler.rs | 13 ++----- protocols/perf/src/server/handler.rs | 13 ++----- protocols/ping/src/handler.rs | 9 +---- protocols/relay/src/behaviour/handler.rs | 13 ++----- protocols/relay/src/priv_client/handler.rs | 13 ++----- protocols/request-response/src/handler.rs | 19 ++-------- protocols/stream/src/handler.rs | 19 ++-------- swarm/benches/connection_handler.rs | 12 +----- swarm/src/connection.rs | 38 +++---------------- swarm/src/dummy.rs | 13 ++----- swarm/src/handler.rs | 8 ++-- swarm/src/handler/one_shot.rs | 13 ++----- swarm/src/handler/pending.rs | 13 ++----- swarm/tests/connection_close.rs | 13 ++----- 22 files changed, 73 insertions(+), 263 deletions(-) diff --git a/protocols/autonat/src/v2/client/handler/dial_back.rs b/protocols/autonat/src/v2/client/handler/dial_back.rs index fce01b2392c..7cdf194343a 100644 --- a/protocols/autonat/src/v2/client/handler/dial_back.rs +++ b/protocols/autonat/src/v2/client/handler/dial_back.rs @@ -35,16 +35,14 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(DIAL_BACK_PROTOCOL), ()) } fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { loop { match self.inbound.poll_next_unpin(cx) { Poll::Pending => return Poll::Pending, @@ -68,12 +66,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index e01a5f6c934..61f564505eb 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -121,16 +121,14 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); } @@ -161,12 +159,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::DialUpgradeError(DialUpgradeError { error, .. }) => { diff --git a/protocols/autonat/src/v2/server/handler/dial_back.rs b/protocols/autonat/src/v2/server/handler/dial_back.rs index 09b2e6a42de..8adb33509ef 100644 --- a/protocols/autonat/src/v2/server/handler/dial_back.rs +++ b/protocols/autonat/src/v2/server/handler/dial_back.rs @@ -46,16 +46,14 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { if let Poll::Ready(result) = self.outbound.poll_unpin(cx) { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( result @@ -76,12 +74,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { diff --git a/protocols/autonat/src/v2/server/handler/dial_request.rs b/protocols/autonat/src/v2/server/handler/dial_request.rs index 109daba10d8..22cab2b9cab 100644 --- a/protocols/autonat/src/v2/server/handler/dial_request.rs +++ b/protocols/autonat/src/v2/server/handler/dial_request.rs @@ -81,16 +81,14 @@ where type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(DIAL_REQUEST_PROTOCOL), ()) } fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { loop { match self.inbound.poll_unpin(cx) { Poll::Ready(Ok(event)) => { @@ -117,12 +115,7 @@ where fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index 844be2f6308..47813493e9e 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -98,10 +98,7 @@ impl Handler { &mut self, FullyNegotiatedInbound { protocol: output, .. - }: FullyNegotiatedInbound< - ::InboundProtocol, - (), - >, + }: FullyNegotiatedInbound<::InboundProtocol>, ) { match output { future::Either::Left(stream) => { @@ -130,10 +127,7 @@ impl Handler { &mut self, FullyNegotiatedOutbound { protocol: stream, .. - }: FullyNegotiatedOutbound< - ::OutboundProtocol, - (), - >, + }: FullyNegotiatedOutbound<::OutboundProtocol>, ) { assert!( self.endpoint.is_listener(), @@ -196,7 +190,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self.endpoint { ConnectedPoint::Dialer { .. } => { SubstreamProtocol::new(Either::Left(ReadyUpgrade::new(PROTOCOL_NAME)), ()) @@ -236,9 +230,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { // Return queued events. if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); @@ -295,12 +287,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => { diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index b570ce2c4fa..cec8228c8f6 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -198,7 +198,6 @@ impl EnabledHandler { &mut self, FullyNegotiatedOutbound { protocol, .. }: FullyNegotiatedOutbound< ::OutboundProtocol, - (), >, ) { let (substream, peer_kind) = protocol; @@ -427,7 +426,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type OutboundProtocol = ProtocolConfig; - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self { Handler::Enabled(handler) => { SubstreamProtocol::new(either::Either::Left(handler.listen_protocol.clone()), ()) @@ -462,9 +461,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { match self { Handler::Enabled(handler) => handler.poll(cx), Handler::Disabled(DisabledHandler::ProtocolUnsupported { peer_kind_sent }) => { @@ -483,12 +480,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match self { Handler::Enabled(handler) => { diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 0a119d1cc8c..dc438962fb6 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -159,10 +159,7 @@ impl Handler { &mut self, FullyNegotiatedInbound { protocol: output, .. - }: FullyNegotiatedInbound< - ::InboundProtocol, - (), - >, + }: FullyNegotiatedInbound<::InboundProtocol>, ) { match output { future::Either::Left(stream) => { @@ -198,10 +195,7 @@ impl Handler { &mut self, FullyNegotiatedOutbound { protocol: output, .. - }: FullyNegotiatedOutbound< - ::OutboundProtocol, - (), - >, + }: FullyNegotiatedOutbound<::OutboundProtocol>, ) { match output { future::Either::Left(stream) => { @@ -296,7 +290,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new( SelectUpgrade::new( ReadyUpgrade::new(PROTOCOL_NAME), @@ -390,12 +384,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => { diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 8713a4cf06f..a3bb19447cb 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -476,10 +476,7 @@ impl Handler { FullyNegotiatedOutbound { protocol: stream, info: (), - }: FullyNegotiatedOutbound< - ::OutboundProtocol, - (), - >, + }: FullyNegotiatedOutbound<::OutboundProtocol>, ) { if let Some(sender) = self.pending_streams.pop_front() { let _ = sender.send(Ok(stream)); @@ -500,7 +497,6 @@ impl Handler { &mut self, FullyNegotiatedInbound { protocol, .. }: FullyNegotiatedInbound< ::InboundProtocol, - (), >, ) { // If `self.allow_listening` is false, then we produced a `DeniedUpgrade` and `protocol` @@ -608,7 +604,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { match self.mode { Mode::Server => SubstreamProtocol::new(Either::Left(self.protocol_config.clone()), ()), Mode::Client => SubstreamProtocol::new(Either::Right(upgrade::DeniedUpgrade), ()), @@ -719,9 +715,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { loop { match &mut self.protocol_status { Some(status) if !status.reported => { @@ -788,12 +782,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedOutbound(fully_negotiated_outbound) => { diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index 5ad6b9f657c..043790822b5 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -92,7 +92,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -106,12 +106,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { // TODO: remove when Rust 1.82 is MSRV @@ -161,9 +156,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index 6c49804f5a8..6ecb19dbc18 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -70,7 +70,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = Infallible; type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), ()) } @@ -82,12 +82,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - Infallible, - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { @@ -129,9 +124,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { loop { match self.inbound.poll_unpin(cx) { Poll::Ready(Ok(Ok(stats))) => { diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index a9438643e1b..510ff0553de 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -229,7 +229,7 @@ impl ConnectionHandler for Handler { type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol, ()> { + fn listen_protocol(&self) -> SubstreamProtocol> { SubstreamProtocol::new(ReadyUpgrade::new(PROTOCOL_NAME), ()) } @@ -340,12 +340,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 58183490a35..d714bf04fc9 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -494,7 +494,7 @@ impl ConnectionHandler for Handler { type OutboundProtocol = ReadyUpgrade; type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(HOP_PROTOCOL_NAME), ()) } @@ -598,9 +598,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { // Return queued events. if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); @@ -876,12 +874,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 47a1546ec29..d2e4db56b4c 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -241,7 +241,7 @@ impl ConnectionHandler for Handler { type OutboundProtocol = ReadyUpgrade; type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(ReadyUpgrade::new(STOP_PROTOCOL_NAME), ()) } @@ -267,9 +267,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { loop { // Reservations match self.inflight_reserve_requests.poll_unpin(cx) { @@ -426,12 +424,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index 45d79a8b189..d70ddc5c0ae 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -127,10 +127,7 @@ where FullyNegotiatedInbound { protocol: (mut stream, protocol), info: (), - }: FullyNegotiatedInbound< - ::InboundProtocol, - (), - >, + }: FullyNegotiatedInbound<::InboundProtocol>, ) { let mut codec = self.codec.clone(); let request_id = self.next_inbound_request_id(); @@ -178,10 +175,7 @@ where FullyNegotiatedOutbound { protocol: (mut stream, protocol), info: (), - }: FullyNegotiatedOutbound< - ::OutboundProtocol, - (), - >, + }: FullyNegotiatedOutbound<::OutboundProtocol>, ) { let message = self .requested_outbound @@ -383,7 +377,7 @@ where type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new( Protocol { protocols: self.inbound_protocols.clone(), @@ -473,12 +467,7 @@ where fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => { diff --git a/protocols/stream/src/handler.rs b/protocols/stream/src/handler.rs index 2dc05e731de..5fc903f5980 100644 --- a/protocols/stream/src/handler.rs +++ b/protocols/stream/src/handler.rs @@ -52,9 +52,7 @@ impl ConnectionHandler for Handler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol( - &self, - ) -> swarm::SubstreamProtocol { + fn listen_protocol(&self) -> swarm::SubstreamProtocol { swarm::SubstreamProtocol::new( Upgrade { supported_protocols: Shared::lock(&self.shared).supported_inbound_protocols(), @@ -66,13 +64,7 @@ impl ConnectionHandler for Handler { fn poll( &mut self, cx: &mut Context<'_>, - ) -> Poll< - swarm::ConnectionHandlerEvent< - Self::OutboundProtocol, - (), - Self::ToBehaviour, - >, - > { + ) -> Poll> { if self.pending_upgrade.is_some() { return Poll::Pending; } @@ -104,12 +96,7 @@ impl ConnectionHandler for Handler { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/swarm/benches/connection_handler.rs b/swarm/benches/connection_handler.rs index 86edc963489..3ae75288208 100644 --- a/swarm/benches/connection_handler.rs +++ b/swarm/benches/connection_handler.rs @@ -281,9 +281,7 @@ impl ConnectionHandler for SpinningHandler { type OutboundOpenInfo = (); - fn listen_protocol( - &self, - ) -> libp2p_swarm::SubstreamProtocol { + fn listen_protocol(&self) -> libp2p_swarm::SubstreamProtocol { libp2p_swarm::SubstreamProtocol::new(Upgrade(self.protocols), ()) } @@ -291,11 +289,7 @@ impl ConnectionHandler for SpinningHandler { &mut self, cx: &mut std::task::Context<'_>, ) -> std::task::Poll< - libp2p_swarm::ConnectionHandlerEvent< - Self::OutboundProtocol, - (), - Self::ToBehaviour, - >, + libp2p_swarm::ConnectionHandlerEvent, > { if self.iter_count == usize::MAX { return std::task::Poll::Pending; @@ -322,8 +316,6 @@ impl ConnectionHandler for SpinningHandler { _event: libp2p_swarm::handler::ConnectionEvent< Self::InboundProtocol, Self::OutboundProtocol, - (), - (), >, ) { } diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 60f279266f8..a6cb50dab1e 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -1200,20 +1200,13 @@ mod tests { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol( - &self, - ) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()).with_timeout(self.upgrade_timeout) } fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - () - >, + event: ConnectionEvent, ) { match event { // TODO: remove when Rust 1.82 is MSRV @@ -1253,13 +1246,7 @@ mod tests { fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent< - Self::OutboundProtocol, - (), - Self::ToBehaviour, - >, - > { + ) -> Poll> { if self.outbound_requested { self.outbound_requested = false; return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { @@ -1280,9 +1267,7 @@ mod tests { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol( - &self, - ) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new( ManyProtocolsUpgrade { protocols: Vec::from_iter(self.active_protocols.clone()), @@ -1293,12 +1278,7 @@ mod tests { fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::LocalProtocolsChange(ProtocolsChange::Added(added)) => { @@ -1330,13 +1310,7 @@ mod tests { fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent< - Self::OutboundProtocol, - (), - Self::ToBehaviour, - >, - > { + ) -> Poll> { if let Some(event) = self.events.pop() { return Poll::Ready(event); } diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 526008d696d..f8137bdbeee 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -73,7 +73,7 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -86,20 +86,13 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { Poll::Pending } fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { // TODO: remove when Rust 1.82 is MSRV diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 9a3ea2493c2..3c10495c5cf 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -227,7 +227,7 @@ pub trait ConnectionHandler: Send + 'static { /// Enumeration with the list of the possible stream events /// to pass to [`on_connection_event`](ConnectionHandler::on_connection_event). #[non_exhaustive] -pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> { +pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI = (), OOI = ()> { /// Informs the handler about the output of a successful upgrade on a new inbound substream. FullyNegotiatedInbound(FullyNegotiatedInbound), /// Informs the handler about the output of a successful upgrade on a new outbound stream. @@ -321,7 +321,7 @@ impl /// [`ConnectionHandler`] implementation to stop a malicious remote node to open and keep alive /// an excessive amount of inbound substreams. #[derive(Debug)] -pub struct FullyNegotiatedInbound { +pub struct FullyNegotiatedInbound { pub protocol: IP::Output, pub info: IOI, } @@ -332,7 +332,7 @@ pub struct FullyNegotiatedInbound { /// The `protocol` field is the information that was previously passed to /// [`ConnectionHandlerEvent::OutboundSubstreamRequest`]. #[derive(Debug)] -pub struct FullyNegotiatedOutbound { +pub struct FullyNegotiatedOutbound { pub protocol: OP::Output, pub info: OOI, } @@ -527,7 +527,7 @@ pub struct ListenUpgradeError { /// The inbound substream protocol(s) are defined by [`ConnectionHandler::listen_protocol`] /// and the outbound substream protocol(s) by [`ConnectionHandlerEvent::OutboundSubstreamRequest`]. #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct SubstreamProtocol { +pub struct SubstreamProtocol { upgrade: TUpgrade, info: TInfo, timeout: Duration, diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index 038db28bb07..c623008dd90 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -129,7 +129,7 @@ where type OutboundOpenInfo = (); type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { self.listen_protocol.clone() } @@ -140,9 +140,7 @@ where fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { if !self.events_out.is_empty() { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( self.events_out.remove(0), @@ -169,12 +167,7 @@ where fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + event: ConnectionEvent, ) { match event { ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { diff --git a/swarm/src/handler/pending.rs b/swarm/src/handler/pending.rs index a1c832b7870..8223c544593 100644 --- a/swarm/src/handler/pending.rs +++ b/swarm/src/handler/pending.rs @@ -51,7 +51,7 @@ impl ConnectionHandler for PendingConnectionHandler { type OutboundOpenInfo = Infallible; type InboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(PendingUpgrade::new(self.protocol_name.clone()), ()) } @@ -64,20 +64,13 @@ impl ConnectionHandler for PendingConnectionHandler { fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { Poll::Pending } fn on_connection_event( &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - Infallible, - >, + event: ConnectionEvent, ) { match event { // TODO: remove when Rust 1.82 is MSRV diff --git a/swarm/tests/connection_close.rs b/swarm/tests/connection_close.rs index fe1720f4fc2..0d95626b2f0 100644 --- a/swarm/tests/connection_close.rs +++ b/swarm/tests/connection_close.rs @@ -103,7 +103,7 @@ impl ConnectionHandler for HandlerWithState { type InboundOpenInfo = (); type OutboundOpenInfo = (); - fn listen_protocol(&self) -> SubstreamProtocol { + fn listen_protocol(&self) -> SubstreamProtocol { SubstreamProtocol::new(DeniedUpgrade, ()) } @@ -114,9 +114,7 @@ impl ConnectionHandler for HandlerWithState { fn poll( &mut self, _: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent, - > { + ) -> Poll> { Poll::Pending } @@ -137,12 +135,7 @@ impl ConnectionHandler for HandlerWithState { fn on_connection_event( &mut self, - _: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - (), - (), - >, + _: ConnectionEvent, ) { } } From b34ed51fd8c89ba181fa6e357adf60d6e4e5d040 Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Fri, 27 Dec 2024 10:48:20 +0800 Subject: [PATCH 6/7] replace allow(lint) with expect(lint) expect(lint) emits lint message when the expected lint is not triggered --- swarm/src/behaviour/toggle.rs | 6 +++--- swarm/src/connection.rs | 10 +++++----- swarm/src/connection/pool.rs | 2 +- swarm/src/handler.rs | 2 +- swarm/src/handler/either.rs | 2 +- swarm/src/handler/map_in.rs | 2 +- swarm/src/handler/map_out.rs | 2 +- swarm/src/handler/multi.rs | 4 ++-- swarm/src/handler/select.rs | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index ff60e0539e3..2bb76880cd3 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -200,7 +200,7 @@ impl ToggleConnectionHandler where TInner: ConnectionHandler, { - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_fully_negotiated_inbound( &mut self, FullyNegotiatedInbound { @@ -232,7 +232,7 @@ where panic!("Unexpected Either::Right in enabled `on_fully_negotiated_inbound`.") } } - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { info, error: err }: ListenUpgradeError< @@ -268,7 +268,7 @@ where } } -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for ToggleConnectionHandler where TInner: ConnectionHandler, diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index a6cb50dab1e..bf688f41f0d 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -123,7 +123,7 @@ where /// The underlying handler. handler: THandler, /// Futures that upgrade incoming substreams. - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. negotiating_in: FuturesUnordered< StreamUpgrade< THandler::InboundOpenInfo, @@ -132,7 +132,7 @@ where >, >, /// Futures that upgrade outgoing substreams. - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. negotiating_out: FuturesUnordered< StreamUpgrade< THandler::OutboundOpenInfo, @@ -157,7 +157,7 @@ where /// /// The upgrade timeout is already ticking here so this may fail in case the remote is not /// quick enough in providing us with a new stream. - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. requested_substreams: FuturesUnordered< SubstreamRequested, >, @@ -171,7 +171,7 @@ where stream_counter: ActiveStreamCounter, } -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl fmt::Debug for Connection where THandler: ConnectionHandler + fmt::Debug, @@ -1278,7 +1278,7 @@ mod tests { fn on_connection_event( &mut self, - event: ConnectionEvent, + event: ConnectionEvent, ) { match event { ConnectionEvent::LocalProtocolsChange(ProtocolsChange::Added(added)) => { diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index ac96d2f91c9..f21a7307105 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -553,7 +553,7 @@ where /// Polls the connection pool for events. #[tracing::instrument(level = "debug", name = "Pool::poll", skip(self, cx))] - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll> where THandler: ConnectionHandler + 'static, diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index 3c10495c5cf..d9293fa41de 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -98,7 +98,7 @@ use crate::{connection::AsStrHashEq, StreamProtocol}; /// Implementors of this trait should keep in mind that the connection can be closed at any time. /// When a connection is closed gracefully, the substreams used by the handler may still /// continue reading data until the remote closes its side of the connection. -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. pub trait ConnectionHandler: Send + 'static { /// A type representing the message(s) a /// [`NetworkBehaviour`](crate::behaviour::NetworkBehaviour) can send to a [`ConnectionHandler`] diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index 4be00cf8f62..a349726f454 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -77,7 +77,7 @@ where /// Implementation of a [`ConnectionHandler`] that represents either of two [`ConnectionHandler`] /// implementations. -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for Either where L: ConnectionHandler, diff --git a/swarm/src/handler/map_in.rs b/swarm/src/handler/map_in.rs index 8a1981321fb..7a5166cab75 100644 --- a/swarm/src/handler/map_in.rs +++ b/swarm/src/handler/map_in.rs @@ -47,7 +47,7 @@ impl MapInEvent ConnectionHandler for MapInEvent where diff --git a/swarm/src/handler/map_out.rs b/swarm/src/handler/map_out.rs index b65316cd2d6..9bb0e2bc554 100644 --- a/swarm/src/handler/map_out.rs +++ b/swarm/src/handler/map_out.rs @@ -43,7 +43,7 @@ impl MapOutEvent { } } -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for MapOutEvent where TConnectionHandler: ConnectionHandler, diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 099abb0880e..4f4d64f65fe 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -86,7 +86,7 @@ where Ok(m) } - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { @@ -108,7 +108,7 @@ where } } -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for MultiHandler where K: Clone + Debug + Hash + Eq + Send + 'static, diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index 06c0ee63847..f4c926f1a0e 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -152,7 +152,7 @@ where TProto1: ConnectionHandler, TProto2: ConnectionHandler, { - #[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. + #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_listen_upgrade_error( &mut self, ListenUpgradeError { @@ -182,7 +182,7 @@ where } } -#[allow(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. +#[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. impl ConnectionHandler for ConnectionHandlerSelect where TProto1: ConnectionHandler, From 7121f24e33e31e272b4e55f75567d94bd69ecf61 Mon Sep 17 00:00:00 2001 From: drHuangMHT Date: Thu, 9 Jan 2025 15:54:59 +0800 Subject: [PATCH 7/7] formatting --- swarm/src/behaviour/toggle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 2bb76880cd3..a706187a40c 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -199,7 +199,7 @@ pub struct ToggleConnectionHandler { impl ToggleConnectionHandler where TInner: ConnectionHandler, -{ +{ #[expect(deprecated)] // TODO: Remove when {In, Out}boundOpenInfo is fully removed. fn on_fully_negotiated_inbound( &mut self,