Skip to content

Commit

Permalink
use Display instead of print_gui for inspect table entries
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Dec 2, 2023
1 parent f26e7d7 commit 0441c28
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 53 deletions.
10 changes: 3 additions & 7 deletions src/gui/pages/inspect_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,9 @@ fn lazy_report(sniffer: &Sniffer) -> Container<'static, Message, Renderer<StyleT
let entry_row = Row::new()
.align_items(Alignment::Center)
.push(
Text::new(format!(
" {}{} ",
report_entry.key.print_gui(),
report_entry.val.print_gui()
))
.style(entry_text_type)
.font(font),
Text::new(format!(" {}{} ", report_entry.key, report_entry.val))
.style(entry_text_type)
.font(font),
)
.push(report_entry.tooltip)
.push(Text::new(" "));
Expand Down
6 changes: 2 additions & 4 deletions src/networking/manage_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ pub fn modify_or_insert_in_map(
) -> InfoAddressPortPair {
let now = Local::now();
let mut traffic_direction = TrafficDirection::default();
let source_ip = &key.address1;
let destination_ip = &key.address2;
let very_long_address = source_ip.len() > 25 || destination_ip.len() > 25;

if !info_traffic_mutex.lock().unwrap().map.contains_key(key) {
// first occurrence of key
Expand All @@ -188,6 +185,8 @@ pub fn modify_or_insert_in_map(
}
}
// determine traffic direction
let source_ip = &key.address1;
let destination_ip = &key.address2;
traffic_direction =
get_traffic_direction(source_ip, destination_ip, &my_interface_addresses);
};
Expand All @@ -212,7 +211,6 @@ pub fn modify_or_insert_in_map(
initial_timestamp: now,
final_timestamp: now,
app_protocol: application_protocol,
very_long_address,
traffic_direction,
})
.clone();
Expand Down
8 changes: 2 additions & 6 deletions src/networking/types/address_port_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,20 @@ impl AddressPortPair {
trans_protocol,
}
}

pub fn print_gui(&self) -> String {
self.to_string().replace('|', "")
}
}

impl fmt::Display for AddressPortPair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.address1.len() > 25 || self.address2.len() > 25 {
write!(
f,
"|{:^45}|{:>8} |{:^45}|{:>8} | {} |",
"{:^45}{:>8} {:^45}{:>8} {} ",
self.address1, self.port1, self.address2, self.port2, self.trans_protocol
)
} else {
write!(
f,
"|{:^25}|{:>8} |{:^25}|{:>8} | {} |",
"{:^25}{:>8} {:^25}{:>8} {} ",
self.address1, self.port1, self.address2, self.port2, self.trans_protocol
)
}
Expand Down
42 changes: 6 additions & 36 deletions src/networking/types/info_address_port_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ pub struct InfoAddressPortPair {
pub initial_timestamp: DateTime<Local>,
/// Last occurrence of information exchange featuring the associate address:port pair as a source or destination.
pub final_timestamp: DateTime<Local>,
/// Set of application layer protocols carried by the associated address:port pair.
/// Application layer protocol carried by the associated address:port pair.
pub app_protocol: AppProtocol,
/// Check if source or destination is an IPv6 address longer than 25 bytes (used for layout)
pub very_long_address: bool,
/// Determines if the connection is incoming or outgoing
pub traffic_direction: TrafficDirection,
}
Expand All @@ -44,22 +42,11 @@ impl Default for InfoAddressPortPair {
initial_timestamp: DateTime::default(),
final_timestamp: DateTime::default(),
app_protocol: AppProtocol::Other,
very_long_address: false,
traffic_direction: TrafficDirection::default(),
}
}
}

impl InfoAddressPortPair {
pub fn print_gui(&self) -> String {
self.to_string()
.get(0..35)
.unwrap()
.to_string()
.replace('|', "")
}
}

impl fmt::Display for InfoAddressPortPair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let bytes_string = get_formatted_bytes_string(self.transmitted_bytes);
Expand All @@ -69,27 +56,10 @@ impl fmt::Display for InfoAddressPortPair {
_ => self.app_protocol.to_string(),
};

if self.very_long_address {
write!(
f,
"{:^9}|{:>10} |{:>9} | {} | {} |",
app_string,
self.transmitted_packets,
bytes_string,
self.initial_timestamp.to_string().get(0..19).unwrap(),
self.final_timestamp.to_string().get(0..19).unwrap()
)
} else {
write!(
f,
"{:^9}|{:>10} |{:>9} | {} | {} |{}",
app_string,
self.transmitted_packets,
bytes_string,
self.initial_timestamp.to_string().get(0..19).unwrap(),
self.final_timestamp.to_string().get(0..19).unwrap(),
" ".repeat(40)
)
}
write!(
f,
"{:^9}{:>10} {:>9} ",
app_string, self.transmitted_packets, bytes_string,
)
}
}

0 comments on commit 0441c28

Please sign in to comment.