summaryrefslogtreecommitdiffstats
path: root/src/api/peers.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-27 01:34:15 +0100
committertv <tv@krebsco.de>2026-10-27 01:34:15 +0100
commit2593edca179e86883e74c7039629564f4ea6ec55 (patch)
tree64257a6f5b1cf79b0e8d39bdfbfadb3e72c78e9c /src/api/peers.rs
parent4cdece6d0f8e25ac154c3fd0f30bca604b08c16a (diff)
admit nodeId and addresses in the API
Diffstat (limited to 'src/api/peers.rs')
-rw-r--r--src/api/peers.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs
index bc32ae1..9e907ac 100644
--- a/src/api/peers.rs
+++ b/src/api/peers.rs
@@ -48,6 +48,8 @@ impl From<Epoch> for EpochInfo {
pub(crate) struct PeerStatus {
/// The name the peer gave itself in the member list, if any (not unique).
alias: Option<String>,
+ /// Where this node reaches it, or would (`Transport::addresses_of`).
+ addresses: Vec<String>,
validated_swarm: Option<String>,
status: PeerLivenessStatus,
handshake_complete: bool,
@@ -93,7 +95,9 @@ pub(crate) struct PeerListResponse {
/// Number of heads of our document. Several heads are concurrent changes no later
/// change has merged yet.
local_heads: usize,
- /// By public key.
+ /// Where this node can be reached (`Transport::local_addresses`).
+ local_addresses: Vec<String>,
+ /// By node ID.
peers: BTreeMap<String, PeerStatus>,
}
@@ -114,17 +118,17 @@ pub(crate) async fn list_peers(
let mut aliases = crate::swarm::members::aliases(&state.doc.read().await.doc);
let mut peers = BTreeMap::new();
- for (public_key, peer_state_mutex) in snapshot {
- let neighbour = crate::swarm::topology::is_neighbour(&state, &public_key);
+ for (peer, peer_state_mutex) in snapshot {
+ let neighbour = crate::swarm::topology::is_neighbour(&state, &peer);
let rtt_ms = state
.lock_rtt()
- .effective(&public_key, now, state.timing.rtt_fresh_for())
+ .effective(&peer, now, state.timing.rtt_fresh_for())
.map(|rtt| rtt.as_secs_f64() * 1000.0);
- let traffic = state.traffic.peer(&public_key).unwrap_or_default();
+ let traffic = state.traffic.peer(&peer).unwrap_or_default();
let sync_throughput = state
.throughput
.lock_or_recover()
- .get(&public_key)
+ .get(&peer)
.map(|estimate| ThroughputInfo {
bytes_per_sec: estimate.bytes_per_sec.round(),
samples: estimate.samples,
@@ -140,11 +144,13 @@ pub(crate) async fn list_peers(
),
};
- let alias = aliases.remove(&public_key);
+ let alias = aliases.remove(&peer);
+ let addresses = state.transport.addresses_of(&peer);
peers.insert(
- public_key,
+ peer,
PeerStatus {
alias,
+ addresses,
validated_swarm: ps.standing.swarm_id().map(str::to_owned),
status,
handshake_complete: ps.hello_state == HelloState::Established,
@@ -168,6 +174,7 @@ pub(crate) async fn list_peers(
let local_heads = state.doc.read().await.heads().len();
Ok(Json(PeerListResponse {
local_alias: state.alias.clone(),
+ local_addresses: state.transport.local_addresses(),
local_epoch: local_epoch.into(),
local_heads,
peers,