Skip to content

Commit 475dc80

Browse files
refactor!: Move ConnectionId and PendingPoint to libp2p-swarm (#3346)
Both of these are only needed as part of `libp2p-swarm`. Them residing in `libp2p-core` is a left-over from when `libp2p-core` still contained `Pool`.
1 parent db2cd43 commit 475dc80

File tree

34 files changed

+132
-133
lines changed

34 files changed

+132
-133
lines changed

core/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.39.0 [unreleased]
2+
3+
- Move `ConnectionId` to `libp2p-swarm`. See [PR 3221].
4+
- Move `PendingPoint` to `libp2p-swarm` and make it crate-private. See [PR 3221].
5+
6+
[PR 3221]: https://github.com/libp2p/rust-libp2p/pull/3221
7+
18
# 0.38.0
29

310
- Remove deprecated functions `StreamMuxerExt::next_{inbound,outbound}`. See [PR 3031].

core/src/connection.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@
2020

2121
use crate::multiaddr::{Multiaddr, Protocol};
2222

23-
/// Connection identifier.
24-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
25-
pub struct ConnectionId(usize);
26-
27-
impl ConnectionId {
28-
/// Creates a `ConnectionId` from a non-negative integer.
29-
///
30-
/// This is primarily useful for creating connection IDs
31-
/// in test environments. There is in general no guarantee
32-
/// that all connection IDs are based on non-negative integers.
33-
pub fn new(id: usize) -> Self {
34-
Self(id)
35-
}
36-
}
37-
38-
impl std::ops::Add<usize> for ConnectionId {
39-
type Output = Self;
40-
41-
fn add(self, other: usize) -> Self {
42-
Self(self.0 + other)
43-
}
44-
}
45-
4623
/// The endpoint roles associated with a peer-to-peer communication channel.
4724
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
4825
pub enum Endpoint {
@@ -75,42 +52,6 @@ impl Endpoint {
7552
}
7653
}
7754

78-
/// The endpoint roles associated with a pending peer-to-peer connection.
79-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
80-
pub enum PendingPoint {
81-
/// The socket comes from a dialer.
82-
///
83-
/// There is no single address associated with the Dialer of a pending
84-
/// connection. Addresses are dialed in parallel. Only once the first dial
85-
/// is successful is the address of the connection known.
86-
Dialer {
87-
/// Same as [`ConnectedPoint::Dialer`] `role_override`.
88-
role_override: Endpoint,
89-
},
90-
/// The socket comes from a listener.
91-
Listener {
92-
/// Local connection address.
93-
local_addr: Multiaddr,
94-
/// Address used to send back data to the remote.
95-
send_back_addr: Multiaddr,
96-
},
97-
}
98-
99-
impl From<ConnectedPoint> for PendingPoint {
100-
fn from(endpoint: ConnectedPoint) -> Self {
101-
match endpoint {
102-
ConnectedPoint::Dialer { role_override, .. } => PendingPoint::Dialer { role_override },
103-
ConnectedPoint::Listener {
104-
local_addr,
105-
send_back_addr,
106-
} => PendingPoint::Listener {
107-
local_addr,
108-
send_back_addr,
109-
},
110-
}
111-
}
112-
}
113-
11455
/// The endpoint roles associated with an established peer-to-peer connection.
11556
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
11657
pub enum ConnectedPoint {

protocols/autonat/src/behaviour.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ use as_server::AsServer;
2828
pub use as_server::{InboundProbeError, InboundProbeEvent};
2929
use futures_timer::Delay;
3030
use instant::Instant;
31-
use libp2p_core::{
32-
connection::ConnectionId, multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr, PeerId,
33-
};
31+
use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr, PeerId};
3432
use libp2p_request_response::{
3533
self as request_response, ProtocolSupport, RequestId, ResponseChannel,
3634
};
@@ -39,8 +37,8 @@ use libp2p_swarm::{
3937
AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredExternalAddr,
4038
ExpiredListenAddr, FromSwarm,
4139
},
42-
ConnectionHandler, ExternalAddresses, IntoConnectionHandler, ListenAddresses, NetworkBehaviour,
43-
NetworkBehaviourAction, PollParameters,
40+
ConnectionHandler, ConnectionId, ExternalAddresses, IntoConnectionHandler, ListenAddresses,
41+
NetworkBehaviour, NetworkBehaviourAction, PollParameters,
4442
};
4543
use std::{
4644
collections::{HashMap, VecDeque},

protocols/autonat/src/behaviour/as_client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ use super::{
2727
use futures::FutureExt;
2828
use futures_timer::Delay;
2929
use instant::Instant;
30-
use libp2p_core::{connection::ConnectionId, Multiaddr, PeerId};
30+
use libp2p_core::{Multiaddr, PeerId};
3131
use libp2p_request_response::{self as request_response, OutboundFailure, RequestId};
3232
use libp2p_swarm::{
33-
AddressScore, ExternalAddresses, ListenAddresses, NetworkBehaviourAction, PollParameters,
33+
AddressScore, ConnectionId, ExternalAddresses, ListenAddresses, NetworkBehaviourAction,
34+
PollParameters,
3435
};
3536
use rand::{seq::SliceRandom, thread_rng};
3637
use std::{

protocols/autonat/src/behaviour/as_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ use super::{
2323
ResponseError,
2424
};
2525
use instant::Instant;
26-
use libp2p_core::{connection::ConnectionId, multiaddr::Protocol, Multiaddr, PeerId};
26+
use libp2p_core::{multiaddr::Protocol, Multiaddr, PeerId};
2727
use libp2p_request_response::{
2828
self as request_response, InboundFailure, RequestId, ResponseChannel,
2929
};
3030
use libp2p_swarm::{
3131
dial_opts::{DialOpts, PeerCondition},
32-
DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
32+
ConnectionId, DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
3333
};
3434
use std::{
3535
collections::{HashMap, HashSet, VecDeque},

protocols/dcutr/src/behaviour_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
2323
use crate::handler;
2424
use either::Either;
25-
use libp2p_core::connection::{ConnectedPoint, ConnectionId};
25+
use libp2p_core::connection::ConnectedPoint;
2626
use libp2p_core::multiaddr::Protocol;
2727
use libp2p_core::{Multiaddr, PeerId};
2828
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
2929
use libp2p_swarm::dial_opts::{self, DialOpts};
30+
use libp2p_swarm::ConnectionId;
3031
use libp2p_swarm::{
3132
ConnectionHandler, ConnectionHandlerUpgrErr, ExternalAddresses, IntoConnectionHandler,
3233
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,

protocols/dcutr/src/handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
use crate::protocol;
2222
use either::Either;
23-
use libp2p_core::connection::ConnectionId;
2423
use libp2p_core::upgrade::DeniedUpgrade;
2524
use libp2p_core::{ConnectedPoint, PeerId};
2625
use libp2p_swarm::dummy;
2726
use libp2p_swarm::handler::SendWrapper;
28-
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};
27+
use libp2p_swarm::{ConnectionHandler, ConnectionId, IntoConnectionHandler};
2928

3029
pub mod direct;
3130
pub mod relayed;

protocols/dcutr/src/handler/direct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020

2121
//! [`ConnectionHandler`] handling direct connection upgraded through a relayed connection.
2222
23-
use libp2p_core::connection::ConnectionId;
2423
use libp2p_core::upgrade::DeniedUpgrade;
2524
use libp2p_swarm::handler::ConnectionEvent;
2625
use libp2p_swarm::{
27-
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
26+
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, ConnectionId, KeepAlive,
2827
SubstreamProtocol,
2928
};
3029
use std::task::{Context, Poll};

protocols/floodsub/src/layer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use crate::topic::Topic;
2626
use crate::FloodsubConfig;
2727
use cuckoofilter::{CuckooError, CuckooFilter};
2828
use fnv::FnvHashSet;
29-
use libp2p_core::{connection::ConnectionId, PeerId};
29+
use libp2p_core::PeerId;
3030
use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm};
3131
use libp2p_swarm::{
32-
dial_opts::DialOpts, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, OneShotHandler,
33-
PollParameters,
32+
dial_opts::DialOpts, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
33+
OneShotHandler, PollParameters,
3434
};
3535
use libp2p_swarm::{ConnectionHandler, IntoConnectionHandler};
3636
use log::warn;

protocols/gossipsub/src/behaviour.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ use prost::Message;
3636
use rand::{seq::SliceRandom, thread_rng};
3737

3838
use libp2p_core::{
39-
connection::ConnectionId, identity::Keypair, multiaddr::Protocol::Ip4,
40-
multiaddr::Protocol::Ip6, Multiaddr, PeerId,
39+
identity::Keypair, multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Multiaddr, PeerId,
4140
};
4241
use libp2p_swarm::{
4342
behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, FromSwarm},
4443
dial_opts::DialOpts,
45-
ConnectionHandler, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction,
46-
NotifyHandler, PollParameters,
44+
ConnectionHandler, ConnectionId, IntoConnectionHandler, NetworkBehaviour,
45+
NetworkBehaviourAction, NotifyHandler, PollParameters,
4746
};
4847
use wasm_timer::Instant;
4948

0 commit comments

Comments
 (0)