summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-24 05:58:37 +0200
committertv <tv@krebsco.de>2026-10-24 05:58:37 +0200
commitecec63df16ba51fde6a63c9610a8296fa81c3f54 (patch)
treeef7263d3fdb0afabad63dcc981f6d6079020a7f4 /src/main.rs
parentf62fcc7a033df6e09d19d06ed5302534394a3f65 (diff)
add traffic counter
This introduces a new wrapper that counts messages and payload bytes per peer, split by kind (hello, helloReply, sync, ping, pong), each sent, received and refused. The traffic counter goes around the firewall, which means messages dropped outbound are still counted as sent, and messages dropped inbound don't count as received.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 972c325..8b6f823 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,6 +34,7 @@ use swarm::{bootstrap, peer, sync};
use transport::Transport;
use transport::firewall::{Firewall, FirewallTransport};
use transport::mycelium::{self, MyceliumSetup, MyceliumSpawnConfig};
+use transport::traffic::{CountingTransport, Traffic};
#[derive(Parser, Debug)]
#[command(version, about = "continuum messaging system", long_about = None)]
@@ -167,6 +168,7 @@ async fn main() -> Result<()> {
debug!(epoch = %initial_epoch, "Local epoch");
let firewall = Arc::new(Firewall::default());
+ let traffic = Arc::new(Traffic::default());
let mycelium_transport = Arc::new(mycelium::MyceliumTransport::connect(mycelium_setup).await?);
debug!(local_id = mycelium_transport.local_id(), "Transport ready");
@@ -178,11 +180,17 @@ async fn main() -> Result<()> {
discovered_swarm_id: None,
})),
peer_states: Arc::new(RwLock::new(HashMap::new())),
- transport: Arc::new(FirewallTransport::new(
- mycelium_transport,
- Arc::clone(&firewall),
+ // Counted outside the firewall: what it drops outbound counts as sent (it plays a
+ // lossy network), what it drops inbound never arrived.
+ transport: Arc::new(CountingTransport::new(
+ Arc::new(FirewallTransport::new(
+ mycelium_transport,
+ Arc::clone(&firewall),
+ )),
+ Arc::clone(&traffic),
)),
firewall,
+ traffic,
sync_events: sync_tx,
change_tx,
initial_sync_done: Arc::new(AtomicBool::new(false)),
@@ -208,7 +216,7 @@ async fn main() -> Result<()> {
let inner_state = consumer_state.clone();
let _ = consumer_state
.transport
- .start_consumer(Box::new(move |sender, msg| {
+ .start_consumer(Box::new(move |sender, msg, _payload_len| {
let state_clone = inner_state.clone();
Box::pin(async move { peer::handle_message(&state_clone, sender, msg).await })
}))