FlashStore

Struct FlashStore 

Source
pub struct FlashStore<F, M>{ /* private fields */ }
Expand description

Owns the flash driver and the sequential-storage map.

Construct once during board init, place in a StaticCell, then hand &'static references to the view constructors when building the Mac platform.

Implementations§

Source§

impl<F, M> FlashStore<F, M>

Source

pub fn new(flash: F, range: Range<u32>) -> Self

Wrap an async flash driver over range. Does NOT erase or format the flash — the underlying map mounts lazily on first access.

range must be page-aligned and at least two pages long; MapConfig::new panics otherwise. Callers pass a board constant, so a bad geometry is a boot-time panic rather than a silent corruption.

Source§

impl<F, M> FlashStore<F, M>

Source

pub async fn load_tracker_preferences( &self, ) -> Result<Option<u8>, Error<F::Error>>

Load the board-independent encoded tracker preferences byte.

Source

pub async fn store_tracker_preferences( &self, value: u8, ) -> Result<(), Error<F::Error>>

Persist the board-independent encoded tracker preferences byte.

Source

pub async fn load_sk(&self) -> Result<Option<[u8; 32]>, Error<F::Error>>

Load the local Ed25519 secret key from storage.

Returns Ok(Some(sk)) when a valid 32-byte key is present, Ok(None) when no key has been stored yet (first boot), and Err on a storage or hardware failure.

Source

pub async fn store_sk(&self, sk: &[u8; 32]) -> Result<(), Error<F::Error>>

Persist the local Ed25519 secret key.

Call this exactly once on first boot, after generating the key from the hardware TRNG. Subsequent boots should use load_sk.

Source§

impl<F, M> FlashStore<F, M>

Source

pub async fn load_all_peers<const N: usize>( &self, out: &mut Vec<([u8; 32], Option<String<MAX_ALIAS_LEN>>), N>, ) -> Result<(), Error<F::Error>>

Load every persisted peer into out.

Each entry is a raw 32-byte public key plus an optional alias string (up to 16 UTF-8 bytes). Entries beyond N are silently dropped.

Source

pub async fn store_peer_entry( &self, pk: &[u8; 32], alias: Option<&[u8]>, ) -> Result<(), Error<F::Error>>

Upsert the alias for pk.

Writes the alias header and appends pk to the peer index if not already present. Any previously stored identity bytes are preserved. alias, if supplied, must be at most MAX_ALIAS_LEN bytes.

Source

pub async fn update_peer_identity( &self, pk: &[u8; 32], identity_bytes: &[u8], ) -> Result<(), Error<F::Error>>

Update (or clear) the serialised NodeIdentityPayload for pk.

The alias header is preserved. Pass an empty slice to remove the identity portion while keeping the alias. The peer must already be in the peer index (i.e. store_peer_entry called first).

Source

pub async fn load_peer_identity( &self, pk: &[u8; 32], out: &mut [u8], ) -> Result<Option<usize>, Error<F::Error>>

Load the raw serialised identity bytes for pk into out.

Returns the number of bytes written when an identity record is present, None when no identity has been stored yet.

Source

pub async fn peer_exists(&self, pk: &[u8; 32]) -> Result<bool, Error<F::Error>>

Return true if pk appears in the peer index.

Used to guard update_peer_identity so that identity bytes received over the air are only stored for peers the user has explicitly added.

Source

pub async fn delete_peer_entry( &self, pk: &[u8; 32], ) -> Result<(), Error<F::Error>>

Remove the peer record for pk from both the per-key record and the peer index. A no-op if the peer was not previously stored.

Source§

impl<F, M> FlashStore<F, M>

Source

pub async fn load_all_channels<const N: usize>( &self, out: &mut Vec<(String<MAX_CHANNEL_NAME_LEN>, [u8; 32]), N>, ) -> Result<(), Error<F::Error>>

Load every persisted channel into out.

Each entry is a name string (up to 16 UTF-8 bytes) and a 32-byte key. Entries beyond N are silently dropped.

Source

pub async fn store_channel_entry( &self, name: &[u8], key: &[u8; 32], ) -> Result<(), Error<F::Error>>

Upsert the channel record for name.

Writes the 32-byte key into the per-name record and appends the name to the channel index if not already present.

Source

pub async fn delete_channel_entry( &self, name: &[u8], ) -> Result<(), Error<F::Error>>

Remove the channel record for name from both the per-name record and the channel index. A no-op if the channel was not previously stored.

Auto Trait Implementations§

§

impl<F, M> !Freeze for FlashStore<F, M>

§

impl<F, M> !RefUnwindSafe for FlashStore<F, M>

§

impl<F, M> Send for FlashStore<F, M>
where M: Send, F: Send,

§

impl<F, M> Sync for FlashStore<F, M>
where M: Sync, F: Send,

§

impl<F, M> Unpin for FlashStore<F, M>
where M: Unpin, F: Unpin,

§

impl<F, M> UnwindSafe for FlashStore<F, M>
where M: UnwindSafe, F: UnwindSafe,

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.

§

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.