DeviceStorage

Device storage backend.

Stores node information, configuration, channels, and other persistent state keyed by TransportIdentity. Implementations must be thread-safe from the perspective of the engine actor (they may use internal locks, but the SDK makes no concurrency assumptions beyond that all calls are serialized by the engine).

Audit trail and factory-reset detection: The recordOwnNode method records the device's NodeNum and firmware version. If the NodeNum changes between calls for the same identity (e.g., factory reset, radio swap, or hostname now resolves to a different physical device), the implementation must atomically clear all state before recording the new tuple. This prevents stale NodeDB rows from leaking into a new session.

Failure contract: implementations may throw MeshtasticException.StorageUnavailable (or any other Exception) to signal transient or persistent I/O failure. The SDK engine catches these uniformly, emits MeshEvent.StorageDegraded at most once per connect cycle, and continues operating entirely in-memory for the remainder of that session. The engine will re-attempt storage activation on the next RadioClient.connect. Callers must therefore not rely on writes having been durable unless they explicitly subscribe to RadioClient.events and confirm no MeshEvent.StorageDegraded was emitted.

Since

0.1.0

Functions

Link copied to clipboard
abstract suspend fun clear()

Clear all stored data for this storage instance.

Link copied to clipboard
abstract override fun close()

Close and release resources.

Link copied to clipboard
abstract suspend fun loadChannels(): List<Channel>

Load all channels.

Link copied to clipboard
abstract suspend fun loadConfig(): ConfigBundle?

Load the cached device configuration (all configs, moduleConfigs, myInfo, metadata).

Link copied to clipboard
abstract suspend fun loadHeartbeats(): Map<NodeId, Long>

Load all persisted last-heartbeat timestamps.

Link copied to clipboard
abstract suspend fun loadNodes(): Map<NodeId, NodeInfo>

Load all stored nodes.

Link copied to clipboard
abstract suspend fun loadSessionPasskey(): SessionPasskey?

Load the persisted session passkey, or null if none is stored or the stored entry has expired (per SessionPasskey.expiresAtEpochMs).

Link copied to clipboard
abstract suspend fun recordOwnNode(nodeNum: NodeId, firmwareVersion: String)

Record the local node's NodeNum and firmware version.

Link copied to clipboard
abstract suspend fun removeNode(nodeId: NodeId)

Remove a node from storage.

Link copied to clipboard
abstract suspend fun saveChannels(channels: List<Channel>)

Save all channels atomically.

Link copied to clipboard
abstract suspend fun saveConfig(config: ConfigBundle)

Save the complete device configuration.

Link copied to clipboard
abstract suspend fun saveHeartbeat(nodeId: NodeId, epochMillis: Long)

Persist the engine-observed last-heartbeat timestamp for nodeId.

Link copied to clipboard
abstract suspend fun saveNode(node: NodeInfo)

Save or update a single node.

Link copied to clipboard
abstract suspend fun saveSessionPasskey(passkey: SessionPasskey)

Persist the latched session passkey for this transport identity.