refactor(platform): restructure platform-specific abstractions and add synthetic backends

This commit is contained in:
Nils Andreas Svee committed 2026-07-17 13:02:17 +07:00
1 parent 50f0dcb4dd
commit ae9193580c
8 files changed
+228 -172

No files matched your search

+22 -3
View File
@@ -7,15 +7,17 @@ use std::io;
use std::mem::size_of;
use std::ptr;
use log::warn;
use thiserror::Error;
use super::{InterfaceStats, InterfaceStatsProvider};
use super::noop::NoopTrafficControl;
use crate::platform::{InterfaceStats, InterfaceStatsProvider};
const ROUTE_MESSAGE_PREFIX_LEN: usize = size_of::<libc::c_ushort>() + 2;
const SYSCTL_FETCH_ATTEMPTS: usize = 3;
#[derive(Debug, Error)]
pub enum MacOsInterfaceStatsError {
pub(crate) enum MacOsInterfaceStatsError {
#[error("interface name contains a NUL byte")]
InterfaceNameContainsNul(#[source] NulError),
@@ -41,7 +43,7 @@ pub enum MacOsInterfaceStatsError {
}
#[derive(Debug, Default)]
pub struct MacOsInterfaceStats;
pub(crate) struct MacOsInterfaceStats;
impl InterfaceStatsProvider for MacOsInterfaceStats {
type Error = MacOsInterfaceStatsError;
@@ -197,3 +199,20 @@ fn parse_route_messages(
interface_index: requested_interface_index,
})
}
pub(crate) type PlatformInterfaceStats = MacOsInterfaceStats;
pub(crate) type PlatformTrafficControl = NoopTrafficControl;
pub(crate) fn interface_stats_provider() -> PlatformInterfaceStats {
MacOsInterfaceStats
}
pub(crate) fn traffic_control_backend() -> PlatformTrafficControl {
NoopTrafficControl
}
pub(crate) fn warn_platform_limitations() {
warn!(
"Traffic control is unavailable on macOS; requested rate changes will be calculated but not applied."
);
}