aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/traffic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/traffic.rs')
-rw-r--r--src/transport/traffic.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs
index 948e5d5..bac0da7 100644
--- a/src/transport/traffic.rs
+++ b/src/transport/traffic.rs
@@ -150,12 +150,16 @@ const LOGGED: usize = 1000;
const LOGGED_TEXT: usize = 8 * 1024;
/// The node's messages one by one, for the dashboard's console (`api::dashboard`):
-/// kept only while it looks (`watch`), the latest `LOGGED`. Those this layer sees: the
-/// node's own, not the paths layer's PINGs and PONGs nor the identity layer's WHO and
-/// ME (counted under their addresses, `ByKind`), but the PINGs and PONGs the node is
-/// handed.
+/// kept only while it looks (`watch`), the latest `LOGGED`. The node's own, each with
+/// the address it went to or came from where the identity layer notes them (`addressed`,
+/// `transport::identity`), else as `CountingTransport` sees them; and the paths layer's
+/// PINGs and PONGs, under their addresses; not the identity layer's WHO and ME (counted
+/// under their addresses, `ByKind`).
#[derive(Debug, Default)]
pub(crate) struct MessageLog {
+ /// The identity layer notes the node's messages, with their addresses
+ /// (`set_addressed`): `CountingTransport`, above it, leaves them to it.
+ addressed: std::sync::atomic::AtomicBool,
/// How many look (`watch`).
watching: AtomicUsize,
/// Told of each message logged, for those sending them on as they come (`logged`).
@@ -192,9 +196,9 @@ 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`).
+ /// The address it went to or came from: of a node's message, where the identity
+ /// layer noted it; of the paths layer's PINGs and PONGs, logged under the address,
+ /// where the node there is known (`peer` is the node then, `api::dashboard`).
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) address: Option<String>,
}
@@ -254,10 +258,21 @@ impl MessageLog {
self.inner.lock_or_recover().next
}
+ /// The identity layer notes the node's messages from now on, with their addresses.
+ pub(crate) fn set_addressed(&self) {
+ self.addressed.store(true, Ordering::Relaxed);
+ }
+
+ /// Whether the identity layer notes the node's messages (`set_addressed`).
+ pub(crate) fn addressed(&self) -> bool {
+ self.addressed.load(Ordering::Relaxed)
+ }
+
pub(crate) fn note(
&self,
way: &'static str,
peer: &str,
+ address: Option<&str>,
message: &ParsedMessage,
bytes: usize,
) {
@@ -290,7 +305,7 @@ impl MessageLog {
bytes,
text,
related: related(peer, message),
- address: None,
+ address: address.map(str::to_owned),
});
if inner.entries.len() > LOGGED {
inner.entries.pop_front();
@@ -523,11 +538,13 @@ impl Transport for CountingTransport {
self.traffic
.refused(&message.peer, message.kind, message.payload_len);
}
- if let Some(parsed) = &message.message {
+ if let Some(parsed) = &message.message
+ && !self.traffic.log.addressed()
+ {
let way = if result.is_ok() { "sent" } else { "refused" };
self.traffic
.log
- .note(way, &message.peer, parsed, message.payload_len);
+ .note(way, &message.peer, None, parsed, message.payload_len);
}
result
}
@@ -537,7 +554,11 @@ impl Transport for CountingTransport {
self.inner
.start_consumer(Box::new(move |sender, message, payload_len| {
traffic.received(&sender, message.kind(), payload_len);
- traffic.log.note("received", &sender, &message, payload_len);
+ if !traffic.log.addressed() {
+ traffic
+ .log
+ .note("received", &sender, None, &message, payload_len);
+ }
handler(sender, message, payload_len)
}))
.await