Skip to content

Commit fd2be38

Browse files
authored
swarm/: Rename ProtocolsHandler to ConnectionHandler (libp2p#2527)
A `ProtocolsHandler`, now `ConnectionHandler`, handels a connection, not a protocol. Thus the name `CONNECTIONHandler` is more appropriate. Next to the rename of `ProtocolsHandler` this commit renames the `mod protocols_handler` to `mod handler`. Finally all combinators (e.g. `ProtocolsHandlerSelect`) are renamed appropriately.
1 parent 6511e6b commit fd2be38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+924
-910
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The main components of this repository are structured as follows:
4343
Multiplexing protocols are (mandatory) `Transport` upgrades.
4444

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

4949
* `protocols/`: Implementations of application protocols based on the

core/src/upgrade.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//!
5454
//! > **Note**: You can use the `apply_inbound` or `apply_outbound` methods to try upgrade a
5555
//! connection or substream. However if you use the recommended `Swarm` or
56-
//! `ProtocolsHandler` APIs, the upgrade is automatically handled for you and you don't
56+
//! `ConnectionHandler` APIs, the upgrade is automatically handled for you and you don't
5757
//! need to use these methods.
5858
//!
5959

examples/file-sharing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod network {
217217
ProtocolSupport, RequestId, RequestResponse, RequestResponseCodec, RequestResponseEvent,
218218
RequestResponseMessage, ResponseChannel,
219219
};
220-
use libp2p::swarm::{ProtocolsHandlerUpgrErr, SwarmBuilder, SwarmEvent};
220+
use libp2p::swarm::{ConnectionHandlerUpgrErr, SwarmBuilder, SwarmEvent};
221221
use libp2p::{NetworkBehaviour, Swarm};
222222
use std::collections::{HashMap, HashSet};
223223
use std::iter;
@@ -404,7 +404,7 @@ mod network {
404404
&mut self,
405405
event: SwarmEvent<
406406
ComposedEvent,
407-
EitherError<ProtocolsHandlerUpgrErr<io::Error>, io::Error>,
407+
EitherError<ConnectionHandlerUpgrErr<io::Error>, io::Error>,
408408
>,
409409
) {
410410
match event {

protocols/autonat/src/behaviour.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use libp2p_request_response::{
3737
RequestResponseConfig, RequestResponseEvent, RequestResponseMessage, ResponseChannel,
3838
};
3939
use libp2p_swarm::{
40-
DialError, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
40+
DialError, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
4141
};
4242
use std::{
4343
collections::{HashMap, VecDeque},
@@ -294,7 +294,7 @@ impl Behaviour {
294294
}
295295

296296
impl NetworkBehaviour for Behaviour {
297-
type ProtocolsHandler = <RequestResponse<AutoNatCodec> as NetworkBehaviour>::ProtocolsHandler;
297+
type ConnectionHandler = <RequestResponse<AutoNatCodec> as NetworkBehaviour>::ConnectionHandler;
298298
type OutEvent = Event;
299299

300300
fn inject_connection_established(
@@ -347,7 +347,7 @@ impl NetworkBehaviour for Behaviour {
347347
peer: &PeerId,
348348
conn: &ConnectionId,
349349
endpoint: &ConnectedPoint,
350-
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
350+
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
351351
remaining_established: usize,
352352
) {
353353
self.inner
@@ -363,7 +363,7 @@ impl NetworkBehaviour for Behaviour {
363363
fn inject_dial_failure(
364364
&mut self,
365365
peer: Option<PeerId>,
366-
handler: Self::ProtocolsHandler,
366+
handler: Self::ConnectionHandler,
367367
error: &DialError,
368368
) {
369369
self.inner.inject_dial_failure(peer, handler, error);
@@ -459,7 +459,7 @@ impl NetworkBehaviour for Behaviour {
459459
}
460460
}
461461

462-
fn new_handler(&mut self) -> Self::ProtocolsHandler {
462+
fn new_handler(&mut self) -> Self::ConnectionHandler {
463463
self.inner.new_handler()
464464
}
465465

@@ -480,7 +480,7 @@ impl NetworkBehaviour for Behaviour {
480480
&mut self,
481481
local_addr: &Multiaddr,
482482
send_back_addr: &Multiaddr,
483-
handler: Self::ProtocolsHandler,
483+
handler: Self::ConnectionHandler,
484484
) {
485485
self.inner
486486
.inject_listen_failure(local_addr, send_back_addr, handler)
@@ -501,7 +501,7 @@ impl NetworkBehaviour for Behaviour {
501501

502502
type Action = NetworkBehaviourAction<
503503
<Behaviour as NetworkBehaviour>::OutEvent,
504-
<Behaviour as NetworkBehaviour>::ProtocolsHandler,
504+
<Behaviour as NetworkBehaviour>::ConnectionHandler,
505505
>;
506506

507507
// Trait implemented for `AsClient` as `AsServer` to handle events from the inner [`RequestResponse`] Protocol.

protocols/dcutr/src/behaviour.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use libp2p_core::multiaddr::Protocol;
2828
use libp2p_core::{Multiaddr, PeerId};
2929
use libp2p_swarm::dial_opts::{self, DialOpts};
3030
use libp2p_swarm::{
31-
DialError, IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
32-
PollParameters, ProtocolsHandler, ProtocolsHandlerUpgrErr,
31+
ConnectionHandler, ConnectionHandlerUpgrErr, DialError, IntoConnectionHandler,
32+
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
3333
};
3434
use std::collections::{HashMap, HashSet, VecDeque};
3535
use std::task::{Context, Poll};
@@ -62,7 +62,7 @@ pub enum UpgradeError {
6262
#[error("Failed to dial peer.")]
6363
Dial,
6464
#[error("Failed to establish substream: {0}.")]
65-
Handler(ProtocolsHandlerUpgrErr<void::Void>),
65+
Handler(ConnectionHandlerUpgrErr<void::Void>),
6666
}
6767

6868
pub struct Behaviour {
@@ -83,10 +83,10 @@ impl Behaviour {
8383
}
8484

8585
impl NetworkBehaviour for Behaviour {
86-
type ProtocolsHandler = handler::Prototype;
86+
type ConnectionHandler = handler::Prototype;
8787
type OutEvent = Event;
8888

89-
fn new_handler(&mut self) -> Self::ProtocolsHandler {
89+
fn new_handler(&mut self) -> Self::ConnectionHandler {
9090
handler::Prototype::UnknownConnection
9191
}
9292

@@ -142,7 +142,7 @@ impl NetworkBehaviour for Behaviour {
142142
fn inject_dial_failure(
143143
&mut self,
144144
peer_id: Option<PeerId>,
145-
handler: Self::ProtocolsHandler,
145+
handler: Self::ConnectionHandler,
146146
_error: &DialError,
147147
) {
148148
match handler {
@@ -187,7 +187,7 @@ impl NetworkBehaviour for Behaviour {
187187
peer_id: &PeerId,
188188
connection_id: &ConnectionId,
189189
connected_point: &ConnectedPoint,
190-
_handler: <<Self as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler,
190+
_handler: <<Self as NetworkBehaviour>::ConnectionHandler as IntoConnectionHandler>::Handler,
191191
_remaining_established: usize,
192192
) {
193193
if !connected_point.is_relayed() {
@@ -209,7 +209,7 @@ impl NetworkBehaviour for Behaviour {
209209
&mut self,
210210
event_source: PeerId,
211211
connection: ConnectionId,
212-
handler_event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
212+
handler_event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
213213
) {
214214
match handler_event {
215215
Either::Left(handler::relayed::Event::InboundConnectRequest {
@@ -313,7 +313,7 @@ impl NetworkBehaviour for Behaviour {
313313
&mut self,
314314
_cx: &mut Context<'_>,
315315
poll_parameters: &mut impl PollParameters,
316-
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
316+
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
317317
if let Some(action) = self.queued_actions.pop_front() {
318318
return Poll::Ready(action.build(poll_parameters));
319319
}

protocols/dcutr/src/handler.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use either::Either;
2323
use libp2p_core::connection::ConnectionId;
2424
use libp2p_core::upgrade::{self, DeniedUpgrade};
2525
use libp2p_core::{ConnectedPoint, PeerId};
26-
use libp2p_swarm::protocols_handler::DummyProtocolsHandler;
27-
use libp2p_swarm::protocols_handler::SendWrapper;
28-
use libp2p_swarm::{IntoProtocolsHandler, ProtocolsHandler};
26+
use libp2p_swarm::handler::DummyConnectionHandler;
27+
use libp2p_swarm::handler::SendWrapper;
28+
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};
2929

3030
pub mod direct;
3131
pub mod relayed;
@@ -43,16 +43,16 @@ pub enum Role {
4343
Listener,
4444
}
4545

46-
impl IntoProtocolsHandler for Prototype {
47-
type Handler = Either<relayed::Handler, Either<direct::Handler, DummyProtocolsHandler>>;
46+
impl IntoConnectionHandler for Prototype {
47+
type Handler = Either<relayed::Handler, Either<direct::Handler, DummyConnectionHandler>>;
4848

4949
fn into_handler(self, _remote_peer_id: &PeerId, endpoint: &ConnectedPoint) -> Self::Handler {
5050
match self {
5151
Self::UnknownConnection => {
5252
if endpoint.is_relayed() {
5353
Either::Left(relayed::Handler::new(endpoint.clone()))
5454
} else {
55-
Either::Right(Either::Right(DummyProtocolsHandler::default()))
55+
Either::Right(Either::Right(DummyConnectionHandler::default()))
5656
}
5757
}
5858
Self::DirectConnection {
@@ -68,7 +68,7 @@ impl IntoProtocolsHandler for Prototype {
6868
}
6969
}
7070

71-
fn inbound_protocol(&self) -> <Self::Handler as ProtocolsHandler>::InboundProtocol {
71+
fn inbound_protocol(&self) -> <Self::Handler as ConnectionHandler>::InboundProtocol {
7272
match self {
7373
Prototype::UnknownConnection => upgrade::EitherUpgrade::A(SendWrapper(
7474
upgrade::EitherUpgrade::A(protocol::inbound::Upgrade {}),

protocols/dcutr/src/handler/direct.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21-
//! [`ProtocolsHandler`] handling direct connection upgraded through a relayed connection.
21+
//! [`ConnectionHandler`] handling direct connection upgraded through a relayed connection.
2222
2323
use libp2p_core::connection::ConnectionId;
2424
use libp2p_core::upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade};
2525
use libp2p_swarm::{
26-
KeepAlive, NegotiatedSubstream, ProtocolsHandler, ProtocolsHandlerEvent,
27-
ProtocolsHandlerUpgrErr, SubstreamProtocol,
26+
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
27+
NegotiatedSubstream, SubstreamProtocol,
2828
};
2929
use std::task::{Context, Poll};
3030
use void::Void;
@@ -48,10 +48,10 @@ impl Handler {
4848
}
4949
}
5050

51-
impl ProtocolsHandler for Handler {
51+
impl ConnectionHandler for Handler {
5252
type InEvent = void::Void;
5353
type OutEvent = Event;
54-
type Error = ProtocolsHandlerUpgrErr<std::io::Error>;
54+
type Error = ConnectionHandlerUpgrErr<std::io::Error>;
5555
type InboundProtocol = DeniedUpgrade;
5656
type OutboundProtocol = DeniedUpgrade;
5757
type OutboundOpenInfo = Void;
@@ -80,7 +80,7 @@ impl ProtocolsHandler for Handler {
8080
fn inject_dial_upgrade_error(
8181
&mut self,
8282
_: Self::OutboundOpenInfo,
83-
_: ProtocolsHandlerUpgrErr<
83+
_: ConnectionHandlerUpgrErr<
8484
<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error,
8585
>,
8686
) {
@@ -94,7 +94,7 @@ impl ProtocolsHandler for Handler {
9494
&mut self,
9595
_: &mut Context<'_>,
9696
) -> Poll<
97-
ProtocolsHandlerEvent<
97+
ConnectionHandlerEvent<
9898
Self::OutboundProtocol,
9999
Self::OutboundOpenInfo,
100100
Self::OutEvent,
@@ -103,7 +103,7 @@ impl ProtocolsHandler for Handler {
103103
> {
104104
if !self.reported {
105105
self.reported = true;
106-
return Poll::Ready(ProtocolsHandlerEvent::Custom(
106+
return Poll::Ready(ConnectionHandlerEvent::Custom(
107107
Event::DirectConnectionUpgradeSucceeded {
108108
relayed_connection_id: self.relayed_connection_id,
109109
},

0 commit comments

Comments
 (0)