diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index 1950c47f28b..8f8892b7810 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -64,8 +64,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, CloseConnection, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, CloseConnection, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{HashSet, VecDeque}; use std::fmt; @@ -261,7 +261,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { if let Some(peer) = self.close_connections.pop_front() { return Poll::Ready(ToSwarm::CloseConnection { diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 472d12f93b6..f58e880cf91 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -22,8 +22,8 @@ use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{ConnectionEstablished, DialFailure, ListenFailure}, - dummy, ConnectionClosed, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionClosed, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{HashMap, HashSet}; use std::fmt; @@ -364,11 +364,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } @@ -600,8 +596,7 @@ mod tests { fn poll( &mut self, - _cx: &mut Context<'_>, - _params: &mut impl PollParameters, + _: &mut Context<'_>, ) -> Poll>> { Poll::Pending } diff --git a/misc/memory-connection-limits/src/lib.rs b/misc/memory-connection-limits/src/lib.rs index 36f0d1648d7..b1e68d80083 100644 --- a/misc/memory-connection-limits/src/lib.rs +++ b/misc/memory-connection-limits/src/lib.rs @@ -21,8 +21,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use void::Void; @@ -192,11 +192,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } diff --git a/misc/memory-connection-limits/tests/util.rs b/misc/memory-connection-limits/tests/util.rs index a2fd7c20fed..8d9d73af187 100644 --- a/misc/memory-connection-limits/tests/util.rs +++ b/misc/memory-connection-limits/tests/util.rs @@ -23,8 +23,8 @@ use std::task::{Context, Poll}; use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use void::Void; @@ -118,11 +118,7 @@ impl NetworkBehaviour void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 439543f8318..e0e311e3666 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -40,7 +40,7 @@ use libp2p_swarm::{ ExternalAddrExpired, FromSwarm, }, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, NewExternalAddrCandidate, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -435,13 +435,16 @@ impl NetworkBehaviour for Behaviour { as NetworkBehaviour>::ConnectionHandler; type ToSwarm = Event; - fn poll(&mut self, cx: &mut Context<'_>, params: &mut impl PollParameters) -> Poll { + fn poll( + &mut self, + cx: &mut Context<'_>, + ) -> Poll>> { loop { if let Some(event) = self.pending_actions.pop_front() { return Poll::Ready(event); } - match self.inner.poll(cx, params) { + match self.inner.poll(cx) { Poll::Ready(ToSwarm::GenerateEvent(event)) => { let actions = match event { request_response::Event::Message { @@ -449,14 +452,14 @@ impl NetworkBehaviour for Behaviour { .. } | request_response::Event::OutboundFailure { .. } => { - self.as_client().handle_event(params, event) + self.as_client().handle_event(event) } request_response::Event::Message { message: request_response::Message::Request { .. }, .. } | request_response::Event::InboundFailure { .. } => { - self.as_server().handle_event(params, event) + self.as_server().handle_event(event) } request_response::Event::ResponseSent { .. } => VecDeque::new(), }; @@ -609,7 +612,6 @@ type Action = ToSwarm<::ToSwarm, THandlerInEvent< trait HandleInnerEvent { fn handle_event( &mut self, - params: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque; } diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index e57523afaf8..45608ea98fd 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -30,7 +30,7 @@ use instant::Instant; use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, OutboundFailure, RequestId}; -use libp2p_swarm::{ConnectionId, ListenAddresses, PollParameters, ToSwarm}; +use libp2p_swarm::{ConnectionId, ListenAddresses, ToSwarm}; use rand::{seq::SliceRandom, thread_rng}; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -101,7 +101,6 @@ pub(crate) struct AsClient<'a> { impl<'a> HandleInnerEvent for AsClient<'a> { fn handle_event( &mut self, - _: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque { match event { diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 09c70a27e93..b4c67a6a350 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -30,7 +30,7 @@ use libp2p_request_response::{ }; use libp2p_swarm::{ dial_opts::{DialOpts, PeerCondition}, - ConnectionId, DialError, PollParameters, ToSwarm, + ConnectionId, DialError, ToSwarm, }; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -95,7 +95,6 @@ pub(crate) struct AsServer<'a> { impl<'a> HandleInnerEvent for AsServer<'a> { fn handle_event( &mut self, - _params: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque { match event { diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index b420bff81cc..84ed18276d2 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -32,8 +32,8 @@ use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionHandler, ConnectionId, THandler, THandlerOutEvent, }; use libp2p_swarm::{ - ExternalAddresses, NetworkBehaviour, NotifyHandler, PollParameters, StreamUpgradeError, - THandlerInEvent, ToSwarm, + ExternalAddresses, NetworkBehaviour, NotifyHandler, StreamUpgradeError, THandlerInEvent, + ToSwarm, }; use std::collections::{HashMap, HashSet, VecDeque}; use std::task::{Context, Poll}; @@ -351,11 +351,7 @@ impl NetworkBehaviour for Behaviour { }; } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 29fe8ba250f..a8598f397aa 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -31,7 +31,7 @@ use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; use libp2p_swarm::{ dial_opts::DialOpts, ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, - OneShotHandler, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + OneShotHandler, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use log::warn; use smallvec::SmallVec; @@ -466,11 +466,7 @@ impl NetworkBehaviour for Floodsub { } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index a82c13d9504..5c5260b4b13 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -42,8 +42,8 @@ use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, FromSwarm}, dial_opts::DialOpts, - ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use crate::backoff::BackoffStorage; @@ -3416,7 +3416,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index c97456826fe..8a3e545a229 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -26,7 +26,7 @@ use libp2p_identity::PublicKey; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}; use libp2p_swarm::{ ConnectionDenied, DialError, ExternalAddresses, ListenAddresses, NetworkBehaviour, - NotifyHandler, PollParameters, StreamUpgradeError, THandlerInEvent, ToSwarm, + NotifyHandler, StreamUpgradeError, THandlerInEvent, ToSwarm, }; use libp2p_swarm::{ConnectionId, THandler, THandlerOutEvent}; use lru::LruCache; @@ -312,11 +312,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index c4b268901f9..4a7829d592a 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -44,8 +44,8 @@ use libp2p_swarm::behaviour::{ use libp2p_swarm::{ dial_opts::{self, DialOpts}, ConnectionDenied, ConnectionHandler, ConnectionId, DialError, ExternalAddresses, - ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ListenAddresses, NetworkBehaviour, NotifyHandler, StreamProtocol, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use log::{debug, info, warn}; use smallvec::SmallVec; @@ -2406,7 +2406,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { let now = Instant::now(); diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 9e937272e8c..bda0910c45c 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -32,8 +32,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use smallvec::SmallVec; use std::collections::hash_map::{Entry, HashMap}; @@ -285,7 +285,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { // Poll ifwatch. while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) { diff --git a/protocols/perf/src/client.rs b/protocols/perf/src/client.rs index 6ef671a429a..52388820be4 100644 --- a/protocols/perf/src/client.rs +++ b/protocols/perf/src/client.rs @@ -30,7 +30,7 @@ use libp2p_identity::PeerId; use libp2p_request_response as request_response; use libp2p_swarm::{ derive_prelude::ConnectionEstablished, ConnectionClosed, ConnectionId, FromSwarm, - NetworkBehaviour, PollParameters, THandlerInEvent, THandlerOutEvent, ToSwarm, + NetworkBehaviour, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use crate::{protocol::Response, RunDuration, RunParams}; @@ -199,9 +199,8 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { - self.request_response.poll(cx, params).map(|to_swarm| { + self.request_response.poll(cx).map(|to_swarm| { to_swarm.map_out(|m| match m { request_response::Event::Message { peer: _, diff --git a/protocols/perf/src/server.rs b/protocols/perf/src/server.rs index ea361755ec3..60fa252de1a 100644 --- a/protocols/perf/src/server.rs +++ b/protocols/perf/src/server.rs @@ -25,8 +25,7 @@ use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response as request_response; use libp2p_swarm::{ - ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandlerInEvent, THandlerOutEvent, - ToSwarm, + ConnectionId, FromSwarm, NetworkBehaviour, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use crate::protocol::Response; @@ -134,9 +133,8 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { - self.request_response.poll(cx, params).map(|to_swarm| { + self.request_response.poll(cx).map(|to_swarm| { to_swarm.map_out(|m| match m { request_response::Event::Message { peer: _, diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index d1c4a2facaf..b25adad9e4e 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -54,8 +54,8 @@ use handler::Handler; use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::time::Duration; use std::{ @@ -141,11 +141,7 @@ impl NetworkBehaviour for Behaviour { }) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(e) = self.events.pop_back() { Poll::Ready(ToSwarm::GenerateEvent(e)) } else { diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 9e49b9cea08..7de9cfced88 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -34,7 +34,7 @@ use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionId, ExternalAddresses, NetworkBehaviour, NotifyHandler, - PollParameters, StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{hash_map, HashMap, HashSet, VecDeque}; use std::num::NonZeroU32; @@ -689,11 +689,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(to_swarm) = self.queued_actions.pop_front() { return Poll::Ready(to_swarm); } diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index 84d5e682419..770f552cb79 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -40,8 +40,8 @@ use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm use libp2p_swarm::dial_opts::DialOpts; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, NetworkBehaviour, - NotifyHandler, PollParameters, Stream, StreamUpgradeError, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + NotifyHandler, Stream, StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, + ToSwarm, }; use std::collections::{hash_map, HashMap, VecDeque}; use std::io::{Error, ErrorKind, IoSlice}; @@ -287,7 +287,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - _poll_parameters: &mut impl PollParameters, ) -> Poll>> { if let Some(action) = self.queued_actions.pop_front() { return Poll::Ready(action); diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 8459dc21c7e..876ced1ee96 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -28,8 +28,8 @@ use libp2p_core::{Endpoint, Multiaddr, PeerRecord}; use libp2p_identity::{Keypair, PeerId, SigningError}; use libp2p_request_response::{ProtocolSupport, RequestId}; use libp2p_swarm::{ - ConnectionDenied, ConnectionId, ExternalAddresses, FromSwarm, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, ExternalAddresses, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::HashMap; use std::iter; @@ -241,12 +241,11 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { use libp2p_request_response as req_res; loop { - match self.inner.poll(cx, params) { + match self.inner.poll(cx) { Poll::Ready(ToSwarm::GenerateEvent(req_res::Event::Message { message: req_res::Message::Response { diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 44f2f97a6a0..2e2e4c0ee1d 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -29,8 +29,8 @@ use libp2p_identity::PeerId; use libp2p_request_response::ProtocolSupport; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ - ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, NetworkBehaviour, THandler, THandlerInEvent, THandlerOutEvent, + ToSwarm, }; use std::collections::{HashMap, HashSet}; use std::iter; @@ -158,7 +158,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { if let Poll::Ready(ExpiredRegistration(registration)) = self.registrations.poll(cx) { return Poll::Ready(ToSwarm::GenerateEvent(Event::RegistrationExpired( @@ -167,7 +166,7 @@ impl NetworkBehaviour for Behaviour { } loop { - if let Poll::Ready(to_swarm) = self.inner.poll(cx, params) { + if let Poll::Ready(to_swarm) = self.inner.poll(cx) { match to_swarm { ToSwarm::GenerateEvent(libp2p_request_response::Event::Message { peer: peer_id, diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 9520a0b686d..322d77047f2 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -84,8 +84,8 @@ use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, DialFailure, FromSwarm}, dial_opts::DialOpts, - ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NotifyHandler, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NotifyHandler, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use smallvec::SmallVec; use std::{ @@ -894,11 +894,7 @@ where } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(ev) = self.pending_events.pop_front() { return Poll::Ready(ev); } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index 45b82edc562..cd153020f63 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -39,7 +39,7 @@ use igd_next::PortMappingProtocol; use libp2p_core::{multiaddr, transport::ListenerId, Endpoint, Multiaddr}; use libp2p_swarm::{ derive_prelude::PeerId, dummy, ConnectionDenied, ConnectionId, ExpiredListenAddr, FromSwarm, - NetworkBehaviour, NewListenAddr, PollParameters, ToSwarm, + NetworkBehaviour, NewListenAddr, ToSwarm, }; /// The duration in seconds of a port mapping on the gateway. @@ -370,7 +370,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - _params: &mut impl PollParameters, ) -> Poll>> { // If there are pending addresses to be emitted we emit them. if let Some(event) = self.pending_events.pop_front() { diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index e54cd058daf..02f2df037c0 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -72,7 +72,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result syn::Result { return std::task::Poll::Ready(#network_behaviour_action::Dial { opts }); @@ -836,7 +835,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result std::task::Poll<#network_behaviour_action>> { + fn poll(&mut self, cx: &mut std::task::Context) -> std::task::Poll<#network_behaviour_action>> { use #prelude_path::futures::*; #(#poll_stmts)* std::task::Poll::Pending diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 53a6220f8d4..d54f19121df 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.44.0 - unreleased +- Remove deprecated `PollParameters` from `NetworkBehaviour::poll` function. + See [PR 4490](https://github.com/libp2p/rust-libp2p/pull/4490). - Add `PeerCondition::DisconnectedAndNotDialing` variant, combining pre-existing conditions. This is the new default. A new dialing attempt is iniated _only if_ the peer is both considered disconnected and there is currently no ongoing dialing attempt. diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 3662bf5c48d..4866b9cc29e 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -209,28 +209,8 @@ pub trait NetworkBehaviour: 'static { /// /// This API mimics the API of the `Stream` trait. The method may register the current task in /// order to wake it up at a later point in time. - fn poll( - &mut self, - cx: &mut Context<'_>, - params: &mut impl PollParameters, - ) -> Poll>>; -} - -/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to. -pub trait PollParameters { - /// Iterator returned by [`supported_protocols`](PollParameters::supported_protocols). - type SupportedProtocolsIter: ExactSizeIterator>; - - /// Returns the list of protocol the behaviour supports when a remote negotiates a protocol on - /// an inbound substream. - /// - /// The iterator's elements are the ASCII names as reported on the wire. - /// - /// Note that the list is computed once at initialization and never refreshed. - #[deprecated( - note = "Use `libp2p_swarm::SupportedProtocols` in your `ConnectionHandler` instead." - )] - fn supported_protocols(&self) -> Self::SupportedProtocolsIter; + fn poll(&mut self, cx: &mut Context<'_>) + -> Poll>>; } /// A command issued from a [`NetworkBehaviour`] for the [`Swarm`]. diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index c6e0870d11c..0e92c54aaf6 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::behaviour::{self, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{self, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::{ConnectionDenied, THandler, THandlerInEvent, THandlerOutEvent}; use either::Either; @@ -155,13 +155,12 @@ where fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { let event = match self { - Either::Left(behaviour) => futures::ready!(behaviour.poll(cx, params)) + Either::Left(behaviour) => futures::ready!(behaviour.poll(cx)) .map_out(Either::Left) .map_in(Either::Left), - Either::Right(behaviour) => futures::ready!(behaviour.poll(cx, params)) + Either::Right(behaviour) => futures::ready!(behaviour.poll(cx)) .map_out(Either::Right) .map_in(Either::Right), }; diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 92bd8963502..4f4f9585f0e 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -27,8 +27,7 @@ use crate::handler::{ }; use crate::upgrade::SendWrapper; use crate::{ - ConnectionDenied, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + ConnectionDenied, NetworkBehaviour, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use either::Either; use futures::future; @@ -181,10 +180,9 @@ where fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { if let Some(inner) = self.inner.as_mut() { - inner.poll(cx, params) + inner.poll(cx) } else { Poll::Pending } diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 6810abec591..067c9788e4d 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -1,4 +1,4 @@ -use crate::behaviour::{FromSwarm, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{FromSwarm, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -50,11 +50,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index 05cbcdf7b8c..deae4bf9bb3 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -1,4 +1,4 @@ -use crate::behaviour::{FromSwarm, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{FromSwarm, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::handler::{ ConnectionEvent, ConnectionHandlerEvent, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -53,11 +53,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index e0bcfccfa56..08d981eaf9a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -96,7 +96,6 @@ pub mod derive_prelude { pub use crate::ConnectionHandlerSelect; pub use crate::DialError; pub use crate::NetworkBehaviour; - pub use crate::PollParameters; pub use crate::THandler; pub use crate::THandlerInEvent; pub use crate::THandlerOutEvent; @@ -114,7 +113,7 @@ pub use behaviour::{ AddressChange, CloseConnection, ConnectionClosed, DialFailure, ExpiredListenAddr, ExternalAddrExpired, ExternalAddresses, FromSwarm, ListenAddresses, ListenFailure, ListenerClosed, ListenerError, NetworkBehaviour, NewExternalAddrCandidate, NewListenAddr, - NotifyHandler, PollParameters, ToSwarm, + NotifyHandler, ToSwarm, }; pub use connection::pool::ConnectionCounters; pub use connection::{ConnectionError, ConnectionId, SupportedProtocols}; @@ -1192,26 +1191,16 @@ where } }, // No pending event. Allow the [`NetworkBehaviour`] to make progress. - None => { - let behaviour_poll = { - let mut parameters = SwarmPollParameters { - supported_protocols: &this.supported_protocols, - }; - this.behaviour.poll(cx, &mut parameters) - }; - - match behaviour_poll { - Poll::Pending => {} - Poll::Ready(behaviour_event) => { - if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) - { - return Poll::Ready(swarm_event); - } - - continue; + None => match this.behaviour.poll(cx) { + Poll::Pending => {} + Poll::Ready(behaviour_event) => { + if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) { + return Poll::Ready(swarm_event); } + + continue; } - } + }, } // Poll the known peers. @@ -1357,20 +1346,6 @@ where } } -/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to. -// TODO: #[derive(Debug)] -pub struct SwarmPollParameters<'a> { - supported_protocols: &'a [Vec], -} - -impl<'a> PollParameters for SwarmPollParameters<'a> { - type SupportedProtocolsIter = std::iter::Cloned>>; - - fn supported_protocols(&self) -> Self::SupportedProtocolsIter { - self.supported_protocols.iter().cloned() - } -} - pub struct Config { pool_config: PoolConfig, } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 6f39d56da91..a4520545998 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -23,8 +23,8 @@ use crate::behaviour::{ FromSwarm, ListenerClosed, ListenerError, NewExternalAddrCandidate, NewListenAddr, NewListener, }; use crate::{ - ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use libp2p_core::{multiaddr::Multiaddr, transport::ListenerId, ConnectedPoint, Endpoint}; use libp2p_identity::PeerId; @@ -110,11 +110,7 @@ where Ok(self.addresses.get(&p).map_or(Vec::new(), |v| v.clone())) } - fn poll( - &mut self, - _: &mut Context, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { self.next_action.take().map_or(Poll::Pending, Poll::Ready) } @@ -559,10 +555,9 @@ where fn poll( &mut self, - cx: &mut Context, - args: &mut impl PollParameters, + cx: &mut Context<'_>, ) -> Poll>> { self.poll += 1; - self.inner.poll(cx, args) + self.inner.poll(cx) } } diff --git a/swarm/tests/listener.rs b/swarm/tests/listener.rs index 71d92cb0e1f..6faee330ab1 100644 --- a/swarm/tests/listener.rs +++ b/swarm/tests/listener.rs @@ -7,8 +7,8 @@ use libp2p_core::{multiaddr::Protocol, transport::ListenerId, Endpoint, Multiadd use libp2p_identity::PeerId; use libp2p_swarm::{ derive_prelude::NewListener, dummy, ConnectionDenied, ConnectionId, FromSwarm, ListenOpts, - ListenerClosed, ListenerError, NetworkBehaviour, NewListenAddr, PollParameters, Swarm, - SwarmEvent, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ListenerClosed, ListenerError, NetworkBehaviour, NewListenAddr, Swarm, SwarmEvent, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use libp2p_swarm_test::SwarmExt; @@ -129,11 +129,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index d0680591621..5782d0a92b3 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -457,7 +457,7 @@ fn multiple_behaviour_attributes() { #[test] fn custom_out_event_no_type_parameters() { use libp2p_identity::PeerId; - use libp2p_swarm::{ConnectionId, PollParameters, ToSwarm}; + use libp2p_swarm::{ConnectionId, ToSwarm}; use std::task::Context; use std::task::Poll; @@ -500,8 +500,7 @@ fn custom_out_event_no_type_parameters() { fn poll( &mut self, - _ctx: &mut Context, - _: &mut impl PollParameters, + _: &mut Context<'_>, ) -> Poll>> { Poll::Pending }