diff options
author | Aram Drevekenin <aram@poor.dev> | 2019-11-07 00:03:37 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2019-11-07 00:03:37 +0100 |
commit | 34c952efd287b9cc3da89b5811a092954f4d99e1 (patch) | |
tree | f0a32ce4ed11de48c83e2fc2cb33f885f5bcd439 /src/network/utilization.rs | |
parent | ac42b697ce0ffc20993baa6cbd9c12e1ba518499 (diff) |
fix(packets): take render duration into account so as not to lose any packets
Diffstat (limited to 'src/network/utilization.rs')
-rw-r--r-- | src/network/utilization.rs | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/src/network/utilization.rs b/src/network/utilization.rs index bb3f581..54870dd 100644 --- a/src/network/utilization.rs +++ b/src/network/utilization.rs @@ -1,7 +1,6 @@ use crate::network::{Connection, Direction, Segment}; use ::std::collections::HashMap; -use ::std::time::SystemTime; #[derive(Clone)] pub struct TotalBandwidth { @@ -9,27 +8,9 @@ pub struct TotalBandwidth { pub total_bytes_uploaded: u128, } -impl TotalBandwidth { - pub fn increment_bytes_downloaded(&mut self, data_length: u128, reset_time: &SystemTime) { - if let Ok(elapsed) = reset_time.elapsed() { - if elapsed.as_millis() < 1000 { - self.total_bytes_downloaded += data_length; - } - } - } - pub fn increment_bytes_uploaded(&mut self, data_length: u128, reset_time: &SystemTime) { - if let Ok(elapsed) = reset_time.elapsed() { - if elapsed.as_millis() < 1000 { - self.total_bytes_uploaded += data_length; - } - } - } -} - #[derive(Clone)] pub struct Utilization { pub connections: HashMap<Connection, TotalBandwidth>, - reset_time: SystemTime, } impl Utilization { @@ -37,12 +18,10 @@ impl Utilization { let connections = HashMap::new(); Utilization { connections, - reset_time: SystemTime::now(), } } pub fn clone_and_reset(&mut self) -> Self { let clone = self.clone(); - self.reset_time = SystemTime::now(); self.connections.clear(); clone } @@ -56,10 +35,10 @@ impl Utilization { }); match seg.direction { Direction::Download => { - total_bandwidth.increment_bytes_downloaded(seg.data_length, &self.reset_time); + total_bandwidth.total_bytes_downloaded += seg.data_length; } Direction::Upload => { - total_bandwidth.increment_bytes_uploaded(seg.data_length, &self.reset_time); + total_bandwidth.total_bytes_uploaded += seg.data_length; } } } |