pub struct PathSet { /* private fields */ }Expand description
A bounded set of alternative paths for a single destination.
paths[0] is always the primary (best) path. Ranking: lowest hops
first, then most-recent timestamp.
Implementations§
Source§impl PathSet
impl PathSet
Sourcepub fn from_single(entry: PathEntry, capacity: usize) -> Self
pub fn from_single(entry: PathEntry, capacity: usize) -> Self
Create a new PathSet containing a single path.
Sourcepub fn primary_mut(&mut self) -> Option<&mut PathEntry>
pub fn primary_mut(&mut self) -> Option<&mut PathEntry>
Mutable access to the primary path.
Sourcepub fn iter(&self) -> impl Iterator<Item = &PathEntry>
pub fn iter(&self) -> impl Iterator<Item = &PathEntry>
Iterator over all paths (primary first).
Sourcepub fn upsert(&mut self, entry: PathEntry)
pub fn upsert(&mut self, entry: PathEntry)
Insert or update a path entry.
- If a path with the same
next_hopalready exists, it is replaced in-place. - Otherwise the entry is added as an alternative. If at capacity the worst path (highest hops, then oldest) is evicted.
After mutation the vector is re-sorted so paths[0] remains the best.
Sourcepub fn failover(&mut self, remove: bool)
pub fn failover(&mut self, remove: bool)
Promote the next-best path after the current primary becomes unresponsive.
If remove is true the old primary is discarded; otherwise it is
moved to the back of the list (it may recover later).
Sourcepub fn cull(
&mut self,
now: f64,
interface_exists: impl Fn(&InterfaceId) -> bool,
)
pub fn cull( &mut self, now: f64, interface_exists: impl Fn(&InterfaceId) -> bool, )
Remove expired or orphaned paths.
interface_exists is a predicate that checks whether an interface is
still registered.
Sourcepub fn retain(&mut self, predicate: impl Fn(&PathEntry) -> bool)
pub fn retain(&mut self, predicate: impl Fn(&PathEntry) -> bool)
Filter paths by a predicate, keeping only those that match.
Sourcepub fn expire_all(&mut self)
pub fn expire_all(&mut self)
Expire all paths in this set (set timestamp/expires to 0).
Sourcepub fn all_random_blobs(&self) -> Vec<[u8; 10]>
pub fn all_random_blobs(&self) -> Vec<[u8; 10]>
Collect all random_blobs across every path in this set.