Expand description
Per-peer and aggregate bandwidth usage tracking with sliding window rate calculation.
This module provides fine-grained bandwidth monitoring for each connected peer, including:
- Recording inbound and outbound bytes per peer with timestamps
- Sliding window rate calculation (bytes/sec) over a configurable window
- Peak rate detection based on inter-sample intervals
- Aggregate statistics across all peers
- Atomic global counters for lock-free stats snapshots
- Idle peer eviction to bound memory usage
§Example
use ipfrs_network::bandwidth_monitor::{BandwidthMonitor, Direction};
use std::time::Duration;
let monitor = BandwidthMonitor::with_window(Duration::from_secs(10));
monitor.record("peer-1", 1024, Direction::Inbound);
monitor.record("peer-1", 512, Direction::Outbound);
let inbound_rate = monitor.rate_for_peer("peer-1", Direction::Inbound);
println!("peer-1 inbound rate: {:.1} B/s", inbound_rate);
let top = monitor.top_receivers(5);
println!("top receiver: {:?}", top.first());Structs§
- Bandwidth
Monitor - Monitor that tracks per-peer and aggregate bandwidth usage.
- Bandwidth
Monitor Stats - Aggregate statistics maintained by
PeerBandwidthMonitor. - Bandwidth
Sample - A single bandwidth observation recorded at a specific point in time.
- Bandwidth
Stats - Atomic global counters for lock-free stats collection.
- Bandwidth
Stats Snapshot - A point-in-time snapshot of
BandwidthStats. - Monitor
Config - Configuration for
PeerBandwidthMonitor. - Peer
Bandwidth - Per-peer bandwidth state keeping a sliding window of recent samples.
- Peer
Bandwidth Monitor - Tracks per-peer and aggregate bandwidth over a sliding tick window.
- Peer
Bandwidth Window - Sliding-window bandwidth state for a single peer, indexed by logical tick.
- Tick
Bandwidth Sample - A single tick-based bandwidth measurement for a peer.
Enums§
- Bandwidth
Anomaly - An anomaly detected by
PeerBandwidthMonitor. - Direction
- Traffic direction for a bandwidth sample.