mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-30 18:21:33 +00:00
core/src/connection: Add ConnectedPoint::is_relayed (#2392)
Add convenience function `is_relayed` to `ConnectedPoint`, determining whether a connection is relayed based on whether it contains a `Protocol::P2pCircuit`.
This commit is contained in:
@ -35,8 +35,9 @@ pub use pool::{ConnectionCounters, ConnectionLimits};
|
||||
pub use pool::{EstablishedConnection, EstablishedConnectionIter, PendingConnection};
|
||||
pub use substream::{Close, Substream, SubstreamEndpoint};
|
||||
|
||||
use crate::multiaddr::{Multiaddr, Protocol};
|
||||
use crate::muxing::StreamMuxer;
|
||||
use crate::{Multiaddr, PeerId};
|
||||
use crate::PeerId;
|
||||
use std::hash::Hash;
|
||||
use std::{error::Error, fmt, pin::Pin, task::Context, task::Poll};
|
||||
use substream::{Muxing, SubstreamEvent};
|
||||
@ -175,6 +176,16 @@ impl ConnectedPoint {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the connection is relayed.
|
||||
pub fn is_relayed(&self) -> bool {
|
||||
match self {
|
||||
ConnectedPoint::Dialer { address } => address,
|
||||
ConnectedPoint::Listener { local_addr, .. } => local_addr,
|
||||
}
|
||||
.iter()
|
||||
.any(|p| p == Protocol::P2pCircuit)
|
||||
}
|
||||
|
||||
/// Returns the address of the remote stored in this struct.
|
||||
///
|
||||
/// For `Dialer`, this returns `address`. For `Listener`, this returns `send_back_addr`.
|
||||
|
Reference in New Issue
Block a user