pub struct FlowTracker<E: FlowExtractor, S = ()> { /* private fields */ }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>
impl<E: FlowExtractor, S: Send + 'static> FlowTracker<E, S>
Sourcepub fn with_state<F>(extractor: E, init: F) -> Self
pub fn with_state<F>(extractor: E, init: F) -> Self
Construct with a custom per-flow state initializer. The closure is called once on first sight of each new flow.
Sourcepub fn with_config_and_state<F>(
extractor: E,
config: FlowTrackerConfig,
init: F,
) -> Self
pub fn with_config_and_state<F>( extractor: E, config: FlowTrackerConfig, init: F, ) -> Self
Same as with_state but with explicit config.
Sourcepub fn track(&mut self, view: PacketView<'_>) -> FlowEvents<E::Key>
pub fn track(&mut self, view: PacketView<'_>) -> FlowEvents<E::Key>
Process a packet. Returns 0–3 events.
Sourcepub fn extractor(&self) -> &E
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).
Sourcepub fn track_with_payload<F>(
&mut self,
view: PacketView<'_>,
payload_cb: F,
) -> FlowEvents<E::Key>
pub fn track_with_payload<F>( &mut self, view: PacketView<'_>, payload_cb: F, ) -> FlowEvents<E::Key>
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).
Sourcepub fn manual_tick(&mut self, now: Timestamp) -> Vec<FlowEvent<E::Key>>
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.
Sourcepub fn sweep(&mut self, now: Timestamp) -> Vec<FlowEvent<E::Key>>
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).
Sourcepub fn get(&self, key: &E::Key) -> Option<&FlowEntry<S>>
pub fn get(&self, key: &E::Key) -> Option<&FlowEntry<S>>
Peek at a flow’s entry without affecting LRU order.
Sourcepub fn get_mut(&mut self, key: &E::Key) -> Option<&mut FlowEntry<S>>
pub fn get_mut(&mut self, key: &E::Key) -> Option<&mut FlowEntry<S>>
Borrow a flow’s entry mutably (does NOT touch LRU order).
Sourcepub fn flows(&self) -> impl Iterator<Item = (&E::Key, &FlowEntry<S>)>
pub fn flows(&self) -> impl Iterator<Item = (&E::Key, &FlowEntry<S>)>
Iterate over all live flows in LRU order (most-recent first).
Sourcepub fn flow_count(&self) -> usize
pub fn flow_count(&self) -> usize
Number of live flows currently being tracked.
Sourcepub fn stats(&self) -> &FlowTrackerStats
pub fn stats(&self) -> &FlowTrackerStats
Tracker stats (cumulative since construction).
Sourcepub fn config(&self) -> &FlowTrackerConfig
pub fn config(&self) -> &FlowTrackerConfig
Tracker config.
Sourcepub fn set_config(&mut self, config: FlowTrackerConfig)
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).
Sourcepub fn into_extractor(self) -> E
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>
impl<E: FlowExtractor, S: Default + Send + 'static> FlowTracker<E, S>
Sourcepub fn new(extractor: E) -> Self
pub fn new(extractor: E) -> Self
Construct with default config and S::default() as the
initializer.
Sourcepub fn with_config(extractor: E, config: FlowTrackerConfig) -> Self
pub fn with_config(extractor: E, config: FlowTrackerConfig) -> Self
Same with explicit config.