From b0624ffd4c7dc53cb0aa1f04c73cd6838c83730a Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Tue, 30 Jun 2020 03:05:24 -0400 Subject: [PATCH 1/2] Update net to ignore all tunnels and bonds since both will contribute to double counting --- src/widgets/net.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/widgets/net.rs b/src/widgets/net.rs index d523a4a..4b6666c 100644 --- a/src/widgets/net.rs +++ b/src/widgets/net.rs @@ -12,7 +12,8 @@ use crate::colorscheme::Colorscheme; use crate::update::UpdatableWidget; use crate::widgets::block; -const VPN_INTERFACE: &str = "tun0"; +const BOND_INTERFACE_PRFIX: &str = "bond"; +const TUN_INTERFACE_PREFIX: &str = "tun"; pub struct NetWidget<'a, 'b> { title: String, @@ -62,9 +63,14 @@ impl UpdatableWidget for NetWidget<'_, '_> { .unwrap() .into_iter() .filter(|(name, _counters)| { - // Filter out the VPN interface unless specified directly since it gets double + // Filter out tunnels and bonds unless specified directly since it gets double // counted along with the hardware interfaces it is operating on. - (self.interface == "all" && name != VPN_INTERFACE) || name == self.interface + // TODO: Ideally it would be good to detect if the interface is virtual instead of + // hardcoding these cases + (self.interface == "all" + && !name.starts_with(TUN_INTERFACE_PREFIX) + && !name.starts_with(BOND_INTERFACE_PRFIX)) + || name == self.interface }) .map(|(_name, counters)| counters) .sum(); From 474b8fd6e51a529db9fc818830b28fdd7f3981f3 Mon Sep 17 00:00:00 2001 From: Lovecraftian Horror Date: Thu, 23 Jul 2020 14:48:55 -0400 Subject: [PATCH 2/2] Fix typo in new const name --- src/widgets/net.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/net.rs b/src/widgets/net.rs index 4b6666c..57802e1 100644 --- a/src/widgets/net.rs +++ b/src/widgets/net.rs @@ -12,7 +12,7 @@ use crate::colorscheme::Colorscheme; use crate::update::UpdatableWidget; use crate::widgets::block; -const BOND_INTERFACE_PRFIX: &str = "bond"; +const BOND_INTERFACE_PREFIX: &str = "bond"; const TUN_INTERFACE_PREFIX: &str = "tun"; pub struct NetWidget<'a, 'b> { @@ -69,7 +69,7 @@ impl UpdatableWidget for NetWidget<'_, '_> { // hardcoding these cases (self.interface == "all" && !name.starts_with(TUN_INTERFACE_PREFIX) - && !name.starts_with(BOND_INTERFACE_PRFIX)) + && !name.starts_with(BOND_INTERFACE_PREFIX)) || name == self.interface }) .map(|(_name, counters)| counters)