Skip to main content

Module bandwidth_monitor

Module bandwidth_monitor 

Source
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§

BandwidthMonitor
Monitor that tracks per-peer and aggregate bandwidth usage.
BandwidthMonitorStats
Aggregate statistics maintained by PeerBandwidthMonitor.
BandwidthSample
A single bandwidth observation recorded at a specific point in time.
BandwidthStats
Atomic global counters for lock-free stats collection.
BandwidthStatsSnapshot
A point-in-time snapshot of BandwidthStats.
MonitorConfig
Configuration for PeerBandwidthMonitor.
PeerBandwidth
Per-peer bandwidth state keeping a sliding window of recent samples.
PeerBandwidthMonitor
Tracks per-peer and aggregate bandwidth over a sliding tick window.
PeerBandwidthWindow
Sliding-window bandwidth state for a single peer, indexed by logical tick.
TickBandwidthSample
A single tick-based bandwidth measurement for a peer.

Enums§

BandwidthAnomaly
An anomaly detected by PeerBandwidthMonitor.
Direction
Traffic direction for a bandwidth sample.