Struct iroh_sync::sync::Replica

source ·
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>

source

pub fn new(namespace: Namespace, store: S) -> Self

Create a new replica.

source

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.

source

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.

source

pub fn subscribers_count(&self) -> usize

Get the number of current event subscribers.

source

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.

source

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

source

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.

source

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.

source

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.

source

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.

source

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

Get the identifier for an entry in this replica.

source

pub fn sync_initial_message(&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 namespace(&self) -> NamespaceId

Get the namespace identifier for this Replica.

source

pub fn secret_key(&self) -> Namespace

Get the byte represenation of the Namespace key for this replica.

Trait Implementations§

source§

impl<S: Store<SignedEntry> + PublicKeyStore> Debug for Replica<S>
where Namespace: Debug, Peer<SignedEntry, S>: Debug, Subscribers: Debug, bool: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Replica<S>

§

impl<S> Send for Replica<S>
where S: Send,

§

impl<S> Sync for Replica<S>
where S: Sync,

§

impl<S> Unpin for Replica<S>
where S: Unpin,

§

impl<S> !UnwindSafe for Replica<S>

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.

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

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