Skip to content

Commit 100ac1a

Browse files
committed
fix timestamp disalignments
1 parent 711ca92 commit 100ac1a

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/gui/sniffer.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,12 @@ impl Sniffer {
686686
}
687687
}
688688

689-
fn refresh_data(&mut self, msg: InfoTraffic, no_more_packets: bool) {
689+
fn refresh_data(&mut self, mut msg: InfoTraffic, no_more_packets: bool) {
690+
self.info_traffic.refresh(&mut msg);
691+
self.update_thresholds();
692+
if self.info_traffic.tot_data_info.tot_packets() == 0 {
693+
return;
694+
}
690695
self.traffic_chart.update_charts_data(&msg, no_more_packets);
691696
let emitted_notifications = notify_and_log(
692697
&mut self.logged_notifications,
@@ -695,11 +700,7 @@ impl Sniffer {
695700
&self.favorite_hosts,
696701
&self.capture_source,
697702
);
698-
self.info_traffic.refresh(msg);
699-
self.update_thresholds();
700-
if self.info_traffic.tot_data_info.tot_packets() == 0 {
701-
return;
702-
}
703+
703704
if self.thumbnail || self.running_page.ne(&RunningPage::Notifications) {
704705
self.unread_notifications += emitted_notifications;
705706
}

src/networking/types/info_traffic.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct InfoTraffic {
3030
}
3131

3232
impl InfoTraffic {
33-
pub fn refresh(&mut self, msg: InfoTraffic) {
33+
pub fn refresh(&mut self, msg: &mut InfoTraffic) {
3434
self.tot_data_info.refresh(msg.tot_data_info);
3535

3636
self.all_packets += msg.all_packets;
@@ -39,30 +39,29 @@ impl InfoTraffic {
3939

4040
// it can happen they're equal due to dis-alignments in the PCAP timestamp
4141
if self.last_packet_timestamp.secs() == msg.last_packet_timestamp.secs() {
42-
self.last_packet_timestamp.add_secs(1);
43-
} else {
44-
self.last_packet_timestamp = msg.last_packet_timestamp;
42+
msg.last_packet_timestamp.add_secs(1);
4543
}
44+
self.last_packet_timestamp = msg.last_packet_timestamp;
4645

47-
for (key, value) in msg.map {
46+
for (key, value) in &msg.map {
4847
self.map
49-
.entry(key)
50-
.and_modify(|x| x.refresh(&value))
51-
.or_insert(value);
48+
.entry(*key)
49+
.and_modify(|x| x.refresh(value))
50+
.or_insert_with(|| value.clone());
5251
}
5352

54-
for (key, value) in msg.services {
53+
for (key, value) in &msg.services {
5554
self.services
56-
.entry(key)
57-
.and_modify(|x| x.refresh(value))
58-
.or_insert(value);
55+
.entry(*key)
56+
.and_modify(|x| x.refresh(*value))
57+
.or_insert(*value);
5958
}
6059

61-
for (key, value) in msg.hosts {
60+
for (key, value) in &msg.hosts {
6261
self.hosts
63-
.entry(key)
64-
.and_modify(|x| x.refresh(&value))
65-
.or_insert(value);
62+
.entry(key.clone())
63+
.and_modify(|x| x.refresh(value))
64+
.or_insert(*value);
6665
}
6766
}
6867

0 commit comments

Comments
 (0)