Skip to content

Commit

Permalink
feat(swarm)!: remove PollParameters
Browse files Browse the repository at this point in the history
Resolves: #3124.

Pull-Request: #4490.
  • Loading branch information
thomaseizinger authored Oct 24, 2023
1 parent 26e2d50 commit 1291ea9
Show file tree
Hide file tree
Showing 33 changed files with 90 additions and 203 deletions.
5 changes: 2 additions & 3 deletions misc/allow-block-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -261,7 +261,6 @@ where
fn poll(
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(peer) = self.close_connections.pop_front() {
return Poll::Ready(ToSwarm::CloseConnection {
Expand Down
13 changes: 4 additions & 9 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -364,11 +364,7 @@ impl NetworkBehaviour for Behaviour {
void::unreachable(event)
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
Poll::Pending
}
}
Expand Down Expand Up @@ -600,8 +596,7 @@ mod tests {

fn poll(
&mut self,
_cx: &mut Context<'_>,
_params: &mut impl PollParameters,
_: &mut Context<'_>,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
Poll::Pending
}
Expand Down
10 changes: 3 additions & 7 deletions misc/memory-connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -192,11 +192,7 @@ impl NetworkBehaviour for Behaviour {
void::unreachable(event)
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
Poll::Pending
}
}
Expand Down
10 changes: 3 additions & 7 deletions misc/memory-connection-limits/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -118,11 +118,7 @@ impl<const MEM_PENDING: usize, const MEM_ESTABLISHED: usize> NetworkBehaviour
void::unreachable(event)
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
Poll::Pending
}
}
14 changes: 8 additions & 6 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -435,28 +435,31 @@ impl NetworkBehaviour for Behaviour {
<request_response::Behaviour<AutoNatCodec> as NetworkBehaviour>::ConnectionHandler;
type ToSwarm = Event;

fn poll(&mut self, cx: &mut Context<'_>, params: &mut impl PollParameters) -> Poll<Action> {
fn poll(
&mut self,
cx: &mut Context<'_>,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
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 {
message: request_response::Message::Response { .. },
..
}
| 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(),
};
Expand Down Expand Up @@ -609,7 +612,6 @@ type Action = ToSwarm<<Behaviour as NetworkBehaviour>::ToSwarm, THandlerInEvent<
trait HandleInnerEvent {
fn handle_event(
&mut self,
params: &mut impl PollParameters,
event: request_response::Event<DialRequest, DialResponse>,
) -> VecDeque<Action>;
}
Expand Down
3 changes: 1 addition & 2 deletions protocols/autonat/src/behaviour/as_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<DialRequest, DialResponse>,
) -> VecDeque<Action> {
match event {
Expand Down
3 changes: 1 addition & 2 deletions protocols/autonat/src/behaviour/as_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<DialRequest, DialResponse>,
) -> VecDeque<Action> {
match event {
Expand Down
10 changes: 3 additions & 7 deletions protocols/dcutr/src/behaviour_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -351,11 +351,7 @@ impl NetworkBehaviour for Behaviour {
};
}

fn poll(
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.queued_events.pop_front() {
return Poll::Ready(event);
}
Expand Down
8 changes: 2 additions & 6 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -466,11 +466,7 @@ impl NetworkBehaviour for Floodsub {
}
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
}
Expand Down
5 changes: 2 additions & 3 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3416,7 +3416,6 @@ where
fn poll(
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
Expand Down
8 changes: 2 additions & 6 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -312,11 +312,7 @@ impl NetworkBehaviour for Behaviour {
}
}

fn poll(
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(event) = self.events.pop_front() {
return Poll::Ready(event);
}
Expand Down
5 changes: 2 additions & 3 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2406,7 +2406,6 @@ where
fn poll(
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
let now = Instant::now();

Expand Down
5 changes: 2 additions & 3 deletions protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -285,7 +285,6 @@ where
fn poll(
&mut self,
cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
// Poll ifwatch.
while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) {
Expand Down
5 changes: 2 additions & 3 deletions protocols/perf/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -199,9 +199,8 @@ impl NetworkBehaviour for Behaviour {
fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
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: _,
Expand Down
6 changes: 2 additions & 4 deletions protocols/perf/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,9 +133,8 @@ impl NetworkBehaviour for Behaviour {
fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
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: _,
Expand Down
10 changes: 3 additions & 7 deletions protocols/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -141,11 +141,7 @@ impl NetworkBehaviour for Behaviour {
})
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(e) = self.events.pop_back() {
Poll::Ready(ToSwarm::GenerateEvent(e))
} else {
Expand Down
8 changes: 2 additions & 6 deletions protocols/relay/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -689,11 +689,7 @@ impl NetworkBehaviour for Behaviour {
}
}

fn poll(
&mut self,
_cx: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
if let Some(to_swarm) = self.queued_actions.pop_front() {
return Poll::Ready(to_swarm);
}
Expand Down
Loading

0 comments on commit 1291ea9

Please sign in to comment.