mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-31 17:01:58 +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:
@@ -42,13 +42,36 @@ use libp2p_core::connection::ConnectedPoint;
|
||||
use libp2p_core::multiaddr::Multiaddr;
|
||||
use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerEvent, StreamMuxerExt, SubstreamBox};
|
||||
use libp2p_core::upgrade::{InboundUpgradeApply, OutboundUpgradeApply};
|
||||
use libp2p_core::PeerId;
|
||||
use libp2p_core::{upgrade, UpgradeError};
|
||||
use libp2p_core::{Endpoint, PeerId};
|
||||
use std::future::Future;
|
||||
use std::task::Waker;
|
||||
use std::time::Duration;
|
||||
use std::{fmt, io, mem, pin::Pin, task::Context, task::Poll};
|
||||
|
||||
/// 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)
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a successfully established connection.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Connected {
|
||||
@@ -824,3 +847,39 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The endpoint roles associated with a pending peer-to-peer connection.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user