mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 01:01: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:
@ -20,7 +20,7 @@
|
||||
|
||||
use crate::codec::{Cookie, ErrorCode, Namespace, NewRegistration, Registration, Ttl};
|
||||
use crate::handler::inbound;
|
||||
use crate::substream_handler::{InboundSubstreamId, SubstreamConnectionHandler};
|
||||
use crate::substream_handler::{InEvent, InboundSubstreamId, SubstreamConnectionHandler};
|
||||
use crate::{handler, MAX_TTL, MIN_TTL};
|
||||
use bimap::BiMap;
|
||||
use futures::future::BoxFuture;
|
||||
@ -31,7 +31,7 @@ use libp2p_core::PeerId;
|
||||
use libp2p_swarm::behaviour::FromSwarm;
|
||||
use libp2p_swarm::{
|
||||
CloseConnection, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||
PollParameters, THandlerOutEvent,
|
||||
PollParameters, THandlerInEvent, THandlerOutEvent,
|
||||
};
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
@ -40,9 +40,7 @@ use std::time::Duration;
|
||||
use void::Void;
|
||||
|
||||
pub struct Behaviour {
|
||||
events: VecDeque<
|
||||
NetworkBehaviourAction<Event, SubstreamConnectionHandler<inbound::Stream, Void, ()>>,
|
||||
>,
|
||||
events: VecDeque<NetworkBehaviourAction<Event, InEvent<(), inbound::InEvent, Void>>>,
|
||||
registrations: Registrations,
|
||||
}
|
||||
|
||||
@ -148,7 +146,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
cx: &mut Context<'_>,
|
||||
_: &mut impl PollParameters,
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, THandlerInEvent<Self>>> {
|
||||
if let Poll::Ready(ExpiredRegistration(registration)) = self.registrations.poll(cx) {
|
||||
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(
|
||||
Event::RegistrationExpired(registration),
|
||||
@ -186,7 +184,7 @@ fn handle_inbound_event(
|
||||
connection: ConnectionId,
|
||||
id: InboundSubstreamId,
|
||||
registrations: &mut Registrations,
|
||||
) -> Vec<NetworkBehaviourAction<Event, SubstreamConnectionHandler<inbound::Stream, Void, ()>>> {
|
||||
) -> Vec<NetworkBehaviourAction<Event, THandlerInEvent<Behaviour>>> {
|
||||
match event {
|
||||
// bad registration
|
||||
inbound::OutEvent::RegistrationRequested(registration)
|
||||
|
Reference in New Issue
Block a user