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:
@ -38,7 +38,7 @@ use libp2p_swarm::{
|
||||
ExpiredListenAddr, FromSwarm,
|
||||
},
|
||||
ConnectionId, ExternalAddresses, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction,
|
||||
PollParameters, THandlerOutEvent,
|
||||
PollParameters, THandlerInEvent, THandlerOutEvent,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
@ -208,10 +208,7 @@ pub struct Behaviour {
|
||||
last_probe: Option<Instant>,
|
||||
|
||||
pending_actions: VecDeque<
|
||||
NetworkBehaviourAction<
|
||||
<Self as NetworkBehaviour>::OutEvent,
|
||||
<Self as NetworkBehaviour>::ConnectionHandler,
|
||||
>,
|
||||
NetworkBehaviourAction<<Self as NetworkBehaviour>::OutEvent, THandlerInEvent<Self>>,
|
||||
>,
|
||||
|
||||
probe_id: ProbeId,
|
||||
@ -389,14 +386,14 @@ impl Behaviour {
|
||||
&mut self,
|
||||
DialFailure {
|
||||
peer_id,
|
||||
handler,
|
||||
connection_id,
|
||||
error,
|
||||
}: DialFailure<<Self as NetworkBehaviour>::ConnectionHandler>,
|
||||
}: DialFailure,
|
||||
) {
|
||||
self.inner
|
||||
.on_swarm_event(FromSwarm::DialFailure(DialFailure {
|
||||
peer_id,
|
||||
handler,
|
||||
connection_id,
|
||||
error,
|
||||
}));
|
||||
if let Some(event) = self.as_server().on_outbound_dial_error(peer_id, error) {
|
||||
@ -560,10 +557,8 @@ impl NetworkBehaviour for Behaviour {
|
||||
}
|
||||
}
|
||||
|
||||
type Action = NetworkBehaviourAction<
|
||||
<Behaviour as NetworkBehaviour>::OutEvent,
|
||||
<Behaviour as NetworkBehaviour>::ConnectionHandler,
|
||||
>;
|
||||
type Action =
|
||||
NetworkBehaviourAction<<Behaviour as NetworkBehaviour>::OutEvent, THandlerInEvent<Behaviour>>;
|
||||
|
||||
// Trait implemented for `AsClient` and `AsServer` to handle events from the inner [`request_response::Behaviour`] Protocol.
|
||||
trait HandleInnerEvent {
|
||||
|
Reference in New Issue
Block a user