pub struct DistributedMessageSet<S, M> { /* private fields */ }Implementations§
Source§impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>
impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>
Sourcepub async fn fetch(
this: Arc<RwLock<Self>>,
network_config: &ClientNetworkConfig,
) -> Result<(), Error>
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.
Sourcepub async fn broadcast(
this: Arc<RwLock<Self>>,
network_config: &ClientNetworkConfig,
) -> Result<(), Error>
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)
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>
impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>
Sourcepub async fn serve(
dms: Arc<RwLock<DistributedMessageSet<S, M>>>,
network_config: ServerNetworkConfig,
) -> Result<(), Error>
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§impl<S: Storage, M: DmsMessage> DistributedMessageSet<S, M>
A cumulative set that is shared in the p2p network, backed by the local file system.
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 willawaituntil the lock is released. - It takes ‘Arc<RwLock
>’ instead of selfif network clients are used.
TODO: add read only type that does not require the private key.
Sourcepub async fn new(
storage: S,
config: Config,
private_key: PrivateKey,
) -> Result<Self, Error>
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.
Sourcepub fn get_storage(&self) -> Arc<RwLock<S>>
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-.
pub fn get_config(&self) -> Config
pub async fn clear(&mut self) -> Result<(), Error>
Sourcepub async fn read_messages(&self) -> Result<Vec<Message<M>>, Error>
pub async fn read_messages(&self) -> Result<Vec<Message<M>>, Error>
Reads the messages from the storage.