mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-01 18:51:35 +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:
@ -9,9 +9,12 @@
|
|||||||
|
|
||||||
- Add support for ECDSA identities (see [PR 2352]).
|
- Add support for ECDSA identities (see [PR 2352]).
|
||||||
|
|
||||||
|
- Add `ConnectedPoint::is_relayed` (see [PR 2392]).
|
||||||
|
|
||||||
[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
|
[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339
|
||||||
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350
|
[PR 2350]: https://github.com/libp2p/rust-libp2p/pull/2350
|
||||||
[PR 2352]: https://github.com/libp2p/rust-libp2p/pull/2352
|
[PR 2352]: https://github.com/libp2p/rust-libp2p/pull/2352
|
||||||
|
[PR 2392]: https://github.com/libp2p/rust-libp2p/pull/2392
|
||||||
|
|
||||||
# 0.30.1 [2021-11-16]
|
# 0.30.1 [2021-11-16]
|
||||||
|
|
||||||
|
@ -35,8 +35,9 @@ pub use pool::{ConnectionCounters, ConnectionLimits};
|
|||||||
pub use pool::{EstablishedConnection, EstablishedConnectionIter, PendingConnection};
|
pub use pool::{EstablishedConnection, EstablishedConnectionIter, PendingConnection};
|
||||||
pub use substream::{Close, Substream, SubstreamEndpoint};
|
pub use substream::{Close, Substream, SubstreamEndpoint};
|
||||||
|
|
||||||
|
use crate::multiaddr::{Multiaddr, Protocol};
|
||||||
use crate::muxing::StreamMuxer;
|
use crate::muxing::StreamMuxer;
|
||||||
use crate::{Multiaddr, PeerId};
|
use crate::PeerId;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::{error::Error, fmt, pin::Pin, task::Context, task::Poll};
|
use std::{error::Error, fmt, pin::Pin, task::Context, task::Poll};
|
||||||
use substream::{Muxing, SubstreamEvent};
|
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.
|
/// Returns the address of the remote stored in this struct.
|
||||||
///
|
///
|
||||||
/// For `Dialer`, this returns `address`. For `Listener`, this returns `send_back_addr`.
|
/// For `Dialer`, this returns `address`. For `Listener`, this returns `send_back_addr`.
|
||||||
|
Reference in New Issue
Block a user