pub use multiaddr;
pub use multistream_select::Negotiated;
mod keys_proto;
mod peer_id;
mod translation;
#[cfg(test)]
mod tests;
pub mod either;
pub mod identity;
pub mod muxing;
pub mod nodes;
pub mod transport;
pub mod upgrade;
pub use multiaddr::Multiaddr;
pub use muxing::StreamMuxer;
pub use peer_id::PeerId;
pub use identity::PublicKey;
pub use transport::Transport;
pub use translation::address_translation;
pub use upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo, UpgradeError, ProtocolName};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Endpoint {
Dialer,
Listener,
}
impl std::ops::Not for Endpoint {
type Output = Endpoint;
fn not(self) -> Self::Output {
match self {
Endpoint::Dialer => Endpoint::Listener,
Endpoint::Listener => Endpoint::Dialer
}
}
}
impl Endpoint {
pub fn is_dialer(self) -> bool {
if let Endpoint::Dialer = self {
true
} else {
false
}
}
pub fn is_listener(self) -> bool {
if let Endpoint::Listener = self {
true
} else {
false
}
}
}
#[derive(Debug, Clone)]
pub enum ConnectedPoint {
Dialer {
address: Multiaddr,
},
Listener {
listen_addr: Multiaddr,
send_back_addr: Multiaddr,
}
}
impl From<&'_ ConnectedPoint> for Endpoint {
fn from(endpoint: &'_ ConnectedPoint) -> Endpoint {
endpoint.to_endpoint()
}
}
impl From<ConnectedPoint> for Endpoint {
fn from(endpoint: ConnectedPoint) -> Endpoint {
endpoint.to_endpoint()
}
}
impl ConnectedPoint {
pub fn to_endpoint(&self) -> Endpoint {
match self {
ConnectedPoint::Dialer { .. } => Endpoint::Dialer,
ConnectedPoint::Listener { .. } => Endpoint::Listener
}
}
pub fn is_dialer(&self) -> bool {
match self {
ConnectedPoint::Dialer { .. } => true,
ConnectedPoint::Listener { .. } => false
}
}
pub fn is_listener(&self) -> bool {
match self {
ConnectedPoint::Dialer { .. } => false,
ConnectedPoint::Listener { .. } => true
}
}
}