Skip to main content

FlowDriver

Struct FlowDriver 

Source
pub struct FlowDriver<E, F, S = ()>
where E: FlowExtractor, F: ReassemblerFactory<E::Key>, S: Send + 'static,
{ /* private fields */ }
Available on crate feature reassembler only.

Implementations§

Source§

impl<E, F> FlowDriver<E, F, ()>

Source

pub fn new(extractor: E, factory: F) -> Self

Construct with default config and S = () (no per-flow user state). Annotation-free.

Source

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

Construct with explicit config and S = ().

Source§

impl<E, F, S> FlowDriver<E, F, S>
where E: FlowExtractor, F: ReassemblerFactory<E::Key>, S: Default + Send + 'static,

Source

pub fn with_state(extractor: E, factory: F) -> Self

Construct with default config and per-flow state initialised via S::default().

Source

pub fn with_state_and_config( extractor: E, factory: F, config: FlowTrackerConfig, ) -> Self

Construct with explicit config and per-flow state initialised via S::default().

Source§

impl<E, F, S> FlowDriver<E, F, S>
where E: FlowExtractor, F: ReassemblerFactory<E::Key>, S: Send + 'static,

Source

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

Construct with default config and a custom per-flow state initialiser. Use when S isn’t Default or when state should be derived from the flow key.

Source

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

Construct with explicit config and a custom per-flow state initialiser.

Source

pub fn with_emit_anomalies(self, enable: bool) -> Self

Opt in to emitting FlowEvent::FlowAnomaly / FlowEvent::TrackerAnomaly for buffer overflows, out-of-order drops, and tracker eviction pressure. Default: false — no anomaly events emitted; counters still accumulate in crate::FlowStats.

Anomalies are coalesced per (flow, side, kind) per tick so a pathological flow doesn’t swamp the stream.

Source

pub fn with_idle_timeout_fn<G>(self, f: G) -> Self
where G: Fn(&E::Key, Option<L4Proto>) -> Option<Duration> + Send + Sync + 'static,

Set a per-key idle-timeout override on the underlying tracker (see FlowTracker::set_idle_timeout_fn). Builder-style passthrough — chains nicely with Self::new / Self::with_config / Self::with_emit_anomalies.

Source

pub fn with_dedup(self, dedup: Dedup) -> Self

Filter incoming PacketViews through a content-hash crate::Dedup before extraction. Views the dedup classifies as duplicates produce zero events. Useful for loopback captures (tcpdump -i lo) where every packet arrives twice via the kernel’s outgoing/host reinjection.

Source

pub fn dedup(&self) -> Option<&Dedup>

Borrow the dedup state (e.g. for .dropped() / .buffered() stats). None when no dedup is configured.

Source

pub fn with_monotonic_timestamps(self, enable: bool) -> Self

Opt in to strictly non-decreasing timestamps across the stream. Each packet’s view.timestamp is clamped to max(view.timestamp, last_emitted_timestamp).

Useful for downstream consumers that build timelines from FlowEvent and want a guarantee that successive events never go backwards in time. Default: off (raw NIC timestamps flow through unmodified). The clamp also applies to Self::sweep’s now argument.

Source

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

Process one packet. Drives the tracker and dispatches TCP payloads to the factory’s reassemblers. Reassemblers are created on demand and cleaned up on Ended.

Source

pub fn track_pending<'v>( &mut self, view: impl Into<PacketView<'v>>, ) -> FlowEvents<E::Key>

Lower-level: process one packet and return events without finalizing reassemblers. Reassemblers remain accessible (via Self::reassembler / Self::drain_buffer) until Self::finalize is called.

You MUST call Self::finalize before the next track_pending / sweep_pending / track / sweep call — otherwise reassemblers for ended flows are never cleaned up. Typical use: the internal session engine calls track_pending, drains buffered bytes from reassemblers, then calls finalize.

Source

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

Run the idle-timeout sweep and clean up reassemblers for ended flows.

Source

pub fn finish(&mut self) -> Vec<FlowEvent<E::Key>>

Sweep every remaining flow to its end. Call once after the last track when input is exhausted — equivalent to sweep(Timestamp::MAX). Every still-open flow is emitted as FlowEvent::Ended.

Source

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

Force-end the flow with this key. Driver-level mirror of FlowTracker::force_close. Tears down the per-(flow, side) reassembler slots before emitting the terminal event. New in 0.8.0.

Returns the resulting FlowEvents (one Ended for the closed flow plus any pending anomalies — same shape as track()). Empty if key was not active.

Source

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

Lower-level sweep variant. Like Self::sweep but does NOT finalize ended flows’ reassemblers. See Self::track_pending for the contract.

Source

pub fn finalize(&mut self, events: &mut [FlowEvent<E::Key>])

Patch reassembly diagnostics into every Ended event and drop the corresponding reassemblers (calling fin / rst). Called automatically by Self::track / Self::sweep; callers using Self::track_pending / Self::sweep_pending must call this before the next track* / sweep* call.

Source

pub fn reassembly_memcap_bytes(&self) -> u64

Inspector for the cross-flow reassembly memcap accounting (issue #26). Returns the running total of bytes currently buffered across every live reassembler. Useful for dashboards and tests; the value mirrors what the AnomalyKind::GlobalMemcapHit bytes_in_flight field would report at the trip moment.

Source

pub fn reassembler( &mut self, key: &E::Key, side: FlowSide, ) -> Option<&mut F::Reassembler>

Borrow the per-(flow, side) reassembler. Returns None when no reassembler exists (no TCP payload has been seen on that side, or the flow has already ended and been finalized).

Most useful between Self::track_pending and Self::finalize, where reassemblers for ended flows haven’t been dropped yet.

Source

pub fn tracker(&self) -> &FlowTracker<E, S>

Borrow the inner tracker (for stats, introspection).

Source

pub fn tracker_mut(&mut self) -> &mut FlowTracker<E, S>

Borrow the inner tracker mutably.

Source

pub fn emits_anomalies(&self) -> bool

True when Self::with_emit_anomalies was called with true. Used by wrappers (e.g. the internal FlowSessionDriver engine) that need to mirror the same anomaly-emission policy.

Source

pub fn snapshot_flow_stats( &self, ) -> impl Iterator<Item = (E::Key, FlowStats)> + '_

Iterate (key, FlowStats) for every live flow. Unlike crate::FlowTracker::all_flow_stats, this combines the tracker’s per-flow stats with live reassembler diagnostics (OOO drops, oversize-byte drops, peak watermark) so consumers get an up-to-date picture mid-flow.

Returns a lazy iterator. Each item clones the underlying crate::FlowStats (cheap — owned u64s + two Timestamps) and patches in the reassembler-derived fields. Collect with .collect::<Vec<_>>() if you need to hold the snapshot past further track() calls.

Source§

impl<E, S> FlowDriver<E, BufferedReassemblerFactory, S>
where E: FlowExtractor, S: Send + 'static,

Source

pub fn drain_buffer(&mut self, key: &E::Key, side: FlowSide) -> Vec<u8>

Drain buffered bytes for the given (key, side) and return them as a Vec<u8>. Returns an empty Vec when no reassembler exists for that key/side or the buffer is empty.

Specialisation of Self::reassembler for the crate::BufferedReassemblerFactory case — calls crate::BufferedReassembler::take on the reassembler. Used by the internal session engine between track_pending and finalize to harvest payload bytes before ended-flow reassemblers are dropped.

Auto Trait Implementations§

§

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

§

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

§

impl<E, F, S> Freeze for FlowDriver<E, F, S>
where F: Freeze, E: Freeze, <E as FlowExtractor>::Key: Freeze,

§

impl<E, F, S> Send for FlowDriver<E, F, S>

§

impl<E, F, S> Sync for FlowDriver<E, F, S>
where F: Sync, S: Sync, <F as ReassemblerFactory<<E as FlowExtractor>::Key>>::Reassembler: Sync,

§

impl<E, F, S> Unpin for FlowDriver<E, F, S>

§

impl<E, F, S> UnsafeUnpin for FlowDriver<E, F, 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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more