pub struct PeerSelector { /* private fields */ }Expand description
The self-optimizing peer selector (SPEC §5, §11). Construct with PeerSelector::new, feed it
registry churn + DHT candidates, ask it to select a source subset, and
stream every measured outcome back via record_outcome.
Implementations§
Source§impl PeerSelector
impl PeerSelector
Sourcepub fn new(config: SelectorConfig) -> Self
pub fn new(config: SelectorConfig) -> Self
Construct a selector from wiring-only SelectorConfig (SPEC §5.6). No behavior knobs — every
tradeoff is learned.
Sourcepub fn select(
&self,
req: &ContentRequest,
candidates: &[Candidate],
) -> Selection
pub fn select( &self, req: &ContentRequest, candidates: &[Candidate], ) -> Selection
select — rank a candidate set for a request (SPEC §5.1).
Registers any fresh candidate (cold — its first pick is exploratory, SPEC §2.3, §4.4-E),
scores every eligible candidate against the learned models, and returns a ranked chosen subset
bounded by the request’s parallelism. Each chosen peer carries its recommended max_concurrency
(its learned saturation headroom, SPEC §4.1/§4.5) and its exploratory flag. Anti-herd: total
dispatched concurrency is filled peer-by-peer up to each peer’s headroom, spilling to the next
(SPEC §4.4-B). Dispatch bumps in-flight so the very next select/rebalance sees it.
Sourcepub fn rebalance(
&self,
req: &ContentRequest,
active: &[PeerId],
need: &RangePlanDelta,
) -> Selection
pub fn rebalance( &self, req: &ContentRequest, active: &[PeerId], need: &RangePlanDelta, ) -> Selection
rebalance — re-query the up-to-the-moment models for still-needed ranges (SPEC §5.5).
Mid-transfer, when a source drops or a range must be relocated, the executor calls this to get
a replacement subset for the needed ranges, de-ranking the already-active peers (they are
counted as busy so their headroom shrinks) and reflecting every record_outcome received so
far. It obeys the same invariants as select (SPEC §4.4).
Sourcepub fn record_outcome(&self, outcome: &TransferOutcome)
pub fn record_outcome(&self, outcome: &TransferOutcome)
record_outcome — fold a measured result back into the models in real time (SPEC §5.2).
Derives throughput strictly from measured bytes / duration_ms (never a self-reported rate,
SPEC §9.3); updates throughput/RTT/reliability (SPEC §3.2, §3.4), the per-class saturation
model (SPEC §4.1), the adaptive relayed penalty (SPEC §4.2), and decrements in-flight (SPEC
§5.3). An outcome for an unknown peer upserts a cold entry first (self-healing, SPEC §5.2).
Sourcepub fn on_pool_event(&self, event: &PoolEvent)
pub fn on_pool_event(&self, event: &PoolEvent)
Consume a dig-gossip churn event to keep the registry live (SPEC §5.4, §2.3). Byte-compatible
with dig_gossip::PoolEvent (see crate::pool_event).
Sourcepub fn on_connection_class(&self, peer: &PeerId, class: TraversalKind)
pub fn on_connection_class(&self, peer: &PeerId, class: TraversalKind)
Attach / update a live peer’s connection class from dig-nat (SPEC §5.4, §7.3).
Sourcepub fn upsert_candidate(&self, candidate: &Candidate)
pub fn upsert_candidate(&self, candidate: &Candidate)
Manually upsert a candidate (seed / bootstrap feed, SPEC §5.4). A fresh peer is cold.
Sourcepub fn remove_peer(&self, peer: &PeerId)
pub fn remove_peer(&self, peer: &PeerId)
Explicitly remove a peer (rare; churn usually drives this — SPEC §5.4). A peer with a range in flight is retained until it settles.
Sourcepub fn on_dispatch(&self, peer: &PeerId, count: u32)
pub fn on_dispatch(&self, peer: &PeerId, count: u32)
Explicitly note that count ranges were dispatched to peer (SPEC §5.3). Optional: select
already accounts the dispatch it returns; the host uses this only if it dispatches outside a
select result.
Sourcepub fn peer_snapshot(&self, peer: &PeerId) -> Option<PeerSnapshot>
pub fn peer_snapshot(&self, peer: &PeerId) -> Option<PeerSnapshot>
A read-only snapshot of one peer’s learned model, or None if unknown (SPEC §5.7).
Sourcepub fn snapshot(&self) -> SelectorSnapshot
pub fn snapshot(&self) -> SelectorSnapshot
A read-only snapshot of the selector’s learned aggregate state (SPEC §5.7). Includes the
engine’s internal side-map sizes (last_selected_len, dispatched_len) so a host can confirm
they track the live registry population rather than growing unboundedly (#179 finding 2).
Sourcepub fn registry_size(&self) -> usize
pub fn registry_size(&self) -> usize
The current registry size (SPEC §5.7).
Auto Trait Implementations§
impl !Freeze for PeerSelector
impl RefUnwindSafe for PeerSelector
impl Send for PeerSelector
impl Sync for PeerSelector
impl Unpin for PeerSelector
impl UnsafeUnpin for PeerSelector
impl UnwindSafe for PeerSelector
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.