Skip to main content

ConnectionTracker

Struct ConnectionTracker 

Source
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

Source

pub fn new() -> Self

Create a tracker with default configuration.

Source

pub fn with_config(config: TrackerConfig) -> Self

Create a tracker with custom TrackerConfig.

Source

pub fn ingest(&self, parsed: &ParsedPacket) -> IngestOutcome

Fold a parsed packet into the connection table, creating or updating the matching connection, timestamping the update with the current wall clock.

This is the right call for live capture. Offline consumers replaying a pcap should use ingest_at and pass the packet’s own capture time so connection lifetimes and cleanup timeouts reflect the trace rather than the replay wall clock.

Source

pub fn ingest_at(&self, parsed: &ParsedPacket, now: SystemTime) -> IngestOutcome

Like ingest, but stamps the connection update with the supplied now instead of the wall clock.

Use this for deterministic offline processing (pcap replay, tests): pass the packet’s capture timestamp so created_at/last_activity and the cleanup timeout sweep operate on trace time, not real time.

Source

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.

Source

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.

Source

pub fn historic_snapshot(&self) -> Vec<Connection>

A point-in-time copy of the historic (recently-closed) connections.

Source

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.

Source

pub fn len(&self) -> usize

Number of active connections.

Source

pub fn is_empty(&self) -> bool

true if there are no active connections.

Source

pub fn historic_len(&self) -> usize

Number of historic (recently-closed) connections.

Source

pub fn clear(&self)

Drop all active and historic connections and reset RTT/QUIC state.

Source

pub fn config(&self) -> &TrackerConfig

The tracker’s configuration.

Source

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 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.

Source

pub fn historic(&self) -> &HistoricMap

Direct access to the historic (recently-closed) connection table.

Source

pub fn take_average_rtt(&self, window_secs: u64) -> Option<f64>

Average RTT (in milliseconds) over the last window_secs seconds of SYN/SYN-ACK samples, consuming the samples in that window. None if no samples are available.

Trait Implementations§

Source§

impl Default for ConnectionTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.