pub struct Replica<'a, I = Box<ReplicaInfo>> { /* private fields */ }Expand description
Local representation of a mutable, synchronizable key-value store.
Implementations§
Source§impl<'a, I> Replica<'a, I>
impl<'a, I> Replica<'a, I>
Sourcepub fn new(store: StoreInstance<'a>, info: I) -> Self
pub fn new(store: StoreInstance<'a>, info: I) -> Self
Create a new replica.
Sourcepub fn insert(
&mut self,
key: impl AsRef<[u8]>,
author: &Author,
hash: Hash,
len: u64,
) -> Result<usize, InsertError>
pub fn insert( &mut self, key: impl AsRef<[u8]>, author: &Author, hash: Hash, len: u64, ) -> Result<usize, InsertError>
Insert a new record at the given key.
The entry will by signed by the provided author.
The len must be the byte length of the data identified by hash.
Returns the number of entries removed as a consequence of this insertion, or an error either if the entry failed to validate or if a store operation failed.
Sourcepub fn delete_prefix(
&mut self,
prefix: impl AsRef<[u8]>,
author: &Author,
) -> Result<usize, InsertError>
pub fn delete_prefix( &mut self, prefix: impl AsRef<[u8]>, author: &Author, ) -> Result<usize, InsertError>
Delete entries that match the given author and key prefix.
This inserts an empty entry with the key set to prefix, effectively clearing all other
entries whose key starts with or is equal to the given prefix.
Returns the number of entries deleted.
Sourcepub fn insert_remote_entry(
&mut self,
entry: SignedEntry,
received_from: PeerIdBytes,
content_status: ContentStatus,
) -> Result<usize, InsertError>
pub fn insert_remote_entry( &mut self, entry: SignedEntry, received_from: PeerIdBytes, content_status: ContentStatus, ) -> Result<usize, InsertError>
Insert an entry into this replica which was received from a remote peer.
This will verify both the namespace and author signatures of the entry, emit an on_insert
event, and insert the entry into the replica store.
Returns the number of entries removed as a consequence of this insertion, or an error if the entry failed to validate or if a store operation failed.
Sourcepub fn hash_and_insert(
&mut self,
key: impl AsRef<[u8]>,
author: &Author,
data: impl AsRef<[u8]>,
) -> Result<Hash, InsertError>
pub fn hash_and_insert( &mut self, key: impl AsRef<[u8]>, author: &Author, data: impl AsRef<[u8]>, ) -> Result<Hash, InsertError>
Hashes the given data and inserts it.
This does not store the content, just the record of it. Returns the calculated hash.
Sourcepub fn record_id(
&self,
key: impl AsRef<[u8]>,
author: &Author,
) -> RecordIdentifier
pub fn record_id( &self, key: impl AsRef<[u8]>, author: &Author, ) -> RecordIdentifier
Get the identifier for an entry in this replica.
Sourcepub fn sync_initial_message(&mut self) -> Result<Message<SignedEntry>>
pub fn sync_initial_message(&mut self) -> Result<Message<SignedEntry>>
Create the initial message for the set reconciliation flow with a remote peer.
Sourcepub fn sync_process_message(
&mut self,
message: Message<SignedEntry>,
from_peer: PeerIdBytes,
state: &mut SyncOutcome,
) -> Result<Option<Message<SignedEntry>>, Error>
pub fn sync_process_message( &mut self, message: Message<SignedEntry>, from_peer: PeerIdBytes, state: &mut SyncOutcome, ) -> Result<Option<Message<SignedEntry>>, Error>
Process a set reconciliation message from a remote peer.
Returns the next message to be sent to the peer, if any.
Sourcepub fn id(&self) -> NamespaceId
pub fn id(&self) -> NamespaceId
Get the namespace identifier for this Replica.
Sourcepub fn capability(&self) -> &Capability
pub fn capability(&self) -> &Capability
Get the Capability of this Replica.
Sourcepub fn secret_key(&self) -> Result<&NamespaceSecret, ReadOnly>
pub fn secret_key(&self) -> Result<&NamespaceSecret, ReadOnly>
Get the byte representation of the NamespaceSecret key for this replica. Will fail if
the replica is read only