Skip to content

Commit ad5a7d6

Browse files
committed
improve HostMessage ergonomics
1 parent fe1d527 commit ad5a7d6

3 files changed

Lines changed: 14 additions & 32 deletions

File tree

src/gui/sniffer.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::mmdb::types::mmdb_reader::{MmdbReader, MmdbReaders};
4646
use crate::networking::parse_packets::BackendTrafficMessage;
4747
use crate::networking::parse_packets::parse_packets;
4848
use crate::networking::types::capture_context::{CaptureContext, CaptureSource, MyPcapImport};
49-
use crate::networking::types::data_info_host::DataInfoHost;
5049
use crate::networking::types::filters::Filters;
5150
use crate::networking::types::host::{Host, HostMessage};
5251
use crate::networking::types::host_data_states::HostDataStates;
@@ -1100,33 +1099,16 @@ impl Sniffer {
11001099
fn handle_new_host(&mut self, host_msg: HostMessage) {
11011100
let HostMessage {
11021101
host,
1103-
other_data,
1104-
is_loopback,
1105-
is_local,
1106-
is_bogon,
1107-
traffic_type,
1102+
data_info_host,
11081103
address_to_lookup,
11091104
rdns,
11101105
} = host_msg;
11111106

1112-
let data_info_host = DataInfoHost {
1113-
data_info: other_data,
1114-
is_favorite: false,
1115-
is_loopback,
1116-
is_local,
1117-
is_bogon,
1118-
traffic_type,
1119-
};
1120-
11211107
self.info_traffic
11221108
.hosts
11231109
.entry(host.clone())
1124-
.and_modify(|data_info_host| {
1125-
data_info_host.data_info.refresh(other_data);
1126-
data_info_host.is_loopback = is_loopback;
1127-
data_info_host.is_local = is_local;
1128-
data_info_host.is_bogon = is_bogon;
1129-
data_info_host.traffic_type = traffic_type;
1110+
.and_modify(|d| {
1111+
d.refresh(&data_info_host);
11301112
})
11311113
.or_insert(data_info_host);
11321114

src/networking/parse_packets.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,18 @@ fn reverse_dns_lookup(
388388
.insert(address_to_lookup, new_host.clone());
389389
drop(resolutions_lock);
390390

391-
let msg_data = HostMessage {
392-
host: new_host,
393-
other_data,
394-
is_loopback,
391+
let data_info_host = DataInfoHost {
392+
data_info: other_data,
393+
is_favorite: false,
395394
is_local,
396395
is_bogon,
396+
is_loopback,
397397
traffic_type,
398+
};
399+
400+
let msg_data = HostMessage {
401+
host: new_host,
402+
data_info_host,
398403
address_to_lookup,
399404
rdns,
400405
};

src/networking/types/host.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::countries::types::country::Country;
22
use crate::networking::types::asn::Asn;
3-
use crate::networking::types::data_info::DataInfo;
4-
use crate::networking::types::traffic_type::TrafficType;
3+
use crate::networking::types::data_info_host::DataInfoHost;
54
use std::net::IpAddr;
65

76
/// Struct to represent a network host
@@ -30,11 +29,7 @@ pub struct ThumbnailHost {
3029
#[derive(Clone, Debug)]
3130
pub struct HostMessage {
3231
pub host: Host,
33-
pub other_data: DataInfo,
34-
pub is_loopback: bool,
35-
pub is_local: bool,
36-
pub is_bogon: Option<&'static str>,
37-
pub traffic_type: TrafficType,
32+
pub data_info_host: DataInfoHost,
3833
pub address_to_lookup: IpAddr,
3934
pub rdns: String,
4035
}

0 commit comments

Comments
 (0)