Skip to content

Commit

Permalink
moved link_type field from RunTimeData to MyDevice struct
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Jan 1, 2024
1 parent 6eb68c3 commit 6fd1b97
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 141 deletions.
2 changes: 0 additions & 2 deletions src/chart/manage_chart_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ mod tests {
use std::collections::VecDeque;

use crate::chart::manage_chart_data::{get_max, get_min, update_charts_data};
use crate::networking::types::my_link_type::MyLinkType;
use crate::{ChartType, Language, RunTimeData, StyleType, TrafficChart};

#[test]
Expand Down Expand Up @@ -168,7 +167,6 @@ mod tests {
style: StyleType::default(),
};
let mut runtime_data = RunTimeData {
link_type: MyLinkType::NotYetAssigned,
all_bytes: 0,
all_packets: 0,
tot_sent_bytes: tot_sent + 1111,
Expand Down
3 changes: 3 additions & 0 deletions src/configs/types/config_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use pcap::{Device, DeviceFlags};
use serde::{Deserialize, Serialize};

use crate::networking::types::my_device::MyDevice;
use crate::networking::types::my_link_type::MyLinkType;
#[cfg(not(test))]
use crate::SNIFFNET_LOWERCASE;

Expand Down Expand Up @@ -57,6 +58,7 @@ impl ConfigDevice {
name: device.name,
desc: device.desc,
addresses: Arc::new(Mutex::new(device.addresses)),
link_type: MyLinkType::NotYetAssigned,
};
}
}
Expand All @@ -70,6 +72,7 @@ impl ConfigDevice {
name: standard_device.name,
desc: standard_device.desc,
addresses: Arc::new(Mutex::new(standard_device.addresses)),
link_type: MyLinkType::NotYetAssigned,
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/gui/pages/overview_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::networking::types::data_info::DataInfo;
use crate::networking::types::filters::Filters;
use crate::networking::types::host::Host;
use crate::networking::types::my_device::MyDevice;
use crate::networking::types::my_link_type::MyLinkType;
use crate::networking::types::search_parameters::SearchParameters;
use crate::report::get_report_entries::{get_app_entries, get_host_entries};
use crate::translations::translations::{
Expand Down Expand Up @@ -67,13 +66,11 @@ pub fn overview_page(sniffer: &Sniffer) -> Container<Message, Renderer<StyleType
sniffer.runtime_data.tot_sent_packets + sniffer.runtime_data.tot_received_packets;
let dropped = sniffer.runtime_data.dropped_packets;
let total = observed + u128::from(dropped);
let link_type = sniffer.runtime_data.link_type;

match (observed, filtered) {
(0, 0) => {
//no packets observed at all
body =
body_no_packets(&sniffer.device, font, language, &sniffer.waiting, link_type);
body = body_no_packets(&sniffer.device, font, language, &sniffer.waiting);
}
(observed, 0) => {
//no packets have been filtered but some have been observed
Expand Down Expand Up @@ -143,8 +140,8 @@ fn body_no_packets(
font: Font,
language: Language,
waiting: &str,
link_type: MyLinkType,
) -> Column<'static, Message, Renderer<StyleType>> {
let link_type = device.link_type;
let mut adapter_info = device.name.clone();
adapter_info.push_str(&format!("\n{}", link_type.full_print_on_one_line(language)));
let (icon_text, nothing_to_see_text) = if !link_type.is_supported() {
Expand Down Expand Up @@ -431,9 +428,8 @@ fn lazy_col_info(
style, language, ..
} = sniffer.configs.lock().unwrap().settings;
let font = style.get_extension().font;
let link_type = sniffer.runtime_data.link_type;

let col_device = col_device(language, font, &sniffer.device, link_type);
let col_device = col_device(language, font, &sniffer.device);

let col_data_representation =
col_data_representation(language, font, sniffer.traffic_chart.chart_type);
Expand Down Expand Up @@ -513,8 +509,8 @@ fn col_device(
language: Language,
font: Font,
device: &MyDevice,
link_type: MyLinkType,
) -> Column<'static, Message, Renderer<StyleType>> {
let link_type = device.link_type;
#[cfg(not(target_os = "windows"))]
let adapter_info = &device.name;
#[cfg(target_os = "windows")]
Expand Down
4 changes: 0 additions & 4 deletions src/gui/types/runtime_data.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//! Module defining the `RunTimeData` struct, useful to to generate chart and to display statistics about network traffic
use crate::networking::types::my_link_type::MyLinkType;
use std::collections::VecDeque;

use crate::notifications::types::logged_notification::LoggedNotification;

/// Struct containing useful data to display statistics about network traffic and the relative notifications
pub struct RunTimeData {
/// Link type of the current capture (e.g., ethernet)
pub link_type: MyLinkType,
/// Total number of bytes (filtered and not filtered)
pub all_bytes: u128,
/// Total number of packets (filtered and not filtered)
Expand Down Expand Up @@ -41,7 +38,6 @@ impl RunTimeData {
/// Constructs a new `ChartsData` element.
pub fn new() -> Self {
RunTimeData {
link_type: MyLinkType::NotYetAssigned,
all_bytes: 0,
all_packets: 0,
tot_sent_bytes: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/gui/types/sniffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Sniffer {
let filters = self.filters.clone();
let country_mmdb_reader = self.country_mmdb_reader.clone();
let asn_mmdb_reader = self.asn_mmdb_reader.clone();
self.runtime_data.link_type = MyLinkType::from_pcap_link_type(cap.get_datalink());
self.device.link_type = MyLinkType::from_pcap_link_type(cap.get_datalink());
thread::Builder::new()
.name("thread_parse_packets".to_string())
.spawn(move || {
Expand Down Expand Up @@ -409,6 +409,7 @@ impl Sniffer {
name: dev.name,
desc: dev.desc,
addresses: self.device.addresses.clone(),
link_type: MyLinkType::NotYetAssigned,
};
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/networking/types/my_device.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::{Arc, Mutex};

use crate::networking::types::my_link_type::MyLinkType;
use pcap::{Address, Device, DeviceFlags};

/// Represents the current inspected device.
Expand All @@ -10,6 +11,7 @@ pub struct MyDevice {
pub name: String,
pub desc: Option<String>,
pub addresses: Arc<Mutex<Vec<Address>>>,
pub link_type: MyLinkType,
}

impl MyDevice {
Expand Down
Loading

0 comments on commit 6fd1b97

Please sign in to comment.