pub struct MessageReassembler { /* private fields */ }Expand description
Receiver side: whole-message reassembly for reliable data-channel MessagePayload
fragments. Buffers a message’s chunks keyed by id and yields the complete Bytes once every
position has arrived (then forgets it).
Correct under duplicates / retransmits (first write per position wins during assembly, out-of-order arrival sorted), partial delivery (TTL eviction), and a message fully retransmitted after it already completed: a completed id is kept as a tombstone until it would expire, so a late re-send within the TTL window is dropped rather than re-assembled and delivered twice.
Bounded against a hostile peer by the ReassemblyLimits it is built with: every accepted
chunk is validated and charged to both a per-peer pending-cost limit and a node-wide budget, so
reassembly memory cannot grow without limit no matter how the load is shaped. Per-chunk data,
per-message data, slot overhead, the pending/terminal id counts, and the completed-id tombstone
set are all capped, and an already-expired chunk is rejected before it can be delivered or
buffered.
Implementations§
Source§impl MessageReassembler
impl MessageReassembler
Sourcepub fn new() -> MessageReassembler
pub fn new() -> MessageReassembler
Empty reassembler with ReassemblyLimits::production bounds.
Sourcepub fn with_limits(limits: ReassemblyLimits) -> MessageReassembler
pub fn with_limits(limits: ReassemblyLimits) -> MessageReassembler
Empty reassembler enforcing the given limits. Tests use this with small limits to exercise
the admission rule without giant synthetic payloads.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of messages currently being reassembled (incomplete).
Sourcepub fn remove_expired(&mut self)
pub fn remove_expired(&mut self)
Drop messages whose TTL has elapsed, returning their cost to the budget, and evict completed-id tombstones that have likewise expired (a retransmit past its expiry is rejected anyway).
Sourcepub fn remove(&mut self, id: Uuid)
pub fn remove(&mut self, id: Uuid)
Forget a message (e.g. after it has been delivered), returning its cost to the budget.
Sourcepub fn handle(&mut self, chunk: Chunk) -> Option<Bytes>
pub fn handle(&mut self, chunk: Chunk) -> Option<Bytes>
Accept one chunk. Returns the fully reassembled payload when this chunk completes its
message (which is then forgotten), otherwise None.
Imperative shell over a functional core: expire stale state, ask the pure classify for an
admission verdict, and apply it. Accepted data mutation stays in admit; the shell records
only bounded terminal/capacity evidence for rejected chunks so local loss cannot become a
peer failure and one logical id cannot produce conflicting terminal outcomes.
Trait Implementations§
Source§impl Default for MessageReassembler
impl Default for MessageReassembler
Source§fn default() -> MessageReassembler
fn default() -> MessageReassembler
Source§impl Drop for MessageReassembler
impl Drop for MessageReassembler
Auto Trait Implementations§
impl Freeze for MessageReassembler
impl RefUnwindSafe for MessageReassembler
impl Send for MessageReassembler
impl Sync for MessageReassembler
impl Unpin for MessageReassembler
impl UnsafeUnpin for MessageReassembler
impl UnwindSafe for MessageReassembler
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
impl<T> MaybeSend for T
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.