pub struct MessageReassembler<C = ()> { /* 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), 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.
One charge per message (load-bounds paper, Law 4, #932). A message is opened only by its
first chunk, [0, n] with data length d₀, and only when (n − 1)·d₀ stays below
ReassemblyLimits::max_message_bytes; the charge C that chunk brings (the receiver’s
mailbox reservation of n·d₀) is held with the message. Every later chunk is at most d₀
long, so the message never outgrows that charge, and the charge a later chunk brings is
dropped. The charge leaves with the completed message (RetainedReassembly), or is dropped
when the message expires or the reassembler closes. The reassembler itself holds no budget
and refuses nothing for capacity: its remaining caps (ids, slots, chunk length, message
length) are validity bounds an honest sender never meets.
chunk [0, n], d₀ ── new id, (n − 1)·d₀ < max ──▶ open(charge) (Incomplete)
chunk [i, n], dᵢ ── open, dᵢ ≤ d₀, slot free ───▶ insert; drop charge (Incomplete | Complete)
chunk [i > 0, n] ── no open message ────────────▶ Rejected(Invalid | Replay)
expiry, stall, close ───────────────────────────▶ drop(message, charge)Rate floor. An open message also expires, attributably, once the bytes it received fall
below the rate floor over the credit-time its sender held unused credit for, less one lane
window of grace (progress; load-bounds paper, Def. 7 and Law 4). The caller reads that
credit, per carrier, from its transport; a caller that reads none (|_| 0, as the plain API
does) never advances the clock, and a message then expires at its TTL alone.
Implementations§
Source§impl MessageReassembler
impl MessageReassembler
Sourcepub fn new() -> MessageReassembler
pub fn new() -> MessageReassembler
Empty reassembler with ReassemblyLimits::production bounds, holding no charge.
Source§impl<C> MessageReassembler<C>
impl<C> MessageReassembler<C>
Sourcepub fn with_limits(limits: ReassemblyLimits) -> MessageReassembler<C>
pub fn with_limits(limits: ReassemblyLimits) -> MessageReassembler<C>
Empty reassembler enforcing the given limits, whose messages hold charges C. 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, with their charges, and evict completed-id tombstones that have likewise expired (a retransmit past its expiry is rejected anyway).
Trait Implementations§
Source§impl Default for MessageReassembler
impl Default for MessageReassembler
Source§fn default() -> MessageReassembler
fn default() -> MessageReassembler
Auto Trait Implementations§
impl<C> Forget for MessageReassembler<C>
impl<C> Freeze for MessageReassembler<C>
impl<C> Move for MessageReassembler<C>
impl<C> RefUnwindSafe for MessageReassembler<C>
impl<C> Send for MessageReassembler<C>
impl<C> Sync for MessageReassembler<C>
impl<C> Unpin for MessageReassembler<C>
impl<C> UnsafeUnpin for MessageReassembler<C>
impl<C> UnwindSafe for MessageReassembler<C>
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
impl<T> MaybeSendSync 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.