diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/dashboard/mod.rs | 25 | ||||
| -rw-r--r-- | src/transport/traffic.rs | 6 |
2 files changed, 30 insertions, 1 deletions
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(); |
