Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All Sniffnet releases with the relative changes are documented in this file.
## [UNRELEASED]
- Import PCAP files ([#795](https://github.com/GyulyVGC/sniffnet/pull/795) — fixes [#283](https://github.com/GyulyVGC/sniffnet/issues/283))
- Donut chart reporting overall traffic statistics ([#756](https://github.com/GyulyVGC/sniffnet/pull/756) — fixes [#687](https://github.com/GyulyVGC/sniffnet/issues/687))
- Notifications: more details and other improvements ([#830](https://github.com/GyulyVGC/sniffnet/pull/830) — fixes [#637](https://github.com/GyulyVGC/sniffnet/issues/637))
- Added support for ARP protocol ([#759](https://github.com/GyulyVGC/sniffnet/pull/759) — fixes [#680](https://github.com/GyulyVGC/sniffnet/issues/680))
- Identify and tag unassigned/reserved "bogon" IP addresses ([#678](https://github.com/GyulyVGC/sniffnet/pull/678) — fixes [#209](https://github.com/GyulyVGC/sniffnet/issues/209))
- Show data agglomerates in _Inspect_ page table ([#684](https://github.com/GyulyVGC/sniffnet/pull/684) — fixes [#601](https://github.com/GyulyVGC/sniffnet/issues/601))
Expand Down
Binary file modified resources/fonts/subset/icons.ttf
Binary file not shown.
48 changes: 12 additions & 36 deletions src/chart/manage_chart_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@ use crate::TrafficChart;
use crate::networking::types::info_traffic::InfoTraffic;

impl TrafficChart {
pub fn update_charts_data(&mut self, info_traffic: &InfoTraffic, no_more_packets: bool) {
pub fn update_charts_data(&mut self, info_traffic_msg: &InfoTraffic, no_more_packets: bool) {
self.no_more_packets = no_more_packets;

if self.ticks == 0 {
self.first_packet_timestamp = info_traffic.last_packet_timestamp;
self.first_packet_timestamp = info_traffic_msg.last_packet_timestamp;
}

#[allow(clippy::cast_precision_loss)]
let tot_seconds = self.ticks as f32;
self.ticks += 1;

#[allow(clippy::cast_precision_loss)]
let out_bytes_entry =
-1.0 * (info_traffic.tot_out_bytes - info_traffic.tot_out_bytes_prev) as f32;
let out_bytes_entry = -1.0 * info_traffic_msg.tot_data_info.outgoing_bytes() as f32;
#[allow(clippy::cast_precision_loss)]
let in_bytes_entry = (info_traffic.tot_in_bytes - info_traffic.tot_in_bytes_prev) as f32;
let in_bytes_entry = info_traffic_msg.tot_data_info.incoming_bytes() as f32;
#[allow(clippy::cast_precision_loss)]
let out_packets_entry =
-1.0 * (info_traffic.tot_out_packets - info_traffic.tot_out_packets_prev) as f32;
let out_packets_entry = -1.0 * info_traffic_msg.tot_data_info.outgoing_packets() as f32;
#[allow(clippy::cast_precision_loss)]
let in_packets_entry =
(info_traffic.tot_in_packets - info_traffic.tot_in_packets_prev) as f32;
let in_packets_entry = info_traffic_msg.tot_data_info.incoming_packets() as f32;

let out_bytes_point = (tot_seconds, out_bytes_entry);
let in_bytes_point = (tot_seconds, in_bytes_entry);
Expand Down Expand Up @@ -163,6 +160,7 @@ mod tests {
use splines::{Interpolation, Key, Spline};

use crate::chart::manage_chart_data::{ChartSeries, get_max, get_min};
use crate::networking::types::data_info::DataInfo;
use crate::utils::types::timestamp::Timestamp;
use crate::{ChartType, InfoTraffic, Language, StyleType, TrafficChart};

Expand Down Expand Up @@ -248,8 +246,7 @@ mod tests {
spline: received_spl,
all_time: vec![],
};
let tot_sent = 1000 * 28 + 500;
let tot_received = 21000 * 28 + 1000;
let tot_data_info = DataInfo::new_for_tests(4444, 3333, 2222, 1111);
let mut traffic_chart = TrafficChart {
ticks: 29,
out_bytes: sent.clone(),
Expand All @@ -271,15 +268,8 @@ mod tests {
let mut info_traffic = InfoTraffic {
all_bytes: 0,
all_packets: 0,
tot_out_bytes: tot_sent + 1111,
tot_in_bytes: tot_received + 2222,
tot_out_packets: tot_sent + 3333,
tot_in_packets: tot_received + 4444,
tot_data_info,
dropped_packets: 0,
tot_out_bytes_prev: tot_sent,
tot_in_bytes_prev: tot_received,
tot_out_packets_prev: tot_sent,
tot_in_packets_prev: tot_received,
..Default::default()
};

Expand All @@ -291,12 +281,6 @@ mod tests {
assert_eq!(get_min(&traffic_chart.out_packets), -3333.0);
assert_eq!(get_max(&traffic_chart.in_bytes), 21000.0);

// prev values aren't updated here anymore: manually set them
info_traffic.tot_out_bytes_prev = info_traffic.tot_out_bytes;
info_traffic.tot_in_bytes_prev = info_traffic.tot_in_bytes;
info_traffic.tot_out_packets_prev = info_traffic.tot_out_packets;
info_traffic.tot_in_packets_prev = info_traffic.tot_in_packets;

let mut sent_bytes = sent.clone();
sent_bytes
.spline
Expand Down Expand Up @@ -337,17 +321,9 @@ mod tests {
received_bytes.spline.keys()
);

info_traffic.tot_out_bytes += 99;
info_traffic.tot_in_packets += 990;
info_traffic.tot_in_bytes += 2;
info_traffic.tot_data_info = DataInfo::new_for_tests(990, 1, 2, 99);
traffic_chart.update_charts_data(&info_traffic, false);
info_traffic.tot_out_bytes_prev = info_traffic.tot_out_bytes;
info_traffic.tot_in_bytes_prev = info_traffic.tot_in_bytes;
info_traffic.tot_out_packets_prev = info_traffic.tot_out_packets;
info_traffic.tot_in_packets_prev = info_traffic.tot_in_packets;
info_traffic.tot_out_bytes += 77;
info_traffic.tot_in_packets += 1;
info_traffic.tot_out_packets += 220;
info_traffic.tot_data_info = DataInfo::new_for_tests(1, 220, 0, 77);
traffic_chart.update_charts_data(&info_traffic, false);

sent_bytes.spline.remove(0);
Expand All @@ -370,7 +346,7 @@ mod tests {
sent_packets.spline.remove(0);
sent_packets
.spline
.add(Key::new(30.0, 0.0, Interpolation::Cosine));
.add(Key::new(30.0, -1.0, Interpolation::Cosine));
sent_packets
.spline
.add(Key::new(31.0, -220.0, Interpolation::Cosine));
Expand Down
3 changes: 2 additions & 1 deletion src/chart/types/chart_type.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::Language;
use crate::translations::translations::{bytes_translation, packets_translation};
use serde::{Deserialize, Serialize};

/// Enum representing the possible kind of chart displayed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ChartType {
Packets,
Bytes,
Expand Down
3 changes: 1 addition & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mod tests {
),
notifications: Notifications {
volume: 100,
packets_notification: Default::default(),
bytes_notification: Default::default(),
data_notification: Default::default(),
favorite_notification: Default::default(),
},
style: StyleType::Custom(ExtraStyles::DraculaDark),
Expand Down
19 changes: 10 additions & 9 deletions src/countries/country_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use crate::countries::flags_pictures::{
AD, AE, AF, AG, AI, AL, AM, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI,
BJ, BM, BN, BO, BOGON, BR, BROADCAST, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK,
CL, CM, CN, CO, COMPUTER, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH,
ER, ES, ET, FI, FJ, FK, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA, GB, GD, GE, GG, GH,
GI, GL, GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID, IE, IL, IM, IN, IO,
IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK,
LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR, MS, MT, MU,
MULTICAST, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF,
PG, PH, PK, PL, PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SK,
SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TR, TT,
TV, TW, TZ, UA, UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA, ZM, ZW,
ER, ES, ET, FI, FJ, FK, FLAGS_HEIGHT_BIG, FLAGS_WIDTH_BIG, FLAGS_WIDTH_SMALL, FM, FO, FR, GA,
GB, GD, GE, GG, GH, GI, GL, GM, GN, GQ, GR, GS, GT, GU, GW, GY, HK, HN, HOME, HR, HT, HU, ID,
IE, IL, IM, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ,
LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MG, MH, MK, ML, MM, MN, MO, MP, MR,
MS, MT, MU, MULTICAST, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM,
PA, PE, PF, PG, PH, PK, PL, PN, PR, PS, PT, PW, PY, QA, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG,
SH, SI, SK, SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN,
TO, TR, TT, TV, TW, TZ, UA, UG, UNKNOWN, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WS, YE, ZA,
ZM, ZW,
};
use crate::countries::types::country::Country;
use crate::gui::styles::container::ContainerType;
Expand Down Expand Up @@ -384,7 +385,7 @@ pub fn get_computer_tooltip<'a>(
)))
.class(SvgType::AdaptColor)
.width(FLAGS_WIDTH_BIG)
.height(FLAGS_WIDTH_BIG * 0.75);
.height(FLAGS_HEIGHT_BIG);

let tooltip = match (is_my_address, is_local, is_bogon, traffic_type) {
(true, _, _, _) => your_network_adapter_translation(language).to_string(),
Expand Down
2 changes: 2 additions & 0 deletions src/countries/flags_pictures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub const FLAGS_WIDTH_SMALL: f32 = 20.0;
pub const FLAGS_WIDTH_BIG: f32 = 37.5;

pub const FLAGS_HEIGHT_BIG: f32 = FLAGS_WIDTH_BIG * 3.0 / 4.0;

pub const AD: &[u8] = include_bytes!("../../resources/countries_flags/4x3/ad.svg");
pub const AE: &[u8] = include_bytes!("../../resources/countries_flags/4x3/ae.svg");
pub const AF: &[u8] = include_bytes!("../../resources/countries_flags/4x3/af.svg");
Expand Down
2 changes: 1 addition & 1 deletion src/gui/pages/inspect_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ fn get_agglomerates_row<'a>(
let tot_bytes = tot.tot_bytes();

let (in_length, out_length) = get_bars_length(chart_type, &tot, &tot);
let bars = get_bars(in_length, out_length);
let bars = get_bars(in_length, out_length).width(ReportCol::FILTER_COLUMNS_WIDTH);

let bytes_col = Column::new()
.align_x(Alignment::Center)
Expand Down
Loading