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 a budget, so reassembly memory cannot grow without limit no
matter how the load is shaped — per-chunk data, per-message data, a global buffered-cost ceiling
(charging a per-slot overhead so a tiny-chunk flood is bounded by slot count too), the id count,
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() -> Self
pub fn new() -> Self
Empty reassembler with ReassemblyLimits::production bounds.
Sourcepub fn with_limits(limits: ReassemblyLimits) -> Self
pub fn with_limits(limits: ReassemblyLimits) -> Self
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. The only mutation of the buffer is in admit; a rejected
chunk leaves no trace and is logged once with its typed Rejected reason.
Trait Implementations§
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,
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>
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.