Struct iota_stronghold::types::Snapshot

source ·
pub struct Snapshot { /* private fields */ }
Expand description

Wrapper for the SnapshotState data structure.

Implementations§

source§

impl Snapshot

source

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.

source

pub fn get_snapshot_state(&self) -> Result<SnapshotState, SnapshotError>

Gets the state component parts as a tuple.

source

pub fn get_state(&self, id: ClientId) -> Result<ClientState, SnapshotError>

Gets the state component parts as a tuple.

source

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.

source

pub fn has_data(&self, cid: ClientId) -> bool

Checks to see if the ClientId exists in the snapshot hashmap.

source

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.

source

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.

source

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.

source

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.

source

pub fn store_secret_key<K>( &mut self, encryption_key: K, location: Location ) -> Result<(), SnapshotError>
where K: AsRef<[u8]> + AsMut<[u8]> + Zeroize,

Stores a secret crypto::keys::x25519::SecretKey as bytes at given location. The stored secret will later be used to decrypt a snapshot

source

pub fn merge_state( &mut self, state: SnapshotState, config: SyncSnapshotsConfig ) -> Result<(), SnapshotError>

Merge another state into the currently loaded snapshot.

source

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.

source

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.

Trait Implementations§

source§

impl Default for Snapshot

source§

fn default() -> Snapshot

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V