Struct rings_core::swarm::Swarm

source ·
pub struct Swarm { /* private fields */ }
Expand description

The transport and dht management.

Implementations§

source§

impl Swarm

source

pub async fn record_sent(&self, did: Did)

Record a succeeded message sent

source

pub async fn record_sent_failed(&self, did: Did)

Record a failed message sent

source

pub async fn behaviour_good(&self, did: Did) -> bool

Check that a Did is behaviour good

source

pub async fn new_connection(&self, did: Did) -> Result<Connection>

Create new connection that will be handled by swarm.

source

pub async fn get_and_check_connection(&self, did: Did) -> Option<Connection>

Get connection by did and check if it is connected.

source

pub fn get_connection(&self, did: Did) -> Option<Connection>

Get connection by did.

source

pub fn get_connections(&self) -> Vec<(Did, Connection)>

Get all connections in transport.

source

pub fn get_connection_ids(&self) -> Vec<Did>

Get dids of all connections in transport.

source§

impl Swarm

source

pub fn did(&self) -> Did

Get did of self.

source

pub fn dht(&self) -> Arc<PeerRing>

Get DHT(Distributed Hash Table) of self.

source

pub fn session_sk(&self) -> &SessionSk

Retrieves the session sk associated with the current instance. The session sk provides a segregated approach to manage private keys. It generates session secret keys for the bound entries of PKIs (Public Key Infrastructure).

source

pub async fn poll_message(&self) -> Option<MessagePayload<Message>>

This method is required because web-sys components is not Send which means an async loop cannot running concurrency.

source

pub async fn listen_once( &self ) -> Option<(MessagePayload<Message>, Vec<MessageHandlerEvent>)>

This method is required because web-sys components is not Send This method will return events already consumed (landed), which is ok to be ignore. which means a listening loop cannot running concurrency.

source

pub async fn handle_message_handler_event( &self, event: &MessageHandlerEvent ) -> Result<Vec<MessageHandlerEvent>>

Event handler of Swarm.

source

pub fn handle_message_handler_events<'life0, 'life_self, 'async_recursion>( &'life_self self, events: &'life0 Vec<MessageHandlerEvent> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_recursion>>where 'life0: 'async_recursion, 'life_self: 'async_recursion,

Batch handle events

source

pub async fn disconnect(&self, did: Did) -> Result<()>

Disconnect a connection. There are three steps:

  1. remove from DHT;
  2. remove from Transport;
  3. close the connection;
source

pub async fn connect(&self, did: Did) -> Result<Connection>

Connect a given Did. If the did is already connected, return directly, else try prepare offer and establish connection by dht. This function may returns a pending connection or connected connection.

source

pub async fn connect_via(&self, did: Did, next_hop: Did) -> Result<Connection>

Similar to connect, but this function will try connect a Did by given hop.

source

pub async fn inspect(&self) -> SwarmInspect

Check the status of swarm

source§

impl Swarm

source

pub async fn listen(self: Arc<Self>)

Listener for native envirement, It will just launch a loop.

Trait Implementations§

source§

impl<const REDUNDANT: u16> ChordStorageInterface<REDUNDANT> for Swarm

source§

fn storage_fetch<'life0, 'async_trait>( &'life0 self, vid: Did ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Fetch virtual node, if exist in localstoreage, copy it to the cache, else Query Remote Node

source§

fn storage_store<'life0, 'async_trait>( &'life0 self, vnode: VirtualNode ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Store VirtualNode, TryInto<VirtualNode> is implemented for alot of types

source§

fn storage_append_data<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, data: Encoded ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

append data to Data type virtual node
source§

fn storage_touch_data<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, data: Encoded ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

append data to Data type virtual node uniquely
source§

impl ChordStorageInterfaceCacheChecker for Swarm

source§

fn storage_check_cache<'life0, 'async_trait>( &'life0 self, vid: Did ) -> Pin<Box<dyn Future<Output = Option<VirtualNode>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Check local cache

source§

impl ConnectionHandshake for Swarm

source§

fn prepare_connection_offer<'life0, 'async_trait>( &'life0 self, peer: Did ) -> Pin<Box<dyn Future<Output = Result<(Connection, ConnectNodeSend)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Create new connection and its offer.
source§

fn answer_remote_connection<'life0, 'life1, 'async_trait>( &'life0 self, peer: Did, offer_msg: &'life1 ConnectNodeSend ) -> Pin<Box<dyn Future<Output = Result<(Connection, ConnectNodeReport)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Answer the offer of remote connection.
source§

fn accept_remote_connection<'life0, 'life1, 'async_trait>( &'life0 self, peer: Did, answer_msg: &'life1 ConnectNodeReport ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Accept the answer of remote connection.
source§

fn create_offer<'life0, 'async_trait>( &'life0 self, peer: Did ) -> Pin<Box<dyn Future<Output = Result<(Connection, MessagePayload<Message>)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Creaet new connection and its answer. This function will wrap the offer inside a payload with verification.
source§

fn answer_offer<'life0, 'async_trait>( &'life0 self, offer_payload: MessagePayload<Message> ) -> Pin<Box<dyn Future<Output = Result<(Connection, MessagePayload<Message>)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Answer the offer of remote connection. This function will verify the answer payload and will wrap the answer inside a payload with verification.
source§

fn accept_answer<'life0, 'async_trait>( &'life0 self, answer_payload: MessagePayload<Message> ) -> Pin<Box<dyn Future<Output = Result<(Did, Connection)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Accept the answer of remote connection. This function will verify the answer payload and will return its did with the connection.
source§

impl ConnectionManager for Swarm

source§

fn disconnect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Disconnect a connection. There are three steps:

  1. remove from DHT;
  2. remove from Transport;
  3. close the connection;
source§

fn connect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Connect a given Did. If the did is already connected, return directly, else try prepare offer and establish connection by dht. This function may returns a pending connection or connected connection.

source§

fn connect_via<'life0, 'async_trait>( &'life0 self, did: Did, next_hop: Did ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Similar to connect, but this function will try connect a Did by given hop.

source§

impl Judegement for Swarm

source§

fn record_connect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Record a succeeded connected

source§

fn record_disconnected<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Record a disconnected

source§

fn should_connect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Asynchronously checks if a connection should be established with the provided DID.

source§

impl JudgeConnection for Swarm

source§

fn disconnect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Asynchronously disconnects the connection associated with the provided DID after recording the disconnection.
source§

fn connect<'life0, 'async_trait>( &'life0 self, did: Did ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Asynchronously establishes a new connection and returns the connection associated with the provided DID if should_connect returns true; otherwise, returns an error.
source§

fn connect_via<'life0, 'async_trait>( &'life0 self, did: Did, next_hop: Did ) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Asynchronously establishes a new connection via a specified next hop DID and returns the connection associated with the provided DID if should_connect returns true; otherwise, returns an error.
source§

impl<T> PayloadSender<T> for Swarmwhere T: Clone + Serialize + DeserializeOwned + Send + Sync + 'static + Debug,

source§

fn session_sk(&self) -> &SessionSk

Get the session sk
source§

fn dht(&self) -> Arc<PeerRing>

Get access to DHT.
source§

fn do_send_payload<'life0, 'async_trait>( &'life0 self, did: Did, payload: MessagePayload<T> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Send a message payload to a specified DID.
source§

fn infer_next_hop(&self, next_hop: Option<Did>, destination: Did) -> Result<Did>

Infer the next hop for a message by calling dht.find_successor().
source§

fn send_payload<'life0, 'async_trait>( &'life0 self, payload: MessagePayload<T> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Alias for do_send_payload that sets the next hop to payload.relay.next_hop.
source§

fn send_message<'life0, 'async_trait>( &'life0 self, msg: T, destination: Did ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Send a message to a specified destination.
source§

fn send_message_by_hop<'life0, 'async_trait>( &'life0 self, msg: T, destination: Did, next_hop: Did ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Send a message to a specified destination by specified next hop.
source§

fn send_direct_message<'life0, 'async_trait>( &'life0 self, msg: T, destination: Did ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Send a direct message to a specified destination.
source§

fn send_report_message<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 MessagePayload<T>, msg: T ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send a report message to a specified destination.
source§

fn forward_by_relay<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 MessagePayload<T>, relay: MessageRelay ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Forward a payload message by relay. It just create a new payload, cloned data, resigned with session and send
source§

fn forward_payload<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 MessagePayload<T>, next_hop: Option<Did> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Forward a payload message, with the next hop inferred by the DHT.
source§

fn reset_destination<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 MessagePayload<T>, next_hop: Did ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reset the destination to a secp DID.
source§

impl<const REDUNDANT: u16> SubringInterface<REDUNDANT> for Swarm

source§

fn subring_join<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

add did into current chord subring. send direct message with JoinSubring type, which will handled by next node.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Swarm

§

impl Send for Swarm

§

impl Sync for Swarm

§

impl Unpin for Swarm

§

impl !UnwindSafe for Swarm

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

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