mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 00:01:33 +00:00
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`.
This commit is contained in:
@ -20,29 +20,6 @@
|
||||
|
||||
use crate::multiaddr::{Multiaddr, Protocol};
|
||||
|
||||
/// Connection identifier.
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ConnectionId(usize);
|
||||
|
||||
impl ConnectionId {
|
||||
/// Creates a `ConnectionId` from a non-negative integer.
|
||||
///
|
||||
/// This is primarily useful for creating connection IDs
|
||||
/// in test environments. There is in general no guarantee
|
||||
/// that all connection IDs are based on non-negative integers.
|
||||
pub fn new(id: usize) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<usize> for ConnectionId {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: usize) -> Self {
|
||||
Self(self.0 + other)
|
||||
}
|
||||
}
|
||||
|
||||
/// The endpoint roles associated with a peer-to-peer communication channel.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Endpoint {
|
||||
@ -75,42 +52,6 @@ impl Endpoint {
|
||||
}
|
||||
}
|
||||
|
||||
/// The endpoint roles associated with a pending peer-to-peer connection.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum PendingPoint {
|
||||
/// The socket comes from a dialer.
|
||||
///
|
||||
/// There is no single address associated with the Dialer of a pending
|
||||
/// connection. Addresses are dialed in parallel. Only once the first dial
|
||||
/// is successful is the address of the connection known.
|
||||
Dialer {
|
||||
/// Same as [`ConnectedPoint::Dialer`] `role_override`.
|
||||
role_override: Endpoint,
|
||||
},
|
||||
/// The socket comes from a listener.
|
||||
Listener {
|
||||
/// Local connection address.
|
||||
local_addr: Multiaddr,
|
||||
/// Address used to send back data to the remote.
|
||||
send_back_addr: Multiaddr,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<ConnectedPoint> for PendingPoint {
|
||||
fn from(endpoint: ConnectedPoint) -> Self {
|
||||
match endpoint {
|
||||
ConnectedPoint::Dialer { role_override, .. } => PendingPoint::Dialer { role_override },
|
||||
ConnectedPoint::Listener {
|
||||
local_addr,
|
||||
send_back_addr,
|
||||
} => PendingPoint::Listener {
|
||||
local_addr,
|
||||
send_back_addr,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The endpoint roles associated with an established peer-to-peer connection.
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
||||
pub enum ConnectedPoint {
|
||||
|
Reference in New Issue
Block a user