pub struct ConnectionTracker { /* private fields */ }Expand description
A live, lifecycle-managed table of network connections built from parsed packets. See the module docs for the intended usage.
Implementations§
Source§impl ConnectionTracker
impl ConnectionTracker
Sourcepub fn ingest_at(&self, parsed: &ParsedPacket, now: SystemTime) -> IngestOutcome
pub fn ingest_at(&self, parsed: &ParsedPacket, now: SystemTime) -> IngestOutcome
Fold a parsed packet into the connection table, creating or updating the
matching connection, stamping the update with the supplied now.
Pass the packet’s own capture timestamp: for offline processing (pcap
replay, tests) this keeps created_at/last_activity and the
cleanup timeout sweep on trace time rather than the
replay wall clock. Live callers should also pass each packet’s own
capture timestamp, not one clock read shared across a batch of packets.
Handshake RTT is the difference between two packets’ now values, so a
shared timestamp collapses every round trip that completes within one
batch to zero.
Sourcepub fn cleanup(&self, now: SystemTime) -> Vec<Connection>
pub fn cleanup(&self, now: SystemTime) -> Vec<Connection>
Remove connections whose protocol-aware timeout has elapsed as of now.
Removed connections are archived into the historic table (when
keep_historic is set, subject to max_historic eviction) and their
QUIC
mappings are dropped. Returns the removed connections (in their original,
pre-archive form) so callers can emit close events or export them.
Sourcepub fn snapshot(&self) -> Vec<Connection>
pub fn snapshot(&self) -> Vec<Connection>
A point-in-time copy of the active connections.
Note: this is a full clone, including each connection’s rate-sample
buffer — the buffer is shared via Arc, so the next per-packet
update on a live connection pays a copy-on-write deep copy. Callers
that only need the cached current_*_rate_bps fields (any read-only
view) should prefer Connection::snapshot_clone over the entries of
connections to keep the packet path allocation-
free.
Sourcepub fn with_retained_sources<R>(
&self,
inspect: impl FnOnce(&ConnectionMap, &HistoricMap) -> R,
) -> R
pub fn with_retained_sources<R>( &self, inspect: impl FnOnce(&ConnectionMap, &HistoricMap) -> R, ) -> R
Inspect the active and historic maps as one consistent retained view.
Cleanup cannot move a connection between the maps while inspect is
running. Packet updates may still update active rows through DashMap’s
per-entry locking.
Sourcepub fn historic_len(&self) -> usize
pub fn historic_len(&self) -> usize
Number of historic (recently-closed) connections.
Sourcepub fn clear(&self)
pub fn clear(&self)
Drop all active and historic connections and reset RTT/QUIC state and the learned-neighbor cache.
Sourcepub fn connections(&self) -> &ConnectionMap
pub fn connections(&self) -> &ConnectionMap
Direct access to the active connection table.
Use this for in-place enrichment (e.g. attaching process, DNS, or GeoIP
information via iter_mut) or custom reads. Lifecycle changes should go
through ingest_at and cleanup so the
connection-count limit, RTT, and QUIC coalescing stay consistent —
inserting or removing entries directly desyncs the internal counter
backing the max_connections check.
Sourcepub fn historic(&self) -> &HistoricMap
pub fn historic(&self) -> &HistoricMap
Direct access to the historic (recently-closed) connection table.
Sourcepub fn neighbor(&self, ip: &IpAddr) -> Option<NeighborEntry>
pub fn neighbor(&self, ip: &IpAddr) -> Option<NeighborEntry>
The ARP/NDP-learned MAC/vendor mapping for ip, if one has been
observed.
Sourcepub fn take_average_rtt(&self, window_secs: u64) -> Option<f64>
pub fn take_average_rtt(&self, window_secs: u64) -> Option<f64>
Average network RTT (in milliseconds) over the last window_secs
seconds of handshake, TCP data, and ICMP echo samples. None if no
samples are available.