Struct swarm_nl::core::Core

source ·
pub struct Core<T: EventHandler + Clone + Send + Sync + 'static> {
    pub state: Arc<Mutex<T>>,
    /* private fields */
}
Expand description

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

Fields§

§state: Arc<Mutex<T>>

The state of the application

Implementations§

source§

impl<T: EventHandler + Clone + Send + Sync + 'static> Core<T>

source

pub fn save_keypair_offline(&self, config_file_path: &str) -> 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 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

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

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.

Trait Implementations§

source§

impl<T: Clone + EventHandler + Clone + Send + Sync + 'static> Clone for Core<T>

source§

fn clone(&self) -> Core<T>

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<T> Freeze for Core<T>

§

impl<T> !RefUnwindSafe for Core<T>

§

impl<T> Send for Core<T>

§

impl<T> Sync for Core<T>

§

impl<T> Unpin for Core<T>

§

impl<T> !UnwindSafe for Core<T>

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

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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