Skip to main content

BufferedReassembler

Struct BufferedReassembler 

Source
pub struct BufferedReassembler { /* private fields */ }
Available on crate feature reassembler only.
Expand description

Built-in: drop OOO segments, accumulate in-order bytes into a Vec<u8> per direction. Drain via take.

Sync, no channel dep. Users who want a channel send via std::sync::mpsc themselves, or use netring’s TokioChannelReassembler for tokio integration.

Optionally bounded via with_max_buffer. When the cap is reached the OverflowPolicy decides whether to rotate bytes out (sliding window) or poison the reassembler so the driver can tear the flow down on the next tick.

Implementations§

Source§

impl BufferedReassembler

Source

pub fn new() -> Self

Source

pub fn with_max_buffer(self, max_bytes: usize) -> Self

Set a maximum in-flight buffer size in bytes. When new in-order segments would push buffered_len() past this cap, the configured OverflowPolicy kicks in.

Default policy is OverflowPolicy::SlidingWindow. Pair with with_overflow_policy to switch to OverflowPolicy::DropFlow for framed binary protocols.

Source

pub fn with_overflow_policy(self, policy: OverflowPolicy) -> Self

Override the overflow policy. Has no effect unless with_max_buffer is also called.

Source

pub fn with_high_watermark_threshold(self, percent: u8) -> Self

Fire a crate::AnomalyKind::ReassemblerHighWatermark anomaly when buffer occupancy crosses percent % of max_buffer from below — once per crossing (debounced; occupancy must drop back below before the next event re-arms). Default: off.

No effect unless with_max_buffer is also set. Values outside 1..=100 are clamped.

Source

pub fn take(&mut self) -> Vec<u8>

Drain accumulated in-order bytes, leaving the buffer empty. expected_seq is preserved so subsequent in-order segments keep accumulating. Also re-arms the high-watermark threshold (if configured): once drained, the next time occupancy climbs back above the threshold counts as a fresh crossing.

Source

pub fn dropped_segments(&self) -> u64

Number of segments dropped because they were out of order.

Source

pub fn bytes_dropped_oversize(&self) -> u64

Number of payload bytes dropped because the per-side buffer cap was exceeded. Zero when no cap is set or when the cap has not yet been hit.

Source

pub fn buffered_len(&self) -> usize

Bytes currently buffered (not yet drained).

Source

pub fn is_poisoned(&self) -> bool

True after an OverflowPolicy::DropFlow overflow. The driver checks this once per tick; true triggers an Ended { reason: BufferOverflow } event for the flow.

Source

pub fn high_watermark(&self) -> u64

Peak buffer occupancy ever observed for this reassembler. Updated on every append_with_cap call, reflecting post-rotation state under OverflowPolicy::SlidingWindow. Survives take — useful for tuning crate::FlowTrackerConfig::max_reassembler_buffer.

Source

pub fn retransmits(&self) -> u64

Number of TCP segments classified as retransmits on this side — seq + len <= expected_seq. Distinct from dropped_segments, which counts strictly-out-of-order segments ahead of expected_seq. New in 0.5.0.

Source§

impl BufferedReassembler

Source

pub fn high_watermark_crossings(&self) -> u64

Running count of below→above transitions of the configured high-watermark threshold. Zero when no threshold is set.

Trait Implementations§

Source§

impl Debug for BufferedReassembler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferedReassembler

Source§

fn default() -> BufferedReassembler

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

impl Reassembler for BufferedReassembler

Source§

fn segment(&mut self, seq: u32, payload: &[u8], ts: Timestamp)

New segment arrived in this direction. Read more
Source§

fn dropped_segments(&self) -> u64

Number of TCP segments dropped because they arrived out of order for this side. Default: 0. Read more
Source§

fn bytes_dropped_oversize(&self) -> u64

Number of payload bytes dropped because the per-side buffer cap was exceeded. Default: 0. Read more
Source§

fn is_poisoned(&self) -> bool

True after a fatal-style overflow (e.g. crate::OverflowPolicy::DropFlow). The driver checks this once per tick; true triggers synthesis of an Ended { reason: BufferOverflow } event for the flow. Default: false.
Source§

fn high_watermark(&self) -> u64

Peak in-flight buffer occupancy ever observed for this side. Default: 0 (custom reassemblers may not track this). Read more
Source§

fn bytes_in_flight(&self) -> u64

Bytes currently buffered, awaiting parser consumption. Default: 0. Mirrors the contract of Self::high_watermark — only meaningful for impls that actually buffer bytes.
Source§

fn high_watermark_crossings(&self) -> u64

Running count of below→above transitions of the configured high-watermark threshold (see [BufferedReassembler:: with_high_watermark_threshold]). Default: 0. The driver uses per-tick deltas of this counter to emit crate::AnomalyKind::ReassemblerHighWatermark events without spamming on repeated above-threshold ticks.
Source§

fn high_watermark_threshold(&self) -> Option<(u64, u8)>

Some((cap, percent)) when a high-watermark threshold is configured; None otherwise. Lets the driver enrich crate::AnomalyKind::ReassemblerHighWatermark events with the cap and threshold percent at emission time. Default: None.
Source§

fn retransmits(&self) -> u64

Number of TCP segments classified as retransmits — re-deliveries of bytes the reassembler has already accounted for (seq + len <= expected_seq). New in 0.5.0; default 0. Read more
Source§

fn current_bytes(&self) -> u64

Current live byte occupancy of the reassembler — bytes in the ready buffer plus any OOO pending. This is the hook a future global-memcap enforcement layer (see crate::FlowTrackerConfig::reassembly_memcap) reads to sum cross-flow usage. Read more
Source§

fn fin(&mut self)

FIN observed in this direction. Default: no-op.
Source§

fn rst(&mut self)

RST observed in this direction (or session aborted). Default: no-op.
Source§

fn on_duplicate(&mut self, _seq: u32, _payload: &[u8], _ts: Timestamp)

Hook called when a segment is classified as a retransmit rather than appended to the buffer. Default no-op. Custom reassemblers can use this to drive RTT estimators, retransmit-rate metrics, etc. Called by BufferedReassembler for each classified retransmit; not called for fresh or OOO segments.
Source§

fn rexmit_inconsistencies(&self) -> u64

Running count of retransmits whose bytes differ from what the reassembler previously saw for the overlapping sequence range — the classic Ptacek-Newsham TCP overlap evasion IOC (cf. Zeek’s rexmit_inconsistency). Default 0 for implementations that don’t retain enough history to detect the divergence. 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<'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