mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 22:01:34 +00:00
refactor: expose and use THandlerOutEvent
type alias (#3368)
Previously, we used the full reference to the `OutEvent` of the `ConnectionHandler` in all implementations of `NetworkBehaviour`. Not only is this very verbose, it is also more brittle to changes. With the current implementation plan for #2824, we will be removing the `IntoConnectionHandler` abstraction. Using a type-alias to refer to the `OutEvent` makes the migration much easier.
This commit is contained in:
@ -37,8 +37,8 @@ use libp2p_swarm::{
|
||||
AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredExternalAddr,
|
||||
ExpiredListenAddr, FromSwarm,
|
||||
},
|
||||
ConnectionHandler, ConnectionId, ExternalAddresses, IntoConnectionHandler, ListenAddresses,
|
||||
NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||
ConnectionId, ExternalAddresses, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction,
|
||||
PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
@ -553,8 +553,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection_id: ConnectionId,
|
||||
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
self.inner
|
||||
.on_connection_handler_event(peer_id, connection_id, event)
|
||||
|
@ -27,11 +27,11 @@ use libp2p_core::multiaddr::Protocol;
|
||||
use libp2p_core::{Multiaddr, PeerId};
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
|
||||
use libp2p_swarm::dial_opts::{self, DialOpts};
|
||||
use libp2p_swarm::ConnectionId;
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandler, ConnectionHandlerUpgrErr, ExternalAddresses, IntoConnectionHandler,
|
||||
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
ConnectionHandlerUpgrErr, ExternalAddresses, NetworkBehaviour, NetworkBehaviourAction,
|
||||
NotifyHandler, PollParameters,
|
||||
};
|
||||
use libp2p_swarm::{ConnectionId, THandlerOutEvent};
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::task::{Context, Poll};
|
||||
use thiserror::Error;
|
||||
@ -222,8 +222,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
event_source: PeerId,
|
||||
connection: ConnectionId,
|
||||
handler_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
handler_event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match handler_event {
|
||||
Either::Left(handler::relayed::Event::InboundConnectRequest {
|
||||
|
@ -30,9 +30,8 @@ use libp2p_core::PeerId;
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm};
|
||||
use libp2p_swarm::{
|
||||
dial_opts::DialOpts, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||
OneShotHandler, PollParameters,
|
||||
OneShotHandler, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};
|
||||
use log::warn;
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::hash_map::{DefaultHasher, HashMap};
|
||||
@ -352,8 +351,7 @@ impl NetworkBehaviour for Floodsub {
|
||||
&mut self,
|
||||
propagation_source: PeerId,
|
||||
_connection_id: ConnectionId,
|
||||
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
// We ignore successful sends or timeouts.
|
||||
let event = match event {
|
||||
|
@ -41,8 +41,8 @@ use libp2p_core::{
|
||||
use libp2p_swarm::{
|
||||
behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, FromSwarm},
|
||||
dial_opts::DialOpts,
|
||||
ConnectionHandler, ConnectionId, IntoConnectionHandler, NetworkBehaviour,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use wasm_timer::Instant;
|
||||
|
||||
@ -3313,8 +3313,7 @@ where
|
||||
&mut self,
|
||||
propagation_source: PeerId,
|
||||
_connection_id: ConnectionId,
|
||||
handler_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
handler_event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match handler_event {
|
||||
HandlerEvent::PeerKind(kind) => {
|
||||
|
@ -21,12 +21,12 @@
|
||||
use crate::handler::{self, InEvent, Proto};
|
||||
use crate::protocol::{Info, Protocol, UpgradeError};
|
||||
use libp2p_core::{multiaddr, ConnectedPoint, Multiaddr, PeerId, PublicKey};
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
|
||||
use libp2p_swarm::ConnectionId;
|
||||
use libp2p_swarm::{
|
||||
dial_opts::DialOpts, AddressScore, ConnectionHandler, ConnectionHandlerUpgrErr, DialError,
|
||||
ExternalAddresses, IntoConnectionHandler, ListenAddresses, NetworkBehaviour,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm},
|
||||
dial_opts::DialOpts,
|
||||
AddressScore, ConnectionHandlerUpgrErr, ConnectionId, DialError, ExternalAddresses,
|
||||
ListenAddresses, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use lru::LruCache;
|
||||
use std::num::NonZeroUsize;
|
||||
@ -253,7 +253,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection_id: ConnectionId,
|
||||
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match event {
|
||||
handler::Event::Identified(mut info) => {
|
||||
|
@ -46,7 +46,7 @@ use libp2p_swarm::behaviour::{
|
||||
use libp2p_swarm::{
|
||||
dial_opts::{self, DialOpts},
|
||||
ConnectionId, DialError, ExternalAddresses, ListenAddresses, NetworkBehaviour,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use log::{debug, info, warn};
|
||||
use smallvec::SmallVec;
|
||||
@ -2025,7 +2025,7 @@ where
|
||||
&mut self,
|
||||
source: PeerId,
|
||||
connection: ConnectionId,
|
||||
event: KademliaHandlerEvent<QueryId>,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match event {
|
||||
KademliaHandlerEvent::ProtocolConfirmed { endpoint } => {
|
||||
|
@ -30,8 +30,8 @@ use if_watch::IfEvent;
|
||||
use libp2p_core::{Multiaddr, PeerId};
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm};
|
||||
use libp2p_swarm::{
|
||||
dummy, ConnectionHandler, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction,
|
||||
PollParameters,
|
||||
dummy, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::hash_map::{Entry, HashMap};
|
||||
@ -190,7 +190,7 @@ where
|
||||
&mut self,
|
||||
_: PeerId,
|
||||
_: libp2p_swarm::ConnectionId,
|
||||
ev: <Self::ConnectionHandler as ConnectionHandler>::OutEvent,
|
||||
ev: THandlerOutEvent<Self>,
|
||||
) {
|
||||
void::unreachable(ev)
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ pub use handler::{Config, Failure, Success};
|
||||
use libp2p_core::PeerId;
|
||||
use libp2p_swarm::{
|
||||
behaviour::FromSwarm, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
@ -123,7 +124,12 @@ impl NetworkBehaviour for Behaviour {
|
||||
Handler::new(self.config.clone())
|
||||
}
|
||||
|
||||
fn on_connection_handler_event(&mut self, peer: PeerId, _: ConnectionId, result: Result) {
|
||||
fn on_connection_handler_event(
|
||||
&mut self,
|
||||
peer: PeerId,
|
||||
_: ConnectionId,
|
||||
result: THandlerOutEvent<Self>,
|
||||
) {
|
||||
self.events.push_front(Event { peer, result })
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ use libp2p_core::PeerId;
|
||||
use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm};
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandlerUpgrErr, ConnectionId, ExternalAddresses, NetworkBehaviour,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use std::collections::{hash_map, HashMap, HashSet, VecDeque};
|
||||
use std::num::NonZeroU32;
|
||||
@ -287,7 +287,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
event_source: PeerId,
|
||||
connection: ConnectionId,
|
||||
event: Either<handler::Event, void::Void>,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
let event = match event {
|
||||
Either::Left(e) => e,
|
||||
|
@ -37,7 +37,7 @@ use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm
|
||||
use libp2p_swarm::dial_opts::DialOpts;
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandlerUpgrErr, ConnectionId, NegotiatedSubstream, NetworkBehaviour,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
NetworkBehaviourAction, NotifyHandler, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use std::collections::{hash_map, HashMap, VecDeque};
|
||||
use std::io::{Error, ErrorKind, IoSlice};
|
||||
@ -194,7 +194,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
event_source: PeerId,
|
||||
_connection: ConnectionId,
|
||||
handler_event: Either<handler::Event, void::Void>,
|
||||
handler_event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
let handler_event = match handler_event {
|
||||
Either::Left(e) => e,
|
||||
|
@ -34,7 +34,7 @@ use libp2p_core::{Multiaddr, PeerId, PeerRecord};
|
||||
use libp2p_swarm::behaviour::FromSwarm;
|
||||
use libp2p_swarm::{
|
||||
CloseConnection, ConnectionId, ExternalAddresses, NetworkBehaviour, NetworkBehaviourAction,
|
||||
NotifyHandler, PollParameters,
|
||||
NotifyHandler, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
@ -191,7 +191,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection_id: ConnectionId,
|
||||
event: handler::OutboundOutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
let new_events = match event {
|
||||
handler::OutboundOutEvent::InboundEvent { message, .. } => void::unreachable(message),
|
||||
|
@ -31,7 +31,7 @@ use libp2p_core::PeerId;
|
||||
use libp2p_swarm::behaviour::FromSwarm;
|
||||
use libp2p_swarm::{
|
||||
CloseConnection, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||
PollParameters,
|
||||
PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
@ -123,7 +123,7 @@ impl NetworkBehaviour for Behaviour {
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection: ConnectionId,
|
||||
event: handler::InboundOutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
let new_events = match event {
|
||||
handler::InboundOutEvent::InboundEvent { id, message } => {
|
||||
|
@ -74,8 +74,8 @@ use libp2p_core::{ConnectedPoint, Multiaddr, PeerId};
|
||||
use libp2p_swarm::{
|
||||
behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm},
|
||||
dial_opts::DialOpts,
|
||||
ConnectionId, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||
PollParameters,
|
||||
ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
@ -776,8 +776,7 @@ where
|
||||
&mut self,
|
||||
peer: PeerId,
|
||||
connection: ConnectionId,
|
||||
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
libp2p_swarm::ConnectionHandler>::OutEvent,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match event {
|
||||
handler::Event::Response {
|
||||
|
@ -29,7 +29,7 @@ pub use listen_addresses::ListenAddresses;
|
||||
use crate::connection::ConnectionId;
|
||||
use crate::dial_opts::DialOpts;
|
||||
use crate::handler::{ConnectionHandler, IntoConnectionHandler};
|
||||
use crate::{AddressRecord, AddressScore, DialError};
|
||||
use crate::{AddressRecord, AddressScore, DialError, THandlerOutEvent};
|
||||
use libp2p_core::{transport::ListenerId, ConnectedPoint, Multiaddr, PeerId};
|
||||
use std::{task::Context, task::Poll};
|
||||
|
||||
@ -37,9 +37,6 @@ use std::{task::Context, task::Poll};
|
||||
pub(crate) type THandlerInEvent<THandler> =
|
||||
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent;
|
||||
|
||||
pub(crate) type THandlerOutEvent<THandler> =
|
||||
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent;
|
||||
|
||||
/// A [`NetworkBehaviour`] defines the behaviour of the local node on the network.
|
||||
///
|
||||
/// In contrast to [`Transport`](libp2p_core::Transport) which defines **how** to send bytes on the
|
||||
@ -170,8 +167,7 @@ pub trait NetworkBehaviour: 'static {
|
||||
&mut self,
|
||||
_peer_id: PeerId,
|
||||
_connection_id: ConnectionId,
|
||||
_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
_event: THandlerOutEvent<Self>,
|
||||
);
|
||||
|
||||
/// Polls for things that swarm should do.
|
||||
@ -264,7 +260,7 @@ pub enum NetworkBehaviourAction<
|
||||
/// # use libp2p_plaintext::PlainText2Config;
|
||||
/// # use libp2p_swarm::{
|
||||
/// # ConnectionId, DialError, IntoConnectionHandler, KeepAlive, NegotiatedSubstream,
|
||||
/// # FromSwarm, DialFailure,
|
||||
/// # FromSwarm, DialFailure, THandlerOutEvent,
|
||||
/// # NetworkBehaviour, NetworkBehaviourAction, PollParameters, ConnectionHandler,
|
||||
/// # ConnectionHandlerEvent, ConnectionHandlerUpgrErr, SubstreamProtocol, Swarm, SwarmEvent,
|
||||
/// # };
|
||||
@ -334,7 +330,7 @@ pub enum NetworkBehaviourAction<
|
||||
/// # &mut self,
|
||||
/// # _: PeerId,
|
||||
/// # _: ConnectionId,
|
||||
/// # _: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
/// # _: THandlerOutEvent<Self>,
|
||||
/// # ) {
|
||||
/// # unreachable!();
|
||||
/// # }
|
||||
|
@ -21,6 +21,7 @@
|
||||
use crate::behaviour::{self, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use crate::connection::ConnectionId;
|
||||
use crate::handler::either::IntoEitherHandler;
|
||||
use crate::THandlerOutEvent;
|
||||
use either::Either;
|
||||
use libp2p_core::{Multiaddr, PeerId};
|
||||
use std::{task::Context, task::Poll};
|
||||
@ -71,7 +72,7 @@ where
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection_id: ConnectionId,
|
||||
event: crate::THandlerOutEvent<Self>,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
match (self, event) {
|
||||
(Either::Left(left), Either::Left(event)) => {
|
||||
|
@ -26,7 +26,7 @@ use crate::handler::{
|
||||
IntoConnectionHandler, KeepAlive, ListenUpgradeError, SubstreamProtocol,
|
||||
};
|
||||
use crate::upgrade::SendWrapper;
|
||||
use crate::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use crate::{NetworkBehaviour, NetworkBehaviourAction, PollParameters, THandlerOutEvent};
|
||||
use either::Either;
|
||||
use futures::future;
|
||||
use libp2p_core::{upgrade::DeniedUpgrade, ConnectedPoint, Multiaddr, PeerId};
|
||||
@ -94,7 +94,7 @@ where
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
connection_id: ConnectionId,
|
||||
event: crate::THandlerOutEvent<Self>,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
if let Some(behaviour) = &mut self.inner {
|
||||
behaviour.on_connection_handler_event(peer_id, connection_id, event)
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
use crate::connection::{Connection, ConnectionId, PendingPoint};
|
||||
use crate::{
|
||||
behaviour::{THandlerInEvent, THandlerOutEvent},
|
||||
behaviour::THandlerInEvent,
|
||||
connection::{
|
||||
Connected, ConnectionError, ConnectionLimit, IncomingInfo, PendingConnectionError,
|
||||
PendingInboundConnectionError, PendingOutboundConnectionError,
|
||||
@ -294,7 +294,7 @@ pub enum PoolEvent<THandler: IntoConnectionHandler> {
|
||||
id: ConnectionId,
|
||||
peer_id: PeerId,
|
||||
/// The produced event.
|
||||
event: THandlerOutEvent<THandler>,
|
||||
event: <<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
},
|
||||
|
||||
/// The connection to a node has changed its address.
|
||||
|
@ -3,7 +3,10 @@ use crate::connection::ConnectionId;
|
||||
use crate::handler::{
|
||||
ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
|
||||
};
|
||||
use crate::{ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol};
|
||||
use crate::{
|
||||
ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol,
|
||||
THandlerOutEvent,
|
||||
};
|
||||
use libp2p_core::upgrade::DeniedUpgrade;
|
||||
use libp2p_core::PeerId;
|
||||
use libp2p_core::UpgradeError;
|
||||
@ -21,7 +24,12 @@ impl NetworkBehaviour for Behaviour {
|
||||
ConnectionHandler
|
||||
}
|
||||
|
||||
fn on_connection_handler_event(&mut self, _: PeerId, _: ConnectionId, event: Void) {
|
||||
fn on_connection_handler_event(
|
||||
&mut self,
|
||||
_: PeerId,
|
||||
_: ConnectionId,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
void::unreachable(event)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ use crate::handler::{
|
||||
ConnectionEvent, ConnectionHandlerEvent, FullyNegotiatedInbound, FullyNegotiatedOutbound,
|
||||
KeepAlive, SubstreamProtocol,
|
||||
};
|
||||
use crate::THandlerOutEvent;
|
||||
use libp2p_core::upgrade::DeniedUpgrade;
|
||||
use libp2p_core::PeerId;
|
||||
use std::task::{Context, Poll};
|
||||
@ -26,7 +27,12 @@ impl NetworkBehaviour for Behaviour {
|
||||
ConnectionHandler
|
||||
}
|
||||
|
||||
fn on_connection_handler_event(&mut self, _: PeerId, _: ConnectionId, event: Void) {
|
||||
fn on_connection_handler_event(
|
||||
&mut self,
|
||||
_: PeerId,
|
||||
_: ConnectionId,
|
||||
event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
void::unreachable(event)
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ type THandlerInEvent<TBehaviour> =
|
||||
<<THandler<TBehaviour> as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent;
|
||||
|
||||
/// Custom event that can be produced by the [`ConnectionHandler`] of the [`NetworkBehaviour`].
|
||||
type THandlerOutEvent<TBehaviour> =
|
||||
pub type THandlerOutEvent<TBehaviour> =
|
||||
<<THandler<TBehaviour> as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent;
|
||||
|
||||
/// Custom error that can be produced by the [`ConnectionHandler`] of the [`NetworkBehaviour`].
|
||||
|
@ -24,7 +24,7 @@ use crate::behaviour::{
|
||||
};
|
||||
use crate::{
|
||||
ConnectionHandler, ConnectionId, IntoConnectionHandler, NetworkBehaviour,
|
||||
NetworkBehaviourAction, PollParameters,
|
||||
NetworkBehaviourAction, PollParameters, THandlerOutEvent,
|
||||
};
|
||||
use libp2p_core::{multiaddr::Multiaddr, transport::ListenerId, ConnectedPoint, PeerId};
|
||||
use std::collections::HashMap;
|
||||
@ -107,8 +107,7 @@ where
|
||||
&mut self,
|
||||
_peer_id: PeerId,
|
||||
_connection_id: ConnectionId,
|
||||
_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as
|
||||
ConnectionHandler>::OutEvent,
|
||||
_event: THandlerOutEvent<Self>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@ -455,7 +454,7 @@ where
|
||||
&mut self,
|
||||
p: PeerId,
|
||||
c: ConnectionId,
|
||||
e: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
e: THandlerOutEvent<Self>,
|
||||
) {
|
||||
assert!(
|
||||
self.on_connection_established
|
||||
|
@ -21,7 +21,7 @@
|
||||
use futures::StreamExt;
|
||||
use libp2p_identify as identify;
|
||||
use libp2p_ping as ping;
|
||||
use libp2p_swarm::{behaviour::FromSwarm, dummy, NetworkBehaviour, SwarmEvent};
|
||||
use libp2p_swarm::{behaviour::FromSwarm, dummy, NetworkBehaviour, SwarmEvent, THandlerOutEvent};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// Small utility to check that a type implements `NetworkBehaviour`.
|
||||
@ -369,10 +369,7 @@ fn generated_out_event_derive_debug() {
|
||||
#[test]
|
||||
fn custom_out_event_no_type_parameters() {
|
||||
use libp2p_core::PeerId;
|
||||
use libp2p_swarm::{
|
||||
ConnectionHandler, ConnectionId, IntoConnectionHandler, NetworkBehaviourAction,
|
||||
PollParameters,
|
||||
};
|
||||
use libp2p_swarm::{ConnectionId, NetworkBehaviourAction, PollParameters};
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
|
||||
@ -392,7 +389,7 @@ fn custom_out_event_no_type_parameters() {
|
||||
&mut self,
|
||||
_peer: PeerId,
|
||||
_connection: ConnectionId,
|
||||
message: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
message: THandlerOutEvent<Self>,
|
||||
) {
|
||||
void::unreachable(message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user