Struct rings_node::prelude::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) -> impl Future<Output = ()>

Record a succeeded message sent

source

pub async fn record_sent_failed(&self, did: Did) -> impl Future<Output = ()>

Record a failed message sent

source

pub async fn behaviour_good(&self, did: Did) -> impl Future<Output = bool>

Check that a Did is behaviour good

source

pub async fn new_connection( &self, did: Did ) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>

Create new connection that will be handled by swarm.

source

pub async fn get_and_check_connection( &self, did: Did ) -> impl Future<Output = Option<ConnectionRef<WebrtcConnection>>>

Get connection by did and check if it is connected.

source

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

Get connection by did.

source

pub fn get_connections( &self ) -> Vec<(Did, ConnectionRef<WebrtcConnection>), Global>

Get all connections in transport.

source

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

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

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 ) -> impl Future<Output = 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 ) -> impl Future<Output = Option<(MessagePayload<Message>, Vec<MessageHandlerEvent, Global>)>>

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 ) -> impl Future<Output = Result<Vec<MessageHandlerEvent, Global>, Error>>

Event handler of Swarm.

source

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

Batch handle events

source

pub async fn disconnect( &self, did: Did ) -> impl Future<Output = Result<(), Error>>

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 ) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>

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 ) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>

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

source

pub async fn inspect(&self) -> impl Future<Output = SwarmInspect>

Check the status of swarm

source§

impl Swarm

source

pub async fn listen(self: Arc<Swarm, Global>) -> impl Future<Output = ()>

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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Swarm: '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Swarm: '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, Global>>where 'life0: 'async_trait, Swarm: '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<(ConnectionRef<WebrtcConnection>, ConnectNodeSend), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<(ConnectionRef<WebrtcConnection>, ConnectNodeReport), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Swarm: '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<ConnectionRef<WebrtcConnection>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Swarm: '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<(ConnectionRef<WebrtcConnection>, MessagePayload<Message>), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<(ConnectionRef<WebrtcConnection>, MessagePayload<Message>), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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, ConnectionRef<WebrtcConnection>), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<ConnectionRef<WebrtcConnection>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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<ConnectionRef<WebrtcConnection>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: '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, Global>>where 'life0: 'async_trait, Swarm: '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, Global>>where 'life0: 'async_trait, Swarm: '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, Global>>where 'life0: 'async_trait, Swarm: '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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<ConnectionRef<WebrtcConnection>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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<ConnectionRef<WebrtcConnection>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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, Global>

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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Swarm: 'async_trait,

Send a message payload to a specified DID.
source§

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

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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, Self: Sync + '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + '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<(), Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Swarm: '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<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
§

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
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
§

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
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
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<T> Upcastable for Twhere T: Any + Send + Sync + 'static,

§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
§

fn upcast_any_box(self: Box<T, Global>) -> Box<dyn Any, Global>

upcast boxed dyn
§

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