pub struct Replica<S: Store<SignedEntry> + PublicKeyStore> { /* private fields */ }Expand description
Local representation of a mutable, synchronizable key-value store.
Implementations§
source§impl<S: Store<SignedEntry> + PublicKeyStore + 'static> Replica<S>
impl<S: Store<SignedEntry> + PublicKeyStore + 'static> Replica<S>
sourcepub fn subscribe(&mut self, sender: Sender<Event>)
pub fn subscribe(&mut self, sender: Sender<Event>)
Subcribe to insert events.
When subscribing to a replica, you must ensure that the corresponding flume::Receiver is
received from in a loop. If not receiving, local and remote inserts will hang waiting for
the receiver to be received from.
sourcepub fn unsubscribe(&mut self, sender: &Sender<Event>)
pub fn unsubscribe(&mut self, sender: &Sender<Event>)
Explicitly unsubscribe a sender.
Simply dropping the receiver is fine too. If you cloned a single sender to subscribe to multiple replicas, you can use this method to explicitly unsubscribe the sender from this replica without having to drop the receiver.
sourcepub fn subscribers_count(&self) -> usize
pub fn subscribers_count(&self) -> usize
Get the number of current event subscribers.
sourcepub fn set_content_status_callback(&mut self, cb: ContentStatusCallback) -> bool
pub fn set_content_status_callback(&mut self, cb: ContentStatusCallback) -> bool
Set the content status callback.
Only one callback can be active at a time. If a previous callback was registered, this
will return false.
sourcepub fn closed(&self) -> bool
pub fn closed(&self) -> bool
Returns true if the replica is closed.
If a replica is closed, no further operations can be performed. A replica cannot be closed
manually, it must be closed via store::Store::close_replica or
store::Store::remove_replica
sourcepub fn insert(
&mut self,
key: impl AsRef<[u8]>,
author: &Author,
hash: Hash,
len: u64
) -> Result<usize, InsertError<S>>
pub fn insert( &mut self, key: impl AsRef<[u8]>, author: &Author, hash: Hash, len: u64 ) -> Result<usize, InsertError<S>>
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<S>>
pub fn delete_prefix( &mut self, prefix: impl AsRef<[u8]>, author: &Author ) -> Result<usize, InsertError<S>>
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<S>>
pub fn insert_remote_entry( &mut self, entry: SignedEntry, received_from: PeerIdBytes, content_status: ContentStatus ) -> Result<usize, InsertError<S>>
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>
pub fn hash_and_insert( &mut self, key: impl AsRef<[u8]>, author: &Author, data: impl AsRef<[u8]> ) -> Result<Hash>
Hashes the given data and inserts it.
This does not store the content, just the record of it. Returns the calculated hash.
sourcepub fn id(&self, key: impl AsRef<[u8]>, author: &Author) -> RecordIdentifier
pub fn id(&self, key: impl AsRef<[u8]>, author: &Author) -> RecordIdentifier
Get the identifier for an entry in this replica.
sourcepub fn sync_initial_message(&self) -> Result<Message<SignedEntry>>
pub fn sync_initial_message(&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 namespace(&self) -> NamespaceId
pub fn namespace(&self) -> NamespaceId
Get the namespace identifier for this Replica.
sourcepub fn secret_key(&self) -> Namespace
pub fn secret_key(&self) -> Namespace
Get the byte represenation of the Namespace key for this replica.