Expand description
Live connection tracking.
ConnectionTracker folds parsed packets into a long-lived, lifecycle-
managed table of Connections. It owns everything needed to turn a stream
of ParsedPackets into the same connection view the rustnet TUI shows:
the active table, an archive of recently-closed (“historic”) connections,
RTT estimation from TCP, QUIC handshakes, and ICMP echo, plus DNS-shaped
response timing, QUIC connection-ID coalescing, and timeout-based cleanup,
all without any UI, capture, or process-lookup
dependency.
This is the piece that makes headless tools easy: pair a capture source with
a parser, then feed each parsed packet to ConnectionTracker::ingest_at
and periodically call ConnectionTracker::cleanup. A Prometheus exporter,
a pcap post-processor, or a test harness can all reuse the exact connection
semantics of the main application. Offline consumers replaying a saved trace
should pass each packet’s capture timestamp so connection lifetimes and
timeouts follow trace time rather than the replay wall clock.
use rustnet_core::network::parser::PacketParser;
use rustnet_core::network::tracker::ConnectionTracker;
use std::time::SystemTime;
let parser = PacketParser::new();
let tracker = ConnectionTracker::new();
for frame in frames {
if let Some(parsed) = parser.parse_packet(&frame) {
tracker.ingest_at(&parsed, SystemTime::now());
}
}
tracker.cleanup(SystemTime::now()); // expire idle/closed connections
for entry in tracker.connections().iter() {
let conn = entry.value();
println!("{} {} -> {}", conn.protocol, conn.local_addr, conn.remote_addr);
}All methods take &self (the internal tables use interior mutability), so a
single tracker can be wrapped in an std::sync::Arc and shared across a
capture thread, a cleanup thread, and a reader thread.
Structs§
- Connection
Tracker - A live, lifecycle-managed table of network connections built from parsed packets. See the module docs for the intended usage.
- Historic
Key - Identity of an archived (closed) connection: the flow key plus the
connection’s creation time, so multiple closed connections that reused the
same 4-tuple don’t clobber each other. (Replaces the former
"<key>:<created_at_nanos>"string suffix.) - Ingest
Outcome - What happened when a packet was ingested via
ingest_at. - Tracker
Config - Tuning knobs for a
ConnectionTracker.
Type Aliases§
- Connection
Map - The active connection table: flow key -> connection.
- Historic
Map - The historic (recently-closed) connection table.