mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 16:51:34 +00:00
refactor(swarm)!: remove handler
from NetworkBehaviourAction::Dial
(#3328)
We create the `ConnectionId` for the new connection as part of `DialOpts`. This allows `NetworkBehaviour`s to accurately track state regarding their own dial attempts. This patch is the main enabler of https://github.com/libp2p/rust-libp2p/pull/3254. Removing the `handler` field will allow us to deprecate the `NetworkBehaviour::new_handler` function in favor of four new ones that give more control over the connection lifecycle.
This commit is contained in:
@ -26,7 +26,7 @@ use libp2p_swarm::{
|
||||
dial_opts::DialOpts,
|
||||
AddressScore, ConnectionHandlerUpgrErr, ConnectionId, DialError, ExternalAddresses,
|
||||
ListenAddresses, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
THandlerOutEvent,
|
||||
THandlerInEvent, THandlerOutEvent,
|
||||
};
|
||||
use lru::LruCache;
|
||||
use std::num::NonZeroUsize;
|
||||
@ -53,7 +53,7 @@ pub struct Behaviour {
|
||||
/// with current information about the local peer.
|
||||
requests: Vec<Request>,
|
||||
/// Pending events to be emitted when polled.
|
||||
events: VecDeque<NetworkBehaviourAction<Event, Proto>>,
|
||||
events: VecDeque<NetworkBehaviourAction<Event, InEvent>>,
|
||||
/// The addresses of all peers that we have discovered.
|
||||
discovered_peers: PeerCache,
|
||||
|
||||
@ -198,10 +198,8 @@ impl Behaviour {
|
||||
if !self.requests.contains(&request) {
|
||||
self.requests.push(request);
|
||||
|
||||
let handler = self.new_handler();
|
||||
self.events.push_back(NetworkBehaviourAction::Dial {
|
||||
opts: DialOpts::peer_id(p).build(),
|
||||
handler,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -309,7 +307,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
_cx: &mut Context<'_>,
|
||||
params: &mut impl PollParameters,
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
if let Some(event) = self.events.pop_front() {
|
||||
return Poll::Ready(event);
|
||||
}
|
||||
|
Reference in New Issue
Block a user