diff options
| author | tv <tv@krebsco.de> | 2026-10-27 01:34:15 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-27 01:34:15 +0100 |
| commit | 2593edca179e86883e74c7039629564f4ea6ec55 (patch) | |
| tree | 64257a6f5b1cf79b0e8d39bdfbfadb3e72c78e9c /src/api | |
| parent | 4cdece6d0f8e25ac154c3fd0f30bca604b08c16a (diff) | |
admit nodeId and addresses in the API
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/peers.rs | 23 | ||||
| -rw-r--r-- | src/api/stats.rs | 7 | ||||
| -rw-r--r-- | src/api/stats/prometheus.rs | 8 |
3 files changed, 22 insertions, 16 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, diff --git a/src/api/stats.rs b/src/api/stats.rs index fabbffd..fa64600 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -21,7 +21,9 @@ use crate::transport::traffic::PeerTraffic; #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub(crate) struct StatsResponse { - public_key: String, + node_id: String, + /// Where this node can be reached (`Transport::local_addresses`). + addresses: Vec<String>, alias: Option<String>, uptime_secs: u64, ready: bool, @@ -228,7 +230,8 @@ async fn collect(state: &AppState) -> StatsResponse { } StatsResponse { - public_key: state.local_id().to_owned(), + node_id: state.local_id().to_owned(), + addresses: state.transport.local_addresses(), alias: state.alias.clone(), uptime_secs: node.uptime.as_secs(), ready: state.is_ready().await, diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs index 8d31eb0..01cd271 100644 --- a/src/api/stats/prometheus.rs +++ b/src/api/stats/prometheus.rs @@ -190,15 +190,11 @@ pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String { // Names for joining (`* on(peer) group_left(alias) continuum_peer_info`), kept out // of the other series so a rename doesn't start new ones. - out.family( - "info", - "gauge", - "This node's public key and alias (always 1).", - ); + out.family("info", "gauge", "This node's node ID and alias (always 1)."); out.sample( "info", &[ - ("public_key", &stats.public_key), + ("node_id", &stats.node_id), ("alias", stats.alias.as_deref().unwrap_or("")), ], 1.0, |
