DistributedMessageSet

Struct DistributedMessageSet 

Source
pub struct DistributedMessageSet<S, M> { /* private fields */ }

Implementations§

Source§

impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>

Source

pub async fn fetch( this: Arc<RwLock<Self>>, network_config: &ClientNetworkConfig, ) -> Result<(), Error>

Fetches unknown messages from the peers using an RPC protocol, and adds them to the local storage.

Source

pub async fn broadcast( this: Arc<RwLock<Self>>, network_config: &ClientNetworkConfig, ) -> Result<(), Error>

Tries to broadcast all the message that this DMS instance has.

Note: this function may take just &self due to its simple implementation, but keeps Arc<RwLock<Self>> to make sure the interface to indicate that this is a network-involved method (unlike others)

Source

pub async fn get_peer_status( this: Arc<RwLock<Self>>, network_config: &ClientNetworkConfig, ) -> Result<Vec<PeerStatus>, Error>

Source§

impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>

Source

pub async fn serve( dms: Arc<RwLock<DistributedMessageSet<S, M>>>, network_config: ServerNetworkConfig, ) -> Result<(), Error>

Runs a DMS server. This function will block the current thread.

Source

pub async fn sync( dms: Arc<RwLock<DistributedMessageSet<S, M>>>, fetch_interval: Option<Duration>, broadcast_interval: Option<Duration>, network_config: ClientNetworkConfig, ) -> Result<(), Error>

Runs a DMS client with auto-sync. This function will block the current thread.

Source§

impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>

A cumulative set that is shared in the p2p network, backed by the local file system.

One of the notable characteristics of blockchain is that it is based on heights; The key idea here is that we retain an instance (both in memory or on disk) of DistributedMessageSet only for a specific height, and discard it if the height progresses, creating a new and empty one again.

Note that this struct represents only the client side. The server side is implemented in [serve()].

For every method,

  • It locks the storage.
  • If the given directory is locked (possibly by another instance of DistributedMessageSet), it will await until the lock is released.
  • It takes ‘Arc<RwLock>’ instead of self if network clients are used.

TODO: add read only type that does not require the private key.

Source

pub async fn new( storage: S, config: Config, private_key: PrivateKey, ) -> Result<Self, Error>

Creates a message set instance.

If the storage is empty, it creates a new one. If not, check the dms_key with the stored one. It loads the storage if the dms_key is the same. It clears all and initializes a new one if not.

  • private_key: The private key for signing messages.
Source

pub fn get_storage(&self) -> Arc<RwLock<S>>

Returns the underlying storage.

This is useful for when you want to store some additional data under the same file lock that this DMS uses.

Note that you MUST NOT create or access files that start with message-.

Source

pub fn get_config(&self) -> Config

Source

pub async fn clear(&mut self) -> Result<(), Error>

Source

pub async fn read_messages(&self) -> Result<Vec<Message<M>>, Error>

Reads the messages from the storage.

Source

pub async fn query_message( &self, message_hash: Hash256, ) -> Result<Option<Message<M>>, Error>

Source

pub async fn commit_message(&mut self, message: &M) -> Result<(), Error>

Signs the given message and adds it to the storage.

Source

pub async fn remove_message( &mut self, message_hash: Hash256, _permanent: Option<String>, ) -> Result<(), Error>

Removes the message from the storage. If permanent is Some with the reason, it permanently rejects the message.

Trait Implementations§

Source§

impl<S, M> Debug for DistributedMessageSet<S, M>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, M> Freeze for DistributedMessageSet<S, M>

§

impl<S, M> !RefUnwindSafe for DistributedMessageSet<S, M>

§

impl<S, M> Send for DistributedMessageSet<S, M>
where M: Send, S: Send + Sync,

§

impl<S, M> Sync for DistributedMessageSet<S, M>
where M: Sync, S: Send + Sync,

§

impl<S, M> Unpin for DistributedMessageSet<S, M>
where M: Unpin,

§

impl<S, M> !UnwindSafe for DistributedMessageSet<S, M>

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

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

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

Source§

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> ErasedDestructor for T
where T: 'static,