From ae068d228bda8e8341fe56dd7960e14371fbbfd7 Mon Sep 17 00:00:00 2001 From: GyulyVGC Date: Sat, 1 Feb 2025 11:17:02 +0100 Subject: [PATCH] show data agglomerates in inspect page corresponding to the selected data representation in overview page --- src/gui/pages/inspect_page.rs | 26 ++++++++++++++++++-------- src/networking/types/data_info.rs | 12 ++++++++++++ src/report/get_report_entries.rs | 21 ++++++++------------- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/gui/pages/inspect_page.rs b/src/gui/pages/inspect_page.rs index e36060c1..13cb7c14 100644 --- a/src/gui/pages/inspect_page.rs +++ b/src/gui/pages/inspect_page.rs @@ -11,6 +11,7 @@ use iced::widget::{ use iced::widget::{lazy, Button, Column, Container, Row, Scrollable, Text, TextInput}; use iced::{alignment, Alignment, Font, Length, Padding, Pixels}; +use crate::chart::types::chart_type::ChartType; use crate::gui::components::tab::get_pages_tabs; use crate::gui::components::types::my_modal::MyModal; use crate::gui::pages::overview_page::get_bars; @@ -23,6 +24,7 @@ use crate::gui::styles::text_input::TextInputType; use crate::gui::types::message::Message; use crate::networking::types::address_port_pair::AddressPortPair; use crate::networking::types::byte_multiple::ByteMultiple; +use crate::networking::types::data_info::DataInfoWithoutTimestamp; use crate::networking::types::host_data_states::HostStates; use crate::networking::types::info_address_port_pair::InfoAddressPortPair; use crate::networking::types::traffic_direction::TrafficDirection; @@ -118,8 +120,7 @@ fn lazy_report<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType> { } = sniffer.configs.lock().unwrap().settings; let font = style.get_extension().font; - let (search_results, results_number, packets, in_bytes, out_bytes) = - get_searched_entries(sniffer); + let (search_results, results_number, agglomerate) = get_searched_entries(sniffer); let mut ret_val = Column::new() .height(Length::Fill) @@ -150,7 +151,11 @@ fn lazy_report<'a>(sniffer: &Sniffer) -> Column<'a, Message, StyleType> { .width(Length::Fill), ) .push(Rule::horizontal(5)) - .push(get_agglomerates_row(font, packets, in_bytes, out_bytes)) + .push(get_agglomerates_row( + font, + agglomerate, + sniffer.traffic_chart.chart_type, + )) .push(Rule::horizontal(5)) .push(get_change_page_row( font, @@ -554,14 +559,19 @@ fn get_button_change_page<'a>(increment: bool) -> Button<'a, Message, StyleType> fn get_agglomerates_row<'a>( font: Font, - tot_packets: u128, - tot_in_bytes: u128, - tot_out_bytes: u128, + tot: DataInfoWithoutTimestamp, + chart_type: ChartType, ) -> Row<'a, Message, StyleType> { - let tot_bytes = tot_in_bytes + tot_out_bytes; + let tot_packets = tot.incoming_packets + tot.outgoing_packets; + let tot_bytes = tot.incoming_bytes + tot.outgoing_bytes; let width = ReportCol::FILTER_COLUMNS_WIDTH; + #[allow(clippy::cast_precision_loss)] - let in_length = width * (tot_in_bytes as f32 / tot_bytes as f32); + let in_length = if chart_type == ChartType::Packets { + width * (tot.incoming_packets as f32 / tot_packets as f32) + } else { + width * (tot.incoming_bytes as f32 / tot_bytes as f32) + }; let out_length = width - in_length; let bars = get_bars(in_length, out_length); diff --git a/src/networking/types/data_info.rs b/src/networking/types/data_info.rs index 0408b63b..766cc340 100644 --- a/src/networking/types/data_info.rs +++ b/src/networking/types/data_info.rs @@ -122,3 +122,15 @@ impl AddAssign for DataInfo { self.final_timestamp = Local::now(); } } + +#[derive(Clone, Default, Copy)] +pub struct DataInfoWithoutTimestamp { + /// Incoming packets + pub incoming_packets: u128, + /// Outgoing packets + pub outgoing_packets: u128, + /// Incoming bytes + pub incoming_bytes: u128, + /// Outgoing bytes + pub outgoing_bytes: u128, +} diff --git a/src/report/get_report_entries.rs b/src/report/get_report_entries.rs index e1c1da5b..893f1237 100644 --- a/src/report/get_report_entries.rs +++ b/src/report/get_report_entries.rs @@ -3,7 +3,7 @@ use std::sync::Mutex; use crate::networking::manage_packets::get_address_to_lookup; use crate::networking::types::address_port_pair::AddressPortPair; -use crate::networking::types::data_info::DataInfo; +use crate::networking::types::data_info::{DataInfo, DataInfoWithoutTimestamp}; use crate::networking::types::data_info_host::DataInfoHost; use crate::networking::types::host::Host; use crate::networking::types::info_address_port_pair::InfoAddressPortPair; @@ -19,13 +19,9 @@ pub fn get_searched_entries( ) -> ( Vec<(AddressPortPair, InfoAddressPortPair)>, usize, - u128, - u128, - u128, + DataInfoWithoutTimestamp, ) { - let mut tot_packets = 0; - let mut tot_in_bytes = 0; - let mut tot_out_bytes = 0; + let mut agglomerate = DataInfoWithoutTimestamp::default(); let info_traffic_lock = sniffer.info_traffic.lock().unwrap(); let mut all_results: Vec<(&AddressPortPair, &InfoAddressPortPair)> = info_traffic_lock .map @@ -43,11 +39,12 @@ pub fn get_searched_entries( .match_entry(key, value, r_dns_host, is_favorite) }) .map(|(key, val)| { - tot_packets += val.transmitted_packets; if val.traffic_direction == TrafficDirection::Outgoing { - tot_out_bytes += val.transmitted_bytes; + agglomerate.outgoing_packets += val.transmitted_packets; + agglomerate.outgoing_bytes += val.transmitted_bytes; } else { - tot_in_bytes += val.transmitted_bytes; + agglomerate.incoming_packets += val.transmitted_packets; + agglomerate.incoming_bytes += val.transmitted_bytes; } (key, val) }) @@ -83,9 +80,7 @@ pub fn get_searched_entries( .map(|&(key, val)| (key.to_owned(), val.to_owned())) .collect(), all_results.len(), - tot_packets, - tot_in_bytes, - tot_out_bytes, + agglomerate, ) }