pub struct TcpReassembler { /* private fields */ }Expand description
TCP stream reassembly engine using a BTreeMap for out-of-order segment management.
Mirrors Wireshark’s reassemble.c logic: segments are keyed by absolute TCP sequence number. In-order segments are immediately appended to the contiguous reassembled buffer, while out-of-order segments are cached until gaps are filled.
Implementations§
Source§impl TcpReassembler
impl TcpReassembler
Sourcepub fn initialize(&mut self, initial_seq: u32)
pub fn initialize(&mut self, initial_seq: u32)
Initialize with the first observed sequence number (ISN + 1 for data after SYN).
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Whether this reassembler has been initialized.
Sourcepub fn reassembled_data(&self) -> &[u8] ⓘ
pub fn reassembled_data(&self) -> &[u8] ⓘ
Get the contiguous reassembled data if it’s in memory.
Returns None if the data has been spilled to disk.
Use [read_reassembled] for guaranteed access regardless of storage location.
Sourcepub fn read_reassembled(&self) -> Result<Vec<u8>>
pub fn read_reassembled(&self) -> Result<Vec<u8>>
Read the reassembled data regardless of storage location.
Works for both in-memory and spilled-to-disk data.
Sourcepub fn drain_reassembled(&mut self) -> Result<Vec<u8>>
pub fn drain_reassembled(&mut self) -> Result<Vec<u8>>
Drain and return the reassembled data, resetting the buffer.
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Total bytes in the out-of-order buffer.
Sourcepub fn fragment_count(&self) -> usize
pub fn fragment_count(&self) -> usize
Number of out-of-order fragments.
Sourcepub fn in_memory_bytes(&self) -> usize
pub fn in_memory_bytes(&self) -> usize
Total bytes currently held in memory (reassembled + OOO segments).
Sourcepub fn spill(&mut self, spill_dir: Option<&Path>) -> Result<usize>
pub fn spill(&mut self, spill_dir: Option<&Path>) -> Result<usize>
Spill reassembled data to a temporary file on disk.
Returns the number of bytes freed from memory.
Sourcepub fn is_spilled(&self) -> bool
pub fn is_spilled(&self) -> bool
Whether the reassembled data has been spilled to disk.
Sourcepub fn process_segment(
&mut self,
seq: u32,
payload: &[u8],
config: &FlowConfig,
) -> Result<ReassemblyAction, FlowError>
pub fn process_segment( &mut self, seq: u32, payload: &[u8], config: &FlowConfig, ) -> Result<ReassemblyAction, FlowError>
Process an incoming TCP segment.
Handles in-order, out-of-order, overlapping, and duplicate segments according to the algorithm described in the architectural blueprint.