From e918c062f39599950e95fb88bfd66c4f46689108 Mon Sep 17 00:00:00 2001 From: Giuliano Bellini s294739 Date: Sat, 18 Feb 2023 22:20:51 +0100 Subject: [PATCH] removed unnecessary fields from logged notifications structs --- src/enums/logged_notification.rs | 7 ++++--- src/gui/pages/notifications_page.rs | 17 ++++------------- src/utility/manage_notifications.rs | 5 +++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/enums/logged_notification.rs b/src/enums/logged_notification.rs index ac895fe9..8a953e98 100644 --- a/src/enums/logged_notification.rs +++ b/src/enums/logged_notification.rs @@ -1,6 +1,6 @@ use crate::structs::address_port_pair::AddressPortPair; use crate::structs::info_address_port_pair::InfoAddressPortPair; -use crate::structs::notifications::{BytesNotification, PacketsNotification}; +use crate::ByteMultiple; /// Enum representing the possible observed values of IP protocol version. pub enum LoggedNotification { @@ -14,7 +14,7 @@ pub enum LoggedNotification { #[derive(Clone)] pub struct PacketsThresholdExceeded { - pub(crate) notification: PacketsNotification, + pub(crate) threshold: u32, pub(crate) incoming: u32, pub(crate) outgoing: u32, pub(crate) timestamp: String, @@ -22,7 +22,8 @@ pub struct PacketsThresholdExceeded { #[derive(Clone)] pub struct BytesThresholdExceeded { - pub(crate) notification: BytesNotification, + pub(crate) threshold: u64, + pub(crate) byte_multiple: ByteMultiple, pub(crate) incoming: u32, pub(crate) outgoing: u32, pub(crate) timestamp: String, diff --git a/src/gui/pages/notifications_page.rs b/src/gui/pages/notifications_page.rs index a5485847..4f22c7c1 100644 --- a/src/gui/pages/notifications_page.rs +++ b/src/gui/pages/notifications_page.rs @@ -181,12 +181,7 @@ fn packets_notification_log( ) -> Container<'static, Message> { let font = get_font(style); let mut threshold_str = threshold_translation(language); - threshold_str.push_str( - &logged_notification - .notification - .previous_threshold - .to_string(), - ); + threshold_str.push_str(&logged_notification.threshold.to_string()); threshold_str.push_str(&format!(" {}", per_second_translation(language))); let mut incoming_str = " - ".to_string(); incoming_str.push_str(incoming_translation(language)); @@ -253,16 +248,12 @@ fn bytes_notification_log( let font = get_font(style); let mut threshold_str = threshold_translation(language); threshold_str.push_str( - &(logged_notification.notification.previous_threshold - / logged_notification - .notification - .byte_multiple - .get_multiplier()) - .to_string(), + &(logged_notification.threshold / logged_notification.byte_multiple.get_multiplier()) + .to_string(), ); threshold_str.push_str(&format!( " {}", - logged_notification.notification.byte_multiple.get_char() + logged_notification.byte_multiple.get_char() )); threshold_str.push_str(&format!(" {}", per_second_translation(language))); let mut incoming_str = " - ".to_string(); diff --git a/src/utility/manage_notifications.rs b/src/utility/manage_notifications.rs index 478f1034..bf2d227a 100644 --- a/src/utility/manage_notifications.rs +++ b/src/utility/manage_notifications.rs @@ -28,7 +28,7 @@ pub fn notify_and_log( } runtime_data.logged_notifications.push_front( LoggedNotification::PacketsThresholdExceeded(PacketsThresholdExceeded { - notification: notifications.packets_notification, + threshold: notifications.packets_notification.previous_threshold, incoming: received_packets_entry.try_into().unwrap(), outgoing: sent_packets_entry.try_into().unwrap(), timestamp: Local::now().to_string().get(11..19).unwrap().to_string(), @@ -58,7 +58,8 @@ pub fn notify_and_log( } runtime_data.logged_notifications.push_front( LoggedNotification::BytesThresholdExceeded(BytesThresholdExceeded { - notification: notifications.bytes_notification, + threshold: notifications.bytes_notification.previous_threshold, + byte_multiple: notifications.bytes_notification.byte_multiple, incoming: received_bytes_entry.try_into().unwrap(), outgoing: sent_bytes_entry.try_into().unwrap(), timestamp: Local::now().to_string().get(11..19).unwrap().to_string(),