pub struct Store { /* private fields */ }
Expand description
Manages the replicas and authors for an instance.
Implementations§
Source§impl Store
impl Store
Sourcepub fn persistent(path: impl AsRef<Path>) -> Result<Self>
pub fn persistent(path: impl AsRef<Path>) -> Result<Self>
Create or open a store from a path
to a database file.
The file will be created if it does not exist, otherwise it will be opened.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flush the current transaction, if any.
This is the cheapest way to ensure that the data is persisted.
Sourcepub fn snapshot(&mut self) -> Result<&ReadOnlyTables>
pub fn snapshot(&mut self) -> Result<&ReadOnlyTables>
Get a read-only snapshot of the database.
This has the side effect of committing any open write transaction, so it can be used as a way to ensure that the data is persisted.
Sourcepub fn snapshot_owned(&mut self) -> Result<ReadOnlyTables>
pub fn snapshot_owned(&mut self) -> Result<ReadOnlyTables>
Get an owned read-only snapshot of the database.
This will open a new read transaction. The read transaction won’t be reused for other reads.
This has the side effect of committing any open write transaction, so it can be used as a way to ensure that the data is persisted.
Source§impl Store
impl Store
Sourcepub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>>
pub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>>
Create a new replica for namespace
and persist in this store.
Create a new author key and persist it in the store.
Sourcepub fn has_news_for_us(
&mut self,
namespace: NamespaceId,
heads: &AuthorHeads,
) -> Result<Option<NonZeroU64>>
pub fn has_news_for_us( &mut self, namespace: NamespaceId, heads: &AuthorHeads, ) -> Result<Option<NonZeroU64>>
Check if a AuthorHeads
contains entry timestamps that we do not have locally.
Returns the number of authors that the other peer has updates for.
Sourcepub fn open_replica(
&mut self,
namespace_id: &NamespaceId,
) -> Result<Replica<'_>, OpenError>
pub fn open_replica( &mut self, namespace_id: &NamespaceId, ) -> Result<Replica<'_>, OpenError>
Open a replica from this store.
This just calls load_replica_info and then creates a new replica with the info.
Sourcepub fn load_replica_info(
&mut self,
namespace_id: &NamespaceId,
) -> Result<ReplicaInfo, OpenError>
pub fn load_replica_info( &mut self, namespace_id: &NamespaceId, ) -> Result<ReplicaInfo, OpenError>
Load the replica info from the store.
Sourcepub fn close_replica(&mut self, id: NamespaceId)
pub fn close_replica(&mut self, id: NamespaceId)
Close a replica.
Sourcepub fn list_namespaces(
&mut self,
) -> Result<impl Iterator<Item = Result<(NamespaceId, CapabilityKind)>>>
pub fn list_namespaces( &mut self, ) -> Result<impl Iterator<Item = Result<(NamespaceId, CapabilityKind)>>>
List all replica namespaces in this store.
Get an author key from the store.
Import an author key pair.
Delete an author.
List all author keys in this store.
Sourcepub fn import_namespace(
&mut self,
capability: Capability,
) -> Result<ImportNamespaceOutcome>
pub fn import_namespace( &mut self, capability: Capability, ) -> Result<ImportNamespaceOutcome>
Import a new replica namespace.
Sourcepub fn remove_replica(&mut self, namespace: &NamespaceId) -> Result<()>
pub fn remove_replica(&mut self, namespace: &NamespaceId) -> Result<()>
Remove a replica.
Completely removes a replica and deletes both the namespace private key and all document entries.
Note that a replica has to be closed before it can be removed. The store has to enforce that a replica cannot be removed while it is still open.
Sourcepub fn get_many(
&mut self,
namespace: NamespaceId,
query: impl Into<Query>,
) -> Result<QueryIterator>
pub fn get_many( &mut self, namespace: NamespaceId, query: impl Into<Query>, ) -> Result<QueryIterator>
Get an iterator over entries of a replica.
Sourcepub fn get_exact(
&mut self,
namespace: NamespaceId,
author: AuthorId,
key: impl AsRef<[u8]>,
include_empty: bool,
) -> Result<Option<SignedEntry>>
pub fn get_exact( &mut self, namespace: NamespaceId, author: AuthorId, key: impl AsRef<[u8]>, include_empty: bool, ) -> Result<Option<SignedEntry>>
Get an entry by key and author.
Sourcepub fn content_hashes(&mut self) -> Result<ContentHashesIterator>
pub fn content_hashes(&mut self) -> Result<ContentHashesIterator>
Get all content hashes of all replicas in the store.
Get the latest entry for each author in a namespace.
Sourcepub fn register_useful_peer(
&mut self,
namespace: NamespaceId,
peer: PeerIdBytes,
) -> Result<()>
pub fn register_useful_peer( &mut self, namespace: NamespaceId, peer: PeerIdBytes, ) -> Result<()>
Register a peer that has been useful to sync a document.
Sourcepub fn get_sync_peers(
&mut self,
namespace: &NamespaceId,
) -> Result<Option<IntoIter<PeerIdBytes>>>
pub fn get_sync_peers( &mut self, namespace: &NamespaceId, ) -> Result<Option<IntoIter<PeerIdBytes>>>
Get the peers that have been useful for a document.
Sourcepub fn set_download_policy(
&mut self,
namespace: &NamespaceId,
policy: DownloadPolicy,
) -> Result<()>
pub fn set_download_policy( &mut self, namespace: &NamespaceId, policy: DownloadPolicy, ) -> Result<()>
Set the download policy for a namespace.
Sourcepub fn get_download_policy(
&mut self,
namespace: &NamespaceId,
) -> Result<DownloadPolicy>
pub fn get_download_policy( &mut self, namespace: &NamespaceId, ) -> Result<DownloadPolicy>
Get the download policy for a namespace.
Trait Implementations§
Source§impl DownloadPolicyStore for Store
impl DownloadPolicyStore for Store
Source§fn get_download_policy(
&mut self,
namespace: &NamespaceId,
) -> Result<DownloadPolicy>
fn get_download_policy( &mut self, namespace: &NamespaceId, ) -> Result<DownloadPolicy>
Source§impl PublicKeyStore for Store
impl PublicKeyStore for Store
Source§fn public_key(&self, id: &[u8; 32]) -> Result<VerifyingKey, SignatureError>
fn public_key(&self, id: &[u8; 32]) -> Result<VerifyingKey, SignatureError>
VerifyingKey
]. Read more