pub struct ContentRoutingOptimizer { /* private fields */ }Expand description
Content routing optimizer that caches and manages peer routing decisions.
Implementations§
Source§impl ContentRoutingOptimizer
impl ContentRoutingOptimizer
Sourcepub fn new(config: OptimizerConfig) -> Self
pub fn new(config: OptimizerConfig) -> Self
Creates a new optimizer with the supplied configuration.
Sourcepub fn add_route(
&mut self,
cid: String,
candidates: Vec<RouteCost>,
now_secs: u64,
)
pub fn add_route( &mut self, cid: String, candidates: Vec<RouteCost>, now_secs: u64, )
Adds (or replaces) a routing entry for cid.
Candidates that do not meet the min_reliability threshold are
discarded before insertion. The survivors are sorted by
RouteCost::weighted_score descending and truncated to
max_candidates_per_cid.
Sourcepub fn best_route(&mut self, cid: &str, now_secs: u64) -> Option<&RouteCost>
pub fn best_route(&mut self, cid: &str, now_secs: u64) -> Option<&RouteCost>
Returns the best peer for cid, updating cache statistics.
Returns None when:
- The entry does not exist (cache miss).
- The entry is stale — the entry is removed and counted as a stale eviction plus a cache miss.
Sourcepub fn evict_stale(&mut self, now_secs: u64) -> usize
pub fn evict_stale(&mut self, now_secs: u64) -> usize
Evicts all stale entries from the cache.
Returns the number of entries that were removed.
Sourcepub fn update_peer_cost(
&mut self,
peer_id: &str,
new_latency_ms: f64,
new_reliability: f64,
)
pub fn update_peer_cost( &mut self, peer_id: &str, new_latency_ms: f64, new_reliability: f64, )
Updates the latency and reliability for peer_id across all
cached routing entries, then re-sorts each affected entry’s candidates.
Sourcepub fn stats(&self) -> &RoutingStats
pub fn stats(&self) -> &RoutingStats
Returns a reference to the current routing statistics.
Sourcepub fn route_count(&self) -> usize
pub fn route_count(&self) -> usize
Returns the number of entries currently held in the route cache.
Auto Trait Implementations§
impl Freeze for ContentRoutingOptimizer
impl RefUnwindSafe for ContentRoutingOptimizer
impl Send for ContentRoutingOptimizer
impl Sync for ContentRoutingOptimizer
impl Unpin for ContentRoutingOptimizer
impl UnsafeUnpin for ContentRoutingOptimizer
impl UnwindSafe for ContentRoutingOptimizer
Blanket Implementations§
impl<T> Allocation for T
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> 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 more