Rust CI / cargo fmt (push) Successful in 11s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (push) Failing after 37s
Rust CI / cargo clippy (push) Failing after 37s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (push) Failing after 41s
Rust CI / cargo check (x86_64-unknown-linux-musl) (push) Failing after 7s
Rust CI / cargo test (x86_64-unknown-linux-musl) (push) Failing after 9s
Rust CI / cargo doc (push) Successful in 32s
Supply chain / cargo-deny advisories (push) Failing after 1m38s
Supply chain / actionlint (push) Successful in 6s
Supply chain / cargo-deny bans licenses sources (push) Failing after 1m40s
64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
// SPDX-FileCopyrightText: 2026-Present Nils Andreas Svee mailto:contact@lochnair.net (github @Lochnair)
|
|
//
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
use std::error::Error;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub(crate) struct InterfaceStats {
|
|
pub(crate) rx_bytes: u64,
|
|
pub(crate) tx_bytes: u64,
|
|
}
|
|
|
|
pub(crate) trait InterfaceStatsProvider: Send {
|
|
type Error: Error + Send + Sync + 'static;
|
|
|
|
fn read_stats(&mut self, interface: &str) -> Result<InterfaceStats, Self::Error>;
|
|
}
|
|
|
|
pub(crate) trait TrafficControlBackend: Send {
|
|
type Error: Error + Send + Sync + 'static;
|
|
type Handle: Send + 'static;
|
|
|
|
fn find_shaper(&mut self, interface: &str) -> Result<Self::Handle, Self::Error>;
|
|
|
|
fn set_rate(
|
|
&mut self,
|
|
shaper: &Self::Handle,
|
|
bandwidth_kbit: u64,
|
|
dry_run: bool,
|
|
) -> Result<(), Self::Error>;
|
|
}
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
mod noop;
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
mod freebsd;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
mod linux;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
mod macos;
|
|
|
|
#[cfg(not(any(target_os = "freebsd", target_os = "linux", target_os = "macos")))]
|
|
mod unsupported;
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
use freebsd as imp;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
use linux as imp;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
use macos as imp;
|
|
|
|
#[cfg(not(any(target_os = "freebsd", target_os = "linux", target_os = "macos")))]
|
|
use unsupported as imp;
|
|
|
|
pub(crate) use imp::{
|
|
PlatformInterfaceStats, PlatformTrafficControl, interface_stats_provider,
|
|
traffic_control_backend, warn_platform_limitations,
|
|
};
|