swarm_nl::core

Struct Core

Source
pub struct Core { /* private fields */ }
Expand description

The core interface for the application layer to interface with the networking layer.

Implementations§

Source§

impl Core

Source

pub const GOSSIP_MESSAGE_SEPARATOR: &'static str = "~~##~~"

The delimeter that separates the messages to gossip.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const FIELD_DELIMITER: &'static str = "_@_"

The delimeter between the data fields of an entry in a dataset requested by a replica peer.

Source

pub const ENTRY_DELIMITER: &'static str = "@@@"

The delimeter between the data entries that has been requested by a replica peer.

Source

pub const DATA_DELIMITER: &'static str = "$$"

The delimeter to separate messages during RPC data marshalling

Source

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.

Source

pub fn peer_id(&self) -> PeerId

Return the node’s PeerId.

Source

pub async fn events(&mut self) -> IntoIter<NetworkEvent>

Return an iterator to the buffered network layer events and consume them.

Source

pub async fn next_event(&mut self) -> Option<NetworkEvent>

Return the next event in the network event queue.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn consume_repl_data( &mut self, replica_network: &str, ) -> Option<ReplBufferData>

Consume data in replication buffer.

Source

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.

Source

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.

Source

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.

Source

pub async fn replicate( &mut self, replica_data: ByteVector, replica_network: &str, ) -> NetworkResult<()>

Send data to replica nodes.

Trait Implementations§

Source§

impl Clone for Core

Source§

fn clone(&self) -> Core

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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§

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

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T