RouteCache

Struct RouteCache 

Source
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: bool

Implementations§

Source§

impl RouteCache

Source

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.

Source

fn parse(text: &str) -> Self

Source

pub fn get(&self, peer: &PublicKey) -> Option<&RouteRecord>

The route remembered for peer, if it has not expired.

Source

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.

Source

pub fn remove(&mut self, peer: &PublicKey) -> bool

Forget peer’s route, reporting whether one was held.

Source

pub fn clear(&mut self) -> usize

Forget everything, reporting how many routes went.

Source

pub fn iter(&self) -> Vec<(PublicKey, &RouteRecord)>

Every remembered route, newest first.

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

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.

Source

fn render(&self) -> String

Trait Implementations§

Source§

impl Debug for RouteCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RouteCache

Source§

fn default() -> RouteCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,