diff --git a/src/main.rs b/src/main.rs index a4449cd..72392bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ use crate::pinger::{InFlightProbeCache, PingListener, PingSender}; use crate::pinger_icmp::{PingerICMPEchoListener, PingerICMPEchoSender}; use crate::pinger_icmp_ts::{PingerICMPTimestampListener, PingerICMPTimestampSender}; use crate::platform::{TrafficControlBackend, traffic_control_backend, warn_platform_limitations}; -use crate::ratecontroller::{Ratecontroller, StatsDirection}; +use crate::ratecontroller::Ratecontroller; use crate::reflector_selector::ReflectorSelector; use crate::settings::MeasurementType; use crate::settings::Settings; @@ -155,10 +155,6 @@ fn install_signal_handlers() { } } -fn interface_stats_directions(_: &Settings) -> (StatsDirection, StatsDirection) { - (StatsDirection::RX, StatsDirection::TX) -} - fn probe_identifier() -> u16 { // The ICMP identifier is only two bytes. (process::id() & 0xffff) as u16 @@ -415,24 +411,11 @@ fn run(settings: &Settings) -> anyhow::Result<()> { // Give the baseliner time to collect initial samples before adjusting rates. sleep(Duration::from_secs(10)); - let (dl_direction, ul_direction) = interface_stats_directions(settings); - - debug!( - "Download direction: {}:{:?}", - settings.network.download_interface, dl_direction - ); - debug!( - "Upload direction: {}:{:?}", - settings.network.upload_interface, ul_direction - ); - let mut ratecontroller = Ratecontroller::new( settings.clone(), control_snapshot_rx, reflector_peers, reselect_tx, - dl_direction, - ul_direction, rate_metrics, )?; diff --git a/src/ratecontroller.rs b/src/ratecontroller.rs index 60b49ac..6ba8e5e 100644 --- a/src/ratecontroller.rs +++ b/src/ratecontroller.rs @@ -31,12 +31,6 @@ enum Direction { Up, } -#[derive(Copy, Clone, Debug)] -pub enum StatsDirection { - RX, - TX, -} - fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec { let mut rates = Vec::new(); @@ -49,25 +43,11 @@ fn generate_initial_speeds(base_speed: f64, size: u32) -> Vec { fn get_interface_stats( stats_provider: &mut S, - download_interface: &str, upload_interface: &str, - down_direction: StatsDirection, - up_direction: StatsDirection, ) -> Result<(i128, i128), S::Error> { - let down = stats_provider.read_stats(download_interface)?; - let up = stats_provider.read_stats(upload_interface)?; + let stats = stats_provider.read_stats(upload_interface)?; - let rx_bytes = match down_direction { - StatsDirection::RX => down.rx_bytes, - StatsDirection::TX => down.tx_bytes, - }; - - let tx_bytes = match up_direction { - StatsDirection::RX => up.rx_bytes, - StatsDirection::TX => up.tx_bytes, - }; - - Ok((rx_bytes.into(), tx_bytes.into())) + Ok((stats.rx_bytes.into(), stats.tx_bytes.into())) } #[derive(Clone, Debug)] @@ -160,14 +140,12 @@ pub struct Ratecontroller { settings: Settings, control_snapshot: Option, control_snapshot_rx: Receiver, - down_direction: StatsDirection, reflectors_lock: ArcRwLock>, reselect_trigger: Sender, state_dl: State, state_ul: State, stats_provider: S, traffic_control: T, - up_direction: StatsDirection, metrics: MetricsSender, } @@ -177,8 +155,6 @@ impl Ratecontroller { control_snapshot_rx: Receiver, reflectors_lock: ArcRwLock>, reselect_trigger: Sender, - down_direction: StatsDirection, - up_direction: StatsDirection, metrics: MetricsSender, mut stats_provider: S, mut traffic_control: T, @@ -195,26 +171,19 @@ impl Ratecontroller { settings.advanced_settings.speed_hist_size, ); - let (cur_rx, cur_tx) = get_interface_stats( - &mut stats_provider, - &settings.network.download_interface, - &settings.network.upload_interface, - down_direction, - up_direction, - )?; + let (cur_rx, cur_tx) = + get_interface_stats(&mut stats_provider, &settings.network.upload_interface)?; Ok(Self { settings, control_snapshot: None, control_snapshot_rx, - down_direction, reflectors_lock, reselect_trigger, state_dl: State::new(dl_shaper, cur_rx, dl_safe_rates), state_ul: State::new(ul_shaper, cur_tx, ul_safe_rates), stats_provider, traffic_control, - up_direction, metrics, }) } @@ -350,8 +319,6 @@ impl Ratecontroller { control_snapshot_rx: Receiver, reflectors_lock: ArcRwLock>, reselect_trigger: Sender, - down_direction: StatsDirection, - up_direction: StatsDirection, metrics: MetricsSender, ) -> anyhow::Result { Self::new_with_backends( @@ -359,8 +326,6 @@ impl Ratecontroller { control_snapshot_rx, reflectors_lock, reselect_trigger, - down_direction, - up_direction, metrics, interface_stats_provider(), traffic_control_backend(), @@ -425,10 +390,7 @@ impl Ratecontroller { (self.state_dl.current_bytes, self.state_ul.current_bytes) = get_interface_stats( &mut self.stats_provider, - &self.settings.network.download_interface, &self.settings.network.upload_interface, - self.down_direction, - self.up_direction, )?; self.update_deltas()?;