iroh_docs::sync

Struct Replica

Source
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>
where I: Deref<Target = ReplicaInfo> + DerefMut,

Source

pub fn new(store: StoreInstance<'a>, info: I) -> Self

Create a new replica.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn record_id( &self, key: impl AsRef<[u8]>, author: &Author, ) -> RecordIdentifier

Get the identifier for an entry in this replica.

Source

pub fn sync_initial_message(&mut self) -> Result<Message<SignedEntry>>

Create the initial message for the set reconciliation flow with a remote peer.

Source

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.

Source

pub fn id(&self) -> NamespaceId

Get the namespace identifier for this Replica.

Source

pub fn capability(&self) -> &Capability

Get the Capability of this Replica.

Source

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

Trait Implementations§

Source§

impl<'a, I> Debug for Replica<'a, I>
where I: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, I> Freeze for Replica<'a, I>
where I: Freeze,

§

impl<'a, I = Box<ReplicaInfo>> !RefUnwindSafe for Replica<'a, I>

§

impl<'a, I> Send for Replica<'a, I>
where I: Send,

§

impl<'a, I> Sync for Replica<'a, I>
where I: Sync,

§

impl<'a, I> Unpin for Replica<'a, I>
where I: Unpin,

§

impl<'a, I = Box<ReplicaInfo>> !UnwindSafe for Replica<'a, I>

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