struct GenerationalBuffer<S> {
shares: VecDeque<(HoprSurbId, S)>,
plain: VecDeque<(HoprSurbId, S)>,
generation: Option<u8>,
}Expand description
The mutex-protected state of a SurbRingBuffer: the SURBs, in their two tiers, and the highest
generation seen.
All of it lives under one lock so that clearing both tiers and advancing the generation on a newer batch is atomic against a concurrent pop, and so that the combined length the capacity bounds is never seen or changed half-way.
Fields§
SURBs carrying a PIX share, in insertion order. The Entry emits shares in SSA-index order, so FIFO here is also lowest-SSA-first.
plain: VecDeque<(HoprSurbId, S)>SURBs carrying no share: pure return paths.
generation: Option<u8>Highest generation seen; None until the first push.
Implementations§
Source§impl<S> GenerationalBuffer<S>
impl<S> GenerationalBuffer<S>
Sourcefn next_tier(&self) -> &VecDeque<(HoprSurbId, S)>
fn next_tier(&self) -> &VecDeque<(HoprSurbId, S)>
The tier a pop takes from: share-bearing SURBs for as long as there are any, share-less ones only once there are none. The single place that priority is decided, so peeking and popping — and with them the exact-ID pop — cannot disagree about which SURB is next.
Sourcefn next_tier_mut(&mut self) -> &mut VecDeque<(HoprSurbId, S)>
fn next_tier_mut(&mut self) -> &mut VecDeque<(HoprSurbId, S)>
As next_tier, for removing from it.
Sourcefn peek_next(&self) -> Option<&(HoprSurbId, S)>
fn peek_next(&self) -> Option<&(HoprSurbId, S)>
The SURB the next pop would take: the oldest of the next tier. Peeking and popping both go
through next_tier, so they stay in step.
Sourcefn pop_next(&mut self) -> Option<(HoprSurbId, S)>
fn pop_next(&mut self) -> Option<(HoprSurbId, S)>
Removes and returns the oldest SURB of the next tier.
Sourcefn make_room_for(&mut self, newcomer_carries_share: bool) -> MadeRoom
fn make_room_for(&mut self, newcomer_carries_share: bool) -> MadeRoom
Makes room in a full buffer for one more SURB by evicting the oldest share-less one.
Failing that, the oldest share-bearing one goes if the newcomer carries a share too. A share-less
newcomer is turned away instead — a return path is not worth a share nothing can replace — and
MadeRoom::Refused says so: there is no room for it, and the caller must not insert it.
What happened is returned rather than just whether there is room, because the cost differs: a share-less SURB is only a lost return path, a share-bearing one is a share nothing can replace.
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for GenerationalBuffer<S>
impl<S> RefUnwindSafe for GenerationalBuffer<S>where
S: RefUnwindSafe,
impl<S> Send for GenerationalBuffer<S>where
S: Send,
impl<S> Sync for GenerationalBuffer<S>where
S: Sync,
impl<S> Unpin for GenerationalBuffer<S>where
S: Unpin,
impl<S> UnsafeUnpin for GenerationalBuffer<S>
impl<S> UnwindSafe for GenerationalBuffer<S>where
S: UnwindSafe,
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more