iroh_docs::store::fs

Struct Store

Source
pub struct Store { /* private fields */ }
Expand description

Manages the replicas and authors for an instance.

Implementations§

Source§

impl Store

Source

pub fn memory() -> Self

Create a new store in memory.

Source

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.

Source

pub fn flush(&mut self) -> Result<()>

Flush the current transaction, if any.

This is the cheapest way to ensure that the data is persisted.

Source

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.

Source

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

Source

pub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>>

Create a new replica for namespace and persist in this store.

Source

pub fn new_author<R: CryptoRngCore + ?Sized>( &mut self, rng: &mut R, ) -> Result<Author>

Create a new author key and persist it in the store.

Source

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.

Source

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.

Source

pub fn load_replica_info( &mut self, namespace_id: &NamespaceId, ) -> Result<ReplicaInfo, OpenError>

Load the replica info from the store.

Source

pub fn close_replica(&mut self, id: NamespaceId)

Close a replica.

Source

pub fn list_namespaces( &mut self, ) -> Result<impl Iterator<Item = Result<(NamespaceId, CapabilityKind)>>>

List all replica namespaces in this store.

Source

pub fn get_author(&mut self, author_id: &AuthorId) -> Result<Option<Author>>

Get an author key from the store.

Source

pub fn import_author(&mut self, author: Author) -> Result<()>

Import an author key pair.

Source

pub fn delete_author(&mut self, author: AuthorId) -> Result<()>

Delete an author.

Source

pub fn list_authors(&mut self) -> Result<impl Iterator<Item = Result<Author>>>

List all author keys in this store.

Source

pub fn import_namespace( &mut self, capability: Capability, ) -> Result<ImportNamespaceOutcome>

Import a new replica namespace.

Source

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.

Source

pub fn get_many( &mut self, namespace: NamespaceId, query: impl Into<Query>, ) -> Result<QueryIterator>

Get an iterator over entries of a replica.

Source

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.

Source

pub fn content_hashes(&mut self) -> Result<ContentHashesIterator>

Get all content hashes of all replicas in the store.

Source

pub fn get_latest_for_each_author( &mut self, namespace: NamespaceId, ) -> Result<LatestIterator<'_>>

Get the latest entry for each author in a namespace.

Source

pub fn register_useful_peer( &mut self, namespace: NamespaceId, peer: PeerIdBytes, ) -> Result<()>

Register a peer that has been useful to sync a document.

Source

pub fn get_sync_peers( &mut self, namespace: &NamespaceId, ) -> Result<Option<IntoIter<PeerIdBytes>>>

Get the peers that have been useful for a document.

Source

pub fn set_download_policy( &mut self, namespace: &NamespaceId, policy: DownloadPolicy, ) -> Result<()>

Set the download policy for a namespace.

Source

pub fn get_download_policy( &mut self, namespace: &NamespaceId, ) -> Result<DownloadPolicy>

Get the download policy for a namespace.

Trait Implementations§

Source§

impl AsMut<Store> for Store

Source§

fn as_mut(&mut self) -> &mut Store

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Store> for Store

Source§

fn as_ref(&self) -> &Store

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DownloadPolicyStore for Store

Source§

fn get_download_policy( &mut self, namespace: &NamespaceId, ) -> Result<DownloadPolicy>

Get the download policy for a document.
Source§

impl Drop for Store

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PublicKeyStore for Store

Source§

fn public_key(&self, id: &[u8; 32]) -> Result<VerifyingKey, SignatureError>

Convert a byte array into a [VerifyingKey]. Read more
Source§

fn namespace_key( &self, bytes: &NamespaceId, ) -> Result<NamespacePublicKey, SignatureError>

Source§

fn author_key( &self, bytes: &AuthorId, ) -> Result<AuthorPublicKey, SignatureError>

Auto Trait Implementations§

§

impl Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T