diff options
| author | tv <tv@krebsco.de> | 2026-11-01 22:18:40 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 22:18:40 +0100 |
| commit | eb8965ec711971f13254b40f174967c081fba6d0 (patch) | |
| tree | 2c326ab471228bb06d1b446594ab79ae2fee51b5 | |
| parent | 9c2786c2186499595a8b3264d78b1af81f834eb9 (diff) | |
dashboard: always try showing ping/pong alias
| -rw-r--r-- | docs/openapi.yaml | 3 | ||||
| -rw-r--r-- | src/api/dashboard/mod.rs | 25 | ||||
| -rw-r--r-- | src/transport/traffic.rs | 6 |
3 files changed, 32 insertions, 2 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 2867950..a6b7d84 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -608,7 +608,8 @@ paths: event lists the messages the node exchanged since the last (at most every 2 s, 500 at most): `seq`, `at` (Unix ms), `way` (`sent`, `received`, `refused`), `peer` (its node ID; the address for the paths layer's own PINGs - and PONGs), `type` (`SYNC`, …), `counted` (its traffic kind), `bytes`, + and PONGs to an address no known node is at), `address` (for those to an + address a known node is at: which), `type` (`SYNC`, …), `counted` (its traffic kind), `bytes`, `text` (the message written out) and, where it belongs to an exchange, `related` (the same for every message of it). When the node stops, an `offline` event ends the stream (a client reconnects once the node diff --git a/src/api/dashboard/mod.rs b/src/api/dashboard/mod.rs index fdc9b4a..2557906 100644 --- a/src/api/dashboard/mod.rs +++ b/src/api/dashboard/mod.rs @@ -191,7 +191,8 @@ impl Hub { if let Some(changed) = document_changes(&mut changes) { let _ = self.documents.send(Arc::new(changed.to_string())); } - let messages = log.after(logged, MESSAGES_AT_MOST); + let mut messages = log.after(logged, MESSAGES_AT_MOST); + by_node(&self.state, &mut messages).await; if let Some(last) = messages.last() { logged = last.seq; if let Ok(json) = serde_json::to_string(&messages) { @@ -227,6 +228,28 @@ impl Hub { } /// Paths changed in a tick listed at most; more: `all`. +/// The messages the paths layer logged under an address (its own PINGs and PONGs) under +/// the node there instead, where one is known: the address it proved itself at, or is +/// said to be at (`Transport::identities_of`), named in `address`. +async fn by_node(state: &AppState, messages: &mut [crate::transport::traffic::Logged]) { + let peers = state.peers_snapshot().await; + let known = |peer: &str| peers.iter().any(|(known, _)| known == peer); + if messages.iter().all(|message| known(&message.peer)) { + return; + } + let mut nodes: std::collections::HashMap<String, String> = std::collections::HashMap::new(); + for (peer, _) in &peers { + for address in state.transport.identities_of(peer) { + nodes.entry(address).or_insert_with(|| peer.clone()); + } + } + for message in messages { + if let Some(node) = nodes.get(&message.peer) { + message.address = Some(std::mem::replace(&mut message.peer, node.clone())); + } + } +} + const MAX_CHANGED: usize = 256; /// Messages sent to the clients per tick at most, the latest (the console keeps fewer). const MESSAGES_AT_MOST: usize = 500; diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index 041471d..21acca6 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -134,6 +134,11 @@ pub(crate) struct Logged { /// exchange. #[serde(skip_serializing_if = "Option::is_none")] pub(crate) related: Option<String>, + /// The address it went to or came from, where the paths layer logged it under that + /// (its own PINGs and PONGs) and the node there is known: `peer` is the node then + /// (`api::dashboard`). + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) address: Option<String>, } /// What ties `message`, with `peer`, to other messages: a PING and its PONG (the @@ -210,6 +215,7 @@ impl MessageLog { bytes, text, related: related(peer, message), + address: None, }); if inner.entries.len() > LOGGED { inner.entries.pop_front(); |
