mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
swarm: Split off "keep alive" functionality from DummyConnectionHandler
(#2859)
Previously, the `DummyConnectionHandler` offered a "keep alive" functionality, i.e. it allowed users to set the value of what is returned from `ConnectionHandler::keep_alive`. This handler is primarily used in tests or `NetworkBehaviour`s that don't open any connections (like mDNS). In all of these cases, it is statically known whether we want to keep connections alive. As such, this functionality is better represented by a static `KeepAliveConnectionHandler` that always returns `KeepAlive::Yes` and a `DummyConnectionHandler` that always returns `KeepAlive::No`. To follow the naming conventions described in https://github.com/libp2p/rust-libp2p/issues/2217, we introduce a top-level `keep_alive` and `dummy` behaviour in `libp2p-swarm` that contains both the `NetworkBehaviour` and `ConnectionHandler` implementation for either case.
This commit is contained in:
@ -23,7 +23,7 @@ use either::Either;
|
||||
use libp2p_core::connection::ConnectionId;
|
||||
use libp2p_core::upgrade::{self, DeniedUpgrade};
|
||||
use libp2p_core::{ConnectedPoint, PeerId};
|
||||
use libp2p_swarm::handler::DummyConnectionHandler;
|
||||
use libp2p_swarm::dummy;
|
||||
use libp2p_swarm::handler::SendWrapper;
|
||||
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};
|
||||
|
||||
@ -44,7 +44,7 @@ pub enum Role {
|
||||
}
|
||||
|
||||
impl IntoConnectionHandler for Prototype {
|
||||
type Handler = Either<relayed::Handler, Either<direct::Handler, DummyConnectionHandler>>;
|
||||
type Handler = Either<relayed::Handler, Either<direct::Handler, dummy::ConnectionHandler>>;
|
||||
|
||||
fn into_handler(self, _remote_peer_id: &PeerId, endpoint: &ConnectedPoint) -> Self::Handler {
|
||||
match self {
|
||||
@ -52,7 +52,7 @@ impl IntoConnectionHandler for Prototype {
|
||||
if endpoint.is_relayed() {
|
||||
Either::Left(relayed::Handler::new(endpoint.clone()))
|
||||
} else {
|
||||
Either::Right(Either::Right(DummyConnectionHandler::default()))
|
||||
Either::Right(Either::Right(dummy::ConnectionHandler))
|
||||
}
|
||||
}
|
||||
Self::DirectConnection {
|
||||
|
Reference in New Issue
Block a user