Skip to content

Commit

Permalink
expose Behaviour::connected and Behaviour::addresses
Browse files Browse the repository at this point in the history
Signed-off-by: ozkanonur <[email protected]>
  • Loading branch information
onur-ozkan committed Jun 22, 2023
1 parent b23a4a7 commit 9c75886
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions protocols/autonat/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerId, HashMap<ConnectionId, Option<Multiaddr>>> {
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.
Expand Down
5 changes: 5 additions & 0 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerId, HashMap<ConnectionId, Multiaddr>> {
self.connected.clone()
}

/// Initiates an active push of the local peer information to the given peers.
pub fn push<I>(&mut self, peers: I)
where
Expand Down
22 changes: 21 additions & 1 deletion protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerId, SmallVec<[Connection; 2]>> {
self.connected.clone()
}

/// Externally managed addresses via `add_address` and `remove_address`.
pub fn addresses(&self) -> HashMap<PeerId, SmallVec<[Multiaddr; 6]>> {
self.addresses.clone()
}
}

impl<TCodec> Behaviour<TCodec>
Expand Down Expand Up @@ -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<Multiaddr>,
/// Pending outbound responses where corresponding inbound requests have
Expand All @@ -943,4 +955,12 @@ impl Connection {
pending_inbound_responses: Default::default(),
}
}

pub fn id(&self) -> ConnectionId {
self.id
}

pub fn address(&self) -> Option<Multiaddr> {
self.address.clone()
}
}

0 comments on commit 9c75886

Please sign in to comment.