mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-10-23 23:51:18 +00:00
show data agglomerates in inspect page corresponding to the selected data representation in overview page
This commit is contained in:
parent
c3f5008e58
commit
ae068d228b
3 changed files with 38 additions and 21 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue