Skip to main content

FlowTracker

Struct FlowTracker 

Source
pub struct FlowTracker<E: FlowExtractor, S = ()> { /* private fields */ }
Available on crate feature tracker only.
Expand description

Bidirectional flow tracker, generic over an extractor E and optional per-flow user state S.

Implementations§

Source§

impl<E: FlowExtractor, S: Send + 'static> FlowTracker<E, S>

Source

pub fn with_state<F>(extractor: E, init: F) -> Self
where F: FnMut(&E::Key) -> S + Send + 'static,

Construct with a custom per-flow state initializer. The closure is called once on first sight of each new flow.

Source

pub fn with_config_and_state<F>( extractor: E, config: FlowTrackerConfig, init: F, ) -> Self
where F: FnMut(&E::Key) -> S + Send + 'static,

Same as with_state but with explicit config.

Source

pub fn track(&mut self, view: PacketView<'_>) -> FlowEvents<E::Key>

Process a packet. Returns 0–3 events.

Source

pub fn extractor(&self) -> &E

Borrow the inner extractor (for callers that want to extract a key without driving the tracker, e.g. external dispatch).

Source

pub fn track_with_payload<F>( &mut self, view: PacketView<'_>, payload_cb: F, ) -> FlowEvents<E::Key>
where F: FnMut(&E::Key, FlowSide, u32, &[u8]),

Process a packet, calling payload_cb(&key, side, seq, payload) for each TCP packet with a non-empty payload before any events are returned. Lets sync reassemblers (or any per-segment dispatch) run inline without a second extract pass.

payload_cb is called at most once per packet (TCP only).

Source

pub fn manual_tick(&mut self, now: Timestamp) -> Vec<FlowEvent<E::Key>>

Alias for Self::sweep. Exists for tests and docs that prefer a name not implying background-thread machinery.

Source

pub fn sweep(&mut self, now: Timestamp) -> Vec<FlowEvent<E::Key>>

Run the idle-timeout sweep. Returns events for flows that ended due to timeout. Call periodically (e.g., from a tokio Interval).

Source

pub fn get(&self, key: &E::Key) -> Option<&FlowEntry<S>>

Peek at a flow’s entry without affecting LRU order.

Source

pub fn get_mut(&mut self, key: &E::Key) -> Option<&mut FlowEntry<S>>

Borrow a flow’s entry mutably (does NOT touch LRU order).

Source

pub fn flows(&self) -> impl Iterator<Item = (&E::Key, &FlowEntry<S>)>

Iterate over all live flows in LRU order (most-recent first).

Source

pub fn flow_count(&self) -> usize

Number of live flows currently being tracked.

Source

pub fn stats(&self) -> &FlowTrackerStats

Tracker stats (cumulative since construction).

Source

pub fn config(&self) -> &FlowTrackerConfig

Tracker config.

Source

pub fn set_config(&mut self, config: FlowTrackerConfig)

Replace the config in-place. Resizes the LRU capacity if max_flows changed (excess flows are dropped — no events emitted for them).

Source

pub fn into_extractor(self) -> E

Consume the tracker and return the inner extractor. Used by builder code that needs to rebuild the tracker (e.g. FlowStream::with_state re-creates the tracker with a new state-init closure).

Source§

impl<E: FlowExtractor, S: Default + Send + 'static> FlowTracker<E, S>

Source

pub fn new(extractor: E) -> Self

Construct with default config and S::default() as the initializer.

Source

pub fn with_config(extractor: E, config: FlowTrackerConfig) -> Self

Same with explicit config.

Auto Trait Implementations§

§

impl<E, S> Freeze for FlowTracker<E, S>
where E: Freeze,

§

impl<E, S = ()> !RefUnwindSafe for FlowTracker<E, S>

§

impl<E, S> Send for FlowTracker<E, S>
where S: Send,

§

impl<E, S = ()> !Sync for FlowTracker<E, S>

§

impl<E, S> Unpin for FlowTracker<E, S>
where E: Unpin,

§

impl<E, S> UnsafeUnpin for FlowTracker<E, S>
where E: UnsafeUnpin,

§

impl<E, S = ()> !UnwindSafe for FlowTracker<E, S>

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