pub struct PersistedState {
pub version: u32,
pub persisted_at_ms: u64,
/* private fields */
}Expand description
Complete persisted state for a HIVE node.
Contains all security-critical data needed to restore a node after reboot without network access.
Fields§
§version: u32Format version for migration support
persisted_at_ms: u64Timestamp when state was last persisted
Implementations§
Source§impl PersistedState
impl PersistedState
Sourcepub fn new(identity: &DeviceIdentity, genesis: Option<&MeshGenesis>) -> Self
pub fn new(identity: &DeviceIdentity, genesis: Option<&MeshGenesis>) -> Self
Create a new persisted state from components.
Sourcepub fn with_registry(
identity: &DeviceIdentity,
genesis: Option<&MeshGenesis>,
registry: &IdentityRegistry,
) -> Self
pub fn with_registry( identity: &DeviceIdentity, genesis: Option<&MeshGenesis>, registry: &IdentityRegistry, ) -> Self
Create persisted state with an existing identity registry.
Sourcepub fn restore_identity(&self) -> Result<DeviceIdentity, PersistenceError>
pub fn restore_identity(&self) -> Result<DeviceIdentity, PersistenceError>
Restore the device identity from persisted state.
Sourcepub fn restore_genesis(&self) -> Option<MeshGenesis>
pub fn restore_genesis(&self) -> Option<MeshGenesis>
Restore the mesh genesis from persisted state.
Sourcepub fn restore_registry(&self) -> IdentityRegistry
pub fn restore_registry(&self) -> IdentityRegistry
Restore the identity registry from persisted state.
Sourcepub fn revoked_keys(&self) -> &[[u8; 32]]
pub fn revoked_keys(&self) -> &[[u8; 32]]
Get the list of revoked public keys.
Sourcepub fn add_revoked_key(&mut self, public_key: [u8; 32])
pub fn add_revoked_key(&mut self, public_key: [u8; 32])
Add a revoked public key.
Sourcepub fn update_registry(&mut self, registry: &IdentityRegistry)
pub fn update_registry(&mut self, registry: &IdentityRegistry)
Update the identity registry data.
Sourcepub fn save(&self, storage: &dyn SecureStorage) -> Result<(), PersistenceError>
pub fn save(&self, storage: &dyn SecureStorage) -> Result<(), PersistenceError>
Save state to secure storage.
The storage key used is “hive_persisted_state”.
Sourcepub fn load(storage: &dyn SecureStorage) -> Result<Self, PersistenceError>
pub fn load(storage: &dyn SecureStorage) -> Result<Self, PersistenceError>
Load state from secure storage.
Returns Err(NotFound) if no state has been persisted.
Sourcepub fn delete(storage: &dyn SecureStorage) -> Result<(), PersistenceError>
pub fn delete(storage: &dyn SecureStorage) -> Result<(), PersistenceError>
Delete persisted state from storage.
Use with caution - this will require re-provisioning.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode the state to bytes.
Format:
- Magic (4 bytes): “HIVE”
- Version (4 bytes): u32 LE
- Private key (32 bytes)
- Persisted at (8 bytes): u64 LE timestamp
- Genesis length (4 bytes): u32 LE (0 if none)
- Genesis data (N bytes)
- Registry length (4 bytes): u32 LE
- Registry data (N bytes)
- Revoked count (4 bytes): u32 LE
- Revoked keys (32 bytes each)
Sourcepub fn decode(data: &[u8]) -> Result<Self, PersistenceError>
pub fn decode(data: &[u8]) -> Result<Self, PersistenceError>
Decode state from bytes.
Sourcepub fn set_persisted_at(&mut self, timestamp_ms: u64)
pub fn set_persisted_at(&mut self, timestamp_ms: u64)
Set the persistence timestamp.
Trait Implementations§
Source§impl Clone for PersistedState
impl Clone for PersistedState
Source§fn clone(&self) -> PersistedState
fn clone(&self) -> PersistedState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more