Struct iota_stronghold::types::Snapshot
source · pub struct Snapshot { /* private fields */ }
Expand description
Wrapper for the SnapshotState
data structure.
Implementations§
source§impl Snapshot
impl Snapshot
sourcepub fn from_state(
state: SnapshotState,
snapshot_key: &Key,
write_key: Option<(VaultId, RecordId)>
) -> Result<Self, SnapshotError>
pub fn from_state( state: SnapshotState, snapshot_key: &Key, write_key: Option<(VaultId, RecordId)> ) -> Result<Self, SnapshotError>
Creates a new Snapshot
from a buffer of SnapshotState
state.
sourcepub fn get_snapshot_state(&self) -> Result<SnapshotState, SnapshotError>
pub fn get_snapshot_state(&self) -> Result<SnapshotState, SnapshotError>
Gets the state component parts as a tuple.
sourcepub fn get_state(&self, id: ClientId) -> Result<ClientState, SnapshotError>
pub fn get_state(&self, id: ClientId) -> Result<ClientState, SnapshotError>
Gets the state component parts as a tuple.
sourcepub fn purge_client(&mut self, id: ClientId) -> Result<(), SnapshotError>
pub fn purge_client(&mut self, id: ClientId) -> Result<(), SnapshotError>
Purges a crate::Client
from the SnapshotState
. The next write to the Snapshot file
will delete the existing crate::Client
.
sourcepub fn has_data(&self, cid: ClientId) -> bool
pub fn has_data(&self, cid: ClientId) -> bool
Checks to see if the ClientId
exists in the snapshot hashmap.
sourcepub fn read_from_snapshot(
snapshot_path: &SnapshotPath,
key: &Key,
write_key: Option<(VaultId, RecordId)>
) -> Result<Self, SnapshotError>
pub fn read_from_snapshot( snapshot_path: &SnapshotPath, key: &Key, write_key: Option<(VaultId, RecordId)> ) -> Result<Self, SnapshotError>
Reads state from the specified named snapshot or the specified path TODO: Add associated data.
sourcepub fn write_to_snapshot(
&self,
snapshot_path: &SnapshotPath,
use_key: UseKey
) -> Result<(), SnapshotError>
pub fn write_to_snapshot( &self, snapshot_path: &SnapshotPath, use_key: UseKey ) -> Result<(), SnapshotError>
Writes state to the specified named snapshot or the specified path TODO: Add associated data.
sourcepub fn add_data(
&mut self,
id: ClientId,
(keys, db, store): (HashMap<VaultId, PKey<Provider>>, DbView<Provider>, Cache<Vec<u8>, Vec<u8>>)
) -> Result<(), SnapshotError>
pub fn add_data( &mut self, id: ClientId, (keys, db, store): (HashMap<VaultId, PKey<Provider>>, DbView<Provider>, Cache<Vec<u8>, Vec<u8>>) ) -> Result<(), SnapshotError>
Adds data to the snapshot state hashmap.
sourcepub fn store_snapshot_key(
&mut self,
snapshot_key: &Key,
vault_id: VaultId,
record_id: RecordId
) -> Result<(), SnapshotError>
pub fn store_snapshot_key( &mut self, snapshot_key: &Key, vault_id: VaultId, record_id: RecordId ) -> Result<(), SnapshotError>
Adds data to the snapshot state hashmap.
sourcepub fn store_secret_key<K>(
&mut self,
encryption_key: K,
location: Location
) -> Result<(), SnapshotError>
pub fn store_secret_key<K>( &mut self, encryption_key: K, location: Location ) -> Result<(), SnapshotError>
Stores a secret crypto::keys::x25519::SecretKey
as bytes at given location.
The stored secret will later be used to decrypt a snapshot
sourcepub fn merge_state(
&mut self,
state: SnapshotState,
config: SyncSnapshotsConfig
) -> Result<(), SnapshotError>
pub fn merge_state( &mut self, state: SnapshotState, config: SyncSnapshotsConfig ) -> Result<(), SnapshotError>
Merge another state into the currently loaded snapshot.
sourcepub fn import_from_serialized_state(
&mut self,
bytes: Vec<u8>,
local_sk: Location,
remote_pk: PublicKey,
config: SyncSnapshotsConfig
) -> Result<(), SnapshotError>
pub fn import_from_serialized_state( &mut self, bytes: Vec<u8>, local_sk: Location, remote_pk: PublicKey, config: SyncSnapshotsConfig ) -> Result<(), SnapshotError>
Deserialize, decompress and decrypt a state received from a remote peer and merge it into the local state.
It expects that a x25519 key exists at local_sk
and that the received snapshot file is encrypted
with a shared key create from the public key of local_sk
and the remote’s secret key.
sourcepub fn export_to_serialized_state(
&self,
select: HashMap<ClientId, HashMap<VaultId, Vec<RecordId>>>,
remote_pk: PublicKey
) -> Result<(PublicKey, Vec<u8>), SnapshotError>
pub fn export_to_serialized_state( &self, select: HashMap<ClientId, HashMap<VaultId, Vec<RecordId>>>, remote_pk: PublicKey ) -> Result<(PublicKey, Vec<u8>), SnapshotError>
Export the given hierarchy from the loaded state to a blank SnapshotState
.
Serialize, compress and encrypt the state so it can be sent to a remote peer.
The snapshot is encrypted with a shared key that is created in a handshake between
the local secret key at local_sk
and the remote public key remote_pk
.