pub struct RouteCache {
entries: HashMap<[u8; 32], RouteRecord>,
forgotten: Vec<[u8; 32]>,
dirty: bool,
}Expand description
Every route this tool remembers.
Fields§
§entries: HashMap<[u8; 32], RouteRecord>§forgotten: Vec<[u8; 32]>Keys this session deliberately forgot. Kept so that a merge with whatever another invocation wrote does not quietly put them back: forgetting is something somebody asked for, and it should not depend on who writes last.
dirty: boolImplementations§
Source§impl RouteCache
impl RouteCache
Sourcepub fn load() -> Self
pub fn load() -> Self
Read the remembered routes, dropping whatever has expired.
A missing file is an empty cache, and so is an unreadable or malformed one: this is a cache, and refusing to run because it cannot be parsed would trade a slow command for no command.
fn parse(text: &str) -> Self
Sourcepub fn get(&self, peer: &PublicKey) -> Option<&RouteRecord>
pub fn get(&self, peer: &PublicKey) -> Option<&RouteRecord>
The route remembered for peer, if it has not expired.
Sourcepub fn record(&mut self, peer: &PublicKey, route: CachedRoute)
pub fn record(&mut self, peer: &PublicKey, route: CachedRoute)
Remember route for peer, stamped now.
A route identical to the one already held keeps its original timestamp: the age is meant to say when the path was learned, not when it was last written down.
Sourcepub fn remove(&mut self, peer: &PublicKey) -> bool
pub fn remove(&mut self, peer: &PublicKey) -> bool
Forget peer’s route, reporting whether one was held.
Sourcepub fn iter(&self) -> Vec<(PublicKey, &RouteRecord)>
pub fn iter(&self) -> Vec<(PublicKey, &RouteRecord)>
Every remembered route, newest first.
pub fn is_empty(&self) -> bool
Sourcepub async fn harvest<R: Radio>(
&mut self,
handle: &MacHandle<'_, TokioPlatform<R, TokioFileCounterStore, TokioFileKeyValueStore>, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>,
)
pub async fn harvest<R: Radio>( &mut self, handle: &MacHandle<'_, TokioPlatform<R, TokioFileCounterStore, TokioFileKeyValueStore>, IDENTITIES, PEERS, CHANNELS, ACKS, TX, FRAME, DUP>, )
Copy the live MAC’s routes into the cache.
Only what changed is stamped, so an unchanged route keeps saying when it was learned rather than when it was last looked at.
Sourcepub fn store(&mut self) -> Result<()>
pub fn store(&mut self) -> Result<()>
Write the cache back, merging whatever another invocation wrote while this one was running.
Two shells against two radios is an ordinary way to use this tool, and last-writer-wins over the whole file would throw away the other’s fresh routes. Merging by timestamp keeps the newer of each, which is the same rule the cache uses against itself.