diff options
author | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-10-12 20:43:14 +0800 |
---|---|---|
committer | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-10-12 20:43:14 +0800 |
commit | b82383dc587f505367828affc8bcd033a70cb4d5 (patch) | |
tree | 264f4bc24a9e8d6969fff17780aed2cb37f25111 /src | |
parent | 76956cfadefcebb7ae4ab136a6e727e2eee33d9e (diff) |
Set known orphan connections max size
Diffstat (limited to 'src')
-rw-r--r-- | src/display/ui_state.rs | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs index 179cba2..55d0f09 100644 --- a/src/display/ui_state.rs +++ b/src/display/ui_state.rs @@ -89,7 +89,7 @@ pub struct UIState { pub remote_addresses_map: HashMap<IpAddr, NetworkData>, pub connections_map: HashMap<Connection, ConnectionData>, /// Used for reducing logging noise. - known_orphan_sockets: RefCell<HashSet<LocalSocket>>, + known_orphan_sockets: RefCell<VecDeque<LocalSocket>>, } impl UIState { @@ -126,21 +126,29 @@ impl UIState { }) }); - // only log each orphan connection once - if name.is_none() && self.known_orphan_sockets.borrow_mut().insert(*local_socket) { - match connections_to_procs - .iter() - .find(|(&LocalSocket { port, protocol, .. }, _)| { - port == local_socket.port && protocol == local_socket.protocol - }) { - Some((lookalike, name)) => { - warn!( - r#""{name}" owns a similar looking connection, but its local ip doesn't match."# - ); - warn!("Looking for: {local_socket}; found: {lookalike}"); - } - None => warn!("Cannot determine which process owns {local_socket}."), - }; + if name.is_none() { + let mut orphans = self.known_orphan_sockets.borrow_mut(); + // only log each orphan connection once + if !orphans.contains(local_socket) { + // newer connections go in the front so that searches are faster + // basically recency bias + orphans.push_front(*local_socket); + orphans.truncate(10_000); // arbitrary maximum backlog + + match connections_to_procs.iter().find( + |(&LocalSocket { port, protocol, .. }, _)| { + port == local_socket.port && protocol == local_socket.protocol + }, + ) { + Some((lookalike, name)) => { + warn!( + r#""{name}" owns a similar looking connection, but its local ip doesn't match."# + ); + warn!("Looking for: {local_socket}; found: {lookalike}"); + } + None => warn!("Cannot determine which process owns {local_socket}."), + }; + } } name |