pub struct Core { /* private fields */ }
Expand description
The core interface for the application layer to interface with the networking layer.
Implementations§
Source§impl Core
impl Core
Sourcepub const GOSSIP_MESSAGE_SEPARATOR: &'static str = "~~##~~"
pub const GOSSIP_MESSAGE_SEPARATOR: &'static str = "~~##~~"
The delimeter that separates the messages to gossip.
Sourcepub const REPL_GOSSIP_FLAG: &'static str = "REPL_GOSSIP_FLAG__@@"
pub const REPL_GOSSIP_FLAG: &'static str = "REPL_GOSSIP_FLAG__@@"
The gossip flag to indicate that incoming gossipsub message is actually data sent for replication.
Sourcepub const RPC_DATA_FORWARDING_FLAG: &'static str = "RPC_DATA_FORWARDING_FLAG__@@"
pub const RPC_DATA_FORWARDING_FLAG: &'static str = "RPC_DATA_FORWARDING_FLAG__@@"
The RPC flag to indicate that incoming message is data that has been forwarded to the node because it is a member of the logical shard to store the data.
Sourcepub const STRONG_CONSISTENCY_FLAG: &'static str = "STRONG_CON__@@"
pub const STRONG_CONSISTENCY_FLAG: &'static str = "STRONG_CON__@@"
The gossip flag to indicate that incoming (or outgoing) gossipsub message is a part of the strong consistency algorithm, intending to increase the confirmation count of a particular data item in the replicas temporary buffer.
Sourcepub const EVENTUAL_CONSISTENCY_FLAG: &'static str = "EVENTUAL_CON_@@"
pub const EVENTUAL_CONSISTENCY_FLAG: &'static str = "EVENTUAL_CON_@@"
The gossip flag to indicate that incoming (or outgoing) gossipsub message is a part of the eventual consistency algorithm seeking to synchronize data across nodes.
Sourcepub const RPC_SYNC_PULL_FLAG: &'static str = "RPC_SYNC_PULL_FLAG__@@"
pub const RPC_SYNC_PULL_FLAG: &'static str = "RPC_SYNC_PULL_FLAG__@@"
The RPC flag to pull missing data from a replica node for eventual consistency synchronization.
Sourcepub const SHARD_RPC_SYNC_FLAG: &'static str = "SHARD_RPC_SYNC_FLAG__@@"
pub const SHARD_RPC_SYNC_FLAG: &'static str = "SHARD_RPC_SYNC_FLAG__@@"
The RPC flag to update the shard network state of a joining node.
Sourcepub const SHARD_GOSSIP_JOIN_FLAG: &'static str = "SHARD_GOSSIP_JOIN_FLAG__@@"
pub const SHARD_GOSSIP_JOIN_FLAG: &'static str = "SHARD_GOSSIP_JOIN_FLAG__@@"
The sharding gossip flag to indicate that a node has joined a shard network.
Sourcepub const SHARD_GOSSIP_EXIT_FLAG: &'static str = "SHARD_GOSSIP_EXIT_FLAG__@@"
pub const SHARD_GOSSIP_EXIT_FLAG: &'static str = "SHARD_GOSSIP_EXIT_FLAG__@@"
The sharding gossip flag to indicate that a node has exited a shard network.
Sourcepub const SHARD_RPC_REQUEST_FLAG: &'static str = "SHARD_RPC_REQUEST_FLAG__@@"
pub const SHARD_RPC_REQUEST_FLAG: &'static str = "SHARD_RPC_REQUEST_FLAG__@@"
The RPC flag to request a data from a node in a logical shard.
Sourcepub const FIELD_DELIMITER: &'static str = "_@_"
pub const FIELD_DELIMITER: &'static str = "_@_"
The delimeter between the data fields of an entry in a dataset requested by a replica peer.
Sourcepub const ENTRY_DELIMITER: &'static str = "@@@"
pub const ENTRY_DELIMITER: &'static str = "@@@"
The delimeter between the data entries that has been requested by a replica peer.
Sourcepub const DATA_DELIMITER: &'static str = "$$"
pub const DATA_DELIMITER: &'static str = "$$"
The delimeter to separate messages during RPC data marshalling
Sourcepub fn save_keypair_offline<T: AsRef<Path> + ?Sized>(
&self,
config_file_path: &T,
) -> bool
pub fn save_keypair_offline<T: AsRef<Path> + ?Sized>( &self, config_file_path: &T, ) -> bool
Serialize keypair to protobuf format and write to config file on disk. This could be useful for saving a keypair for future use when going offline.
It returns a boolean to indicate success of operation. Only key types other than RSA can be serialized to protobuf format and only a single keypair can be saved at a time.
Sourcepub async fn events(&mut self) -> IntoIter<NetworkEvent>
pub async fn events(&mut self) -> IntoIter<NetworkEvent>
Return an iterator to the buffered network layer events and consume them.
Sourcepub async fn next_event(&mut self) -> Option<NetworkEvent>
pub async fn next_event(&mut self) -> Option<NetworkEvent>
Return the next event in the network event queue.
Sourcepub async fn replica_peers(&mut self, replica_network: &str) -> Vec<PeerId>
pub async fn replica_peers(&mut self, replica_network: &str) -> Vec<PeerId>
Return the number of replica peers in a network, with the node exclusive.
Sourcepub async fn send_to_network(
&mut self,
app_request: AppData,
) -> Option<StreamId>
pub async fn send_to_network( &mut self, app_request: AppData, ) -> Option<StreamId>
Send data to the network layer and recieve a unique StreamId
to track the request.
If the internal stream buffer is full, None
will be returned.
Sourcepub async fn recv_from_network(
&mut self,
stream_id: StreamId,
) -> NetworkResult<AppResponse>
pub async fn recv_from_network( &mut self, stream_id: StreamId, ) -> NetworkResult<AppResponse>
Explicitly retrieve the reponse to a request sent to the network layer.
This function is decoupled from the Core::send_to_network()
method so as to prevent
blocking until the response is returned.
Sourcepub async fn query_network(
&mut self,
request: AppData,
) -> NetworkResult<AppResponse>
pub async fn query_network( &mut self, request: AppData, ) -> NetworkResult<AppResponse>
Perform an atomic send
and recieve
to and from the network layer. This function is
atomic and blocks until the result of the request is returned from the network layer.
This function should mostly be used when the result of the request is needed immediately and delay can be condoned. It will still timeout if the delay exceeds the configured period.
If the internal buffer is full, it will return an error.
Sourcepub async fn consume_repl_data(
&mut self,
replica_network: &str,
) -> Option<ReplBufferData>
pub async fn consume_repl_data( &mut self, replica_network: &str, ) -> Option<ReplBufferData>
Consume data in replication buffer.
Sourcepub async fn join_repl_network(
&mut self,
repl_network: String,
) -> NetworkResult<()>
pub async fn join_repl_network( &mut self, repl_network: String, ) -> NetworkResult<()>
Join a replica network and get up to speed with the current network data state.
If the consistency model is eventual, the node’s buffer will almost immediately be up to
date. But if the consistency model is strong, Core::replicate_buffer
must be called to
update the buffer.
Sourcepub async fn leave_repl_network(
&mut self,
repl_network: String,
) -> NetworkResult<AppResponse>
pub async fn leave_repl_network( &mut self, repl_network: String, ) -> NetworkResult<AppResponse>
Leave a replica network. The messages on the internal replica queue are not discarded so as to aid speedy recorvery in case of reconnection.
Sourcepub async fn replicate_buffer(
&self,
repl_network: String,
replica_node: PeerId,
) -> Result<(), NetworkError>
pub async fn replicate_buffer( &self, repl_network: String, replica_node: PeerId, ) -> Result<(), NetworkError>
Clone a replica node’s current buffer image. This is necessary in case of joining a replica network with a strong consistency model.
Sourcepub async fn replicate(
&mut self,
replica_data: ByteVector,
replica_network: &str,
) -> NetworkResult<()>
pub async fn replicate( &mut self, replica_data: ByteVector, replica_network: &str, ) -> NetworkResult<()>
Send data to replica nodes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Core
impl !RefUnwindSafe for Core
impl Send for Core
impl Sync for Core
impl Unpin for Core
impl !UnwindSafe for Core
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more