Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm/: Rename ProtocolsHandler to ConnectionHandler #2527

Merged
merged 4 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The main components of this repository are structured as follows:
Multiplexing protocols are (mandatory) `Transport` upgrades.

* `swarm/`: The implementation of `libp2p-swarm` building on `libp2p-core`
with the central interfaces `NetworkBehaviour` and `ProtocolsHandler` used
with the central interfaces `NetworkBehaviour` and `ConnectionHandler` used
to implement application protocols (see `protocols/`).

* `protocols/`: Implementations of application protocols based on the
Expand Down
2 changes: 1 addition & 1 deletion core/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//!
//! > **Note**: You can use the `apply_inbound` or `apply_outbound` methods to try upgrade a
//! connection or substream. However if you use the recommended `Swarm` or
//! `ProtocolsHandler` APIs, the upgrade is automatically handled for you and you don't
//! `ConnectionHandler` APIs, the upgrade is automatically handled for you and you don't
//! need to use these methods.
//!

Expand Down
4 changes: 2 additions & 2 deletions examples/file-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod network {
ProtocolSupport, RequestId, RequestResponse, RequestResponseCodec, RequestResponseEvent,
RequestResponseMessage, ResponseChannel,
};
use libp2p::swarm::{ProtocolsHandlerUpgrErr, SwarmBuilder, SwarmEvent};
use libp2p::swarm::{ConnectionHandlerUpgrErr, SwarmBuilder, SwarmEvent};
use libp2p::{NetworkBehaviour, Swarm};
use std::collections::{HashMap, HashSet};
use std::iter;
Expand Down Expand Up @@ -404,7 +404,7 @@ mod network {
&mut self,
event: SwarmEvent<
ComposedEvent,
EitherError<ProtocolsHandlerUpgrErr<io::Error>, io::Error>,
EitherError<ConnectionHandlerUpgrErr<io::Error>, io::Error>,
>,
) {
match event {
Expand Down
14 changes: 7 additions & 7 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use libp2p_request_response::{
RequestResponseConfig, RequestResponseEvent, RequestResponseMessage, ResponseChannel,
};
use libp2p_swarm::{
DialError, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
DialError, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
};
use std::{
collections::{HashMap, VecDeque},
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Behaviour {
}

impl NetworkBehaviour for Behaviour {
type ProtocolsHandler = <RequestResponse<AutoNatCodec> as NetworkBehaviour>::ProtocolsHandler;
type ConnectionHandler = <RequestResponse<AutoNatCodec> as NetworkBehaviour>::ConnectionHandler;
type OutEvent = Event;

fn inject_connection_established(
Expand Down Expand Up @@ -347,7 +347,7 @@ impl NetworkBehaviour for Behaviour {
peer: &PeerId,
conn: &ConnectionId,
endpoint: &ConnectedPoint,
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
remaining_established: usize,
) {
self.inner
Expand All @@ -363,7 +363,7 @@ impl NetworkBehaviour for Behaviour {
fn inject_dial_failure(
&mut self,
peer: Option<PeerId>,
handler: Self::ProtocolsHandler,
handler: Self::ConnectionHandler,
error: &DialError,
) {
self.inner.inject_dial_failure(peer, handler, error);
Expand Down Expand Up @@ -459,7 +459,7 @@ impl NetworkBehaviour for Behaviour {
}
}

fn new_handler(&mut self) -> Self::ProtocolsHandler {
fn new_handler(&mut self) -> Self::ConnectionHandler {
self.inner.new_handler()
}

Expand All @@ -480,7 +480,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
local_addr: &Multiaddr,
send_back_addr: &Multiaddr,
handler: Self::ProtocolsHandler,
handler: Self::ConnectionHandler,
) {
self.inner
.inject_listen_failure(local_addr, send_back_addr, handler)
Expand All @@ -501,7 +501,7 @@ impl NetworkBehaviour for Behaviour {

type Action = NetworkBehaviourAction<
<Behaviour as NetworkBehaviour>::OutEvent,
<Behaviour as NetworkBehaviour>::ProtocolsHandler,
<Behaviour as NetworkBehaviour>::ConnectionHandler,
>;

// Trait implemented for `AsClient` as `AsServer` to handle events from the inner [`RequestResponse`] Protocol.
Expand Down
18 changes: 9 additions & 9 deletions protocols/dcutr/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use libp2p_core::multiaddr::Protocol;
use libp2p_core::{Multiaddr, PeerId};
use libp2p_swarm::dial_opts::{self, DialOpts};
use libp2p_swarm::{
DialError, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
PollParameters, ProtocolsHandler, ProtocolsHandlerUpgrErr,
ConnectionHandler, ConnectionHandlerUpgrErr, DialError, IntoConnectionHandler,
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
};
use std::collections::{HashMap, HashSet, VecDeque};
use std::task::{Context, Poll};
Expand Down Expand Up @@ -62,7 +62,7 @@ pub enum UpgradeError {
#[error("Failed to dial peer.")]
Dial,
#[error("Failed to establish substream: {0}.")]
Handler(ProtocolsHandlerUpgrErr<void::Void>),
Handler(ConnectionHandlerUpgrErr<void::Void>),
}

pub struct Behaviour {
Expand All @@ -83,10 +83,10 @@ impl Behaviour {
}

impl NetworkBehaviour for Behaviour {
type ProtocolsHandler = handler::Prototype;
type ConnectionHandler = handler::Prototype;
type OutEvent = Event;

fn new_handler(&mut self) -> Self::ProtocolsHandler {
fn new_handler(&mut self) -> Self::ConnectionHandler {
handler::Prototype::UnknownConnection
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl NetworkBehaviour for Behaviour {
fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ProtocolsHandler,
handler: Self::ConnectionHandler,
_error: &DialError,
) {
match handler {
Expand Down Expand Up @@ -187,7 +187,7 @@ impl NetworkBehaviour for Behaviour {
peer_id: &PeerId,
connection_id: &ConnectionId,
connected_point: &ConnectedPoint,
_handler: <<Self as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler,
_handler: <<Self as NetworkBehaviour>::ConnectionHandler as IntoConnectionHandler>::Handler,
_remaining_established: usize,
) {
if !connected_point.is_relayed() {
Expand All @@ -209,7 +209,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
event_source: PeerId,
connection: ConnectionId,
handler_event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
handler_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
) {
match handler_event {
Either::Left(handler::relayed::Event::InboundConnectRequest {
Expand Down Expand Up @@ -313,7 +313,7 @@ impl NetworkBehaviour for Behaviour {
&mut self,
_cx: &mut Context<'_>,
poll_parameters: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
if let Some(action) = self.queued_actions.pop_front() {
return Poll::Ready(action.build(poll_parameters));
}
Expand Down
14 changes: 7 additions & 7 deletions protocols/dcutr/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use either::Either;
use libp2p_core::connection::ConnectionId;
use libp2p_core::upgrade::{self, DeniedUpgrade};
use libp2p_core::{ConnectedPoint, PeerId};
use libp2p_swarm::protocols_handler::DummyProtocolsHandler;
use libp2p_swarm::protocols_handler::SendWrapper;
use libp2p_swarm::{IntoProtocolsHandler, ProtocolsHandler};
use libp2p_swarm::handler::DummyConnectionHandler;
use libp2p_swarm::handler::SendWrapper;
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};

pub mod direct;
pub mod relayed;
Expand All @@ -43,16 +43,16 @@ pub enum Role {
Listener,
}

impl IntoProtocolsHandler for Prototype {
type Handler = Either<relayed::Handler, Either<direct::Handler, DummyProtocolsHandler>>;
impl IntoConnectionHandler for Prototype {
type Handler = Either<relayed::Handler, Either<direct::Handler, DummyConnectionHandler>>;

fn into_handler(self, _remote_peer_id: &PeerId, endpoint: &ConnectedPoint) -> Self::Handler {
match self {
Self::UnknownConnection => {
if endpoint.is_relayed() {
Either::Left(relayed::Handler::new(endpoint.clone()))
} else {
Either::Right(Either::Right(DummyProtocolsHandler::default()))
Either::Right(Either::Right(DummyConnectionHandler::default()))
}
}
Self::DirectConnection {
Expand All @@ -68,7 +68,7 @@ impl IntoProtocolsHandler for Prototype {
}
}

fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
fn inbound_protocol(&self) -> <Self::Handler as ConnectionHandler>::InboundProtocol {
match self {
Prototype::UnknownConnection => upgrade::EitherUpgrade::A(SendWrapper(
upgrade::EitherUpgrade::A(protocol::inbound::Upgrade {}),
Expand Down
16 changes: 8 additions & 8 deletions protocols/dcutr/src/handler/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! [`ProtocolsHandler`] handling direct connection upgraded through a relayed connection.
//! [`ConnectionHandler`] handling direct connection upgraded through a relayed connection.

use libp2p_core::connection::ConnectionId;
use libp2p_core::upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade};
use libp2p_swarm::{
KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent,
ProtocolsHandlerUpgrErr, SubstreamProtocol,
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
NegotiatedSubstream, SubstreamProtocol,
};
use std::task::{Context, Poll};
use void::Void;
Expand All @@ -48,10 +48,10 @@ impl Handler {
}
}

impl ProtocolsHandler for Handler {
impl ConnectionHandler for Handler {
type InEvent = void::Void;
type OutEvent = Event;
type Error = ProtocolsHandlerUpgrErr<std::io::Error>;
type Error = ConnectionHandlerUpgrErr<std::io::Error>;
type InboundProtocol = DeniedUpgrade;
type OutboundProtocol = DeniedUpgrade;
type OutboundOpenInfo = Void;
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ProtocolsHandler for Handler {
fn inject_dial_upgrade_error(
&mut self,
_: Self::OutboundOpenInfo,
_: ProtocolsHandlerUpgrErr<
_: ConnectionHandlerUpgrErr<
<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error,
>,
) {
Expand All @@ -94,7 +94,7 @@ impl ProtocolsHandler for Handler {
&mut self,
_: &mut Context<'_>,
) -> Poll<
ProtocolsHandlerEvent<
ConnectionHandlerEvent<
Self::OutboundProtocol,
Self::OutboundOpenInfo,
Self::OutEvent,
Expand All @@ -103,7 +103,7 @@ impl ProtocolsHandler for Handler {
> {
if !self.reported {
self.reported = true;
return Poll::Ready(ProtocolsHandlerEvent::Custom(
return Poll::Ready(ConnectionHandlerEvent::Custom(
Event::DirectConnectionUpgradeSucceeded {
relayed_connection_id: self.relayed_connection_id,
},
Expand Down
Loading