diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 439543f8318..04362c936da 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -263,6 +263,13 @@ impl Behaviour { self.confidence } + // Connected peers with the observed address of each connection. + // If the endpoint of a connection is relayed or not global (in case of Config::only_global_ips), + // the observed address is `None`. + pub fn connected(&self) -> HashMap>> { + self.connected.clone() + } + /// Add a peer to the list over servers that may be used for probes. /// These peers are used for dial-request even if they are currently not connection, in which case a connection will be /// establish before sending the dial-request. diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index f572b937d38..2643a3c38c4 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -176,6 +176,11 @@ impl Behaviour { } } + /// For each peer we're connected to, the observed address to send back to it. + pub fn connected(&self) -> HashMap> { + self.connected.clone() + } + /// Initiates an active push of the local peer information to the given peers. pub fn push(&mut self, peers: I) where diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 7b1a8088443..406fb0a7e65 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -351,6 +351,17 @@ where { Self::with_codec(TCodec::default(), protocols, cfg) } + + /// The currently connected peers, their pending outbound and inbound responses and their known, + /// reachable addresses, if any. + pub fn connected(&self) -> HashMap> { + self.connected.clone() + } + + /// Externally managed addresses via `add_address` and `remove_address`. + pub fn addresses(&self) -> HashMap> { + self.addresses.clone() + } } impl Behaviour @@ -922,7 +933,8 @@ where const EMPTY_QUEUE_SHRINK_THRESHOLD: usize = 100; /// Internal information tracked for an established connection. -struct Connection { +#[derive(Clone)] +pub struct Connection { id: ConnectionId, address: Option, /// Pending outbound responses where corresponding inbound requests have @@ -943,4 +955,12 @@ impl Connection { pending_inbound_responses: Default::default(), } } + + pub fn id(&self) -> ConnectionId { + self.id + } + + pub fn address(&self) -> Option { + self.address.clone() + } }