Skip to main content

naia_shared/connection/
bandwidth.rs

1/// Per-connection outbound bandwidth budget. Applied symmetrically to
2/// server-outbound and client-outbound send loops.
3///
4/// Not to be confused with `ConnectionConfig::bandwidth_measure_duration`,
5/// which is a telemetry/averaging window — this is the actual token-bucket cap
6/// consumed by the unified priority-sort send loop.
7#[derive(Clone, Debug)]
8pub struct BandwidthConfig {
9    /// Target outbound bytes-per-second per connection. Budget accumulates as
10    /// `target_bytes_per_sec × dt` each tick; surplus carries into the next
11    /// tick (Fiedler token-bucket).
12    pub target_bytes_per_sec: u32,
13}
14
15impl BandwidthConfig {
16    /// 512 kbps — generous default; overridable.
17    pub const DEFAULT_TARGET_BYTES_PER_SEC: u32 = 64_000;
18}
19
20impl Default for BandwidthConfig {
21    fn default() -> Self {
22        Self {
23            target_bytes_per_sec: Self::DEFAULT_TARGET_BYTES_PER_SEC,
24        }
25    }
26}