Struct rings_node::prelude::Swarm
source · pub struct Swarm { /* private fields */ }
Expand description
The transport and dht management.
Implementations§
source§impl Swarm
impl Swarm
sourcepub async fn record_sent(&self, did: Did) -> impl Future<Output = ()>
pub async fn record_sent(&self, did: Did) -> impl Future<Output = ()>
Record a succeeded message sent
sourcepub async fn record_sent_failed(&self, did: Did) -> impl Future<Output = ()>
pub async fn record_sent_failed(&self, did: Did) -> impl Future<Output = ()>
Record a failed message sent
sourcepub async fn behaviour_good(&self, did: Did) -> impl Future<Output = bool>
pub async fn behaviour_good(&self, did: Did) -> impl Future<Output = bool>
Check that a Did is behaviour good
sourcepub async fn new_connection(
&self,
did: Did
) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>
pub async fn new_connection( &self, did: Did ) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>
Create new connection that will be handled by swarm.
sourcepub async fn get_and_check_connection(
&self,
did: Did
) -> impl Future<Output = Option<ConnectionRef<WebrtcConnection>>>
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.
sourcepub fn get_connection(
&self,
did: Did
) -> Option<ConnectionRef<WebrtcConnection>>
pub fn get_connection( &self, did: Did ) -> Option<ConnectionRef<WebrtcConnection>>
Get connection by did.
sourcepub fn get_connections(
&self
) -> Vec<(Did, ConnectionRef<WebrtcConnection>), Global>
pub fn get_connections( &self ) -> Vec<(Did, ConnectionRef<WebrtcConnection>), Global>
Get all connections in transport.
sourcepub fn get_connection_ids(&self) -> Vec<Did, Global>
pub fn get_connection_ids(&self) -> Vec<Did, Global>
Get dids of all connections in transport.
source§impl Swarm
impl Swarm
sourcepub fn session_sk(&self) -> &SessionSk
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).
sourcepub async fn poll_message(
&self
) -> impl Future<Output = Option<MessagePayload<Message>>>
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.
sourcepub async fn listen_once(
&self
) -> impl Future<Output = Option<(MessagePayload<Message>, Vec<MessageHandlerEvent, Global>)>>
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.
sourcepub async fn handle_message_handler_event(
&self,
event: &MessageHandlerEvent
) -> impl Future<Output = Result<Vec<MessageHandlerEvent, Global>, Error>>
pub async fn handle_message_handler_event( &self, event: &MessageHandlerEvent ) -> impl Future<Output = Result<Vec<MessageHandlerEvent, Global>, Error>>
Event handler of Swarm.
sourcepub 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,
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
sourcepub async fn disconnect(
&self,
did: Did
) -> impl Future<Output = Result<(), Error>>
pub async fn disconnect( &self, did: Did ) -> impl Future<Output = Result<(), Error>>
Disconnect a connection. There are three steps:
- remove from DHT;
- remove from Transport;
- close the connection;
sourcepub async fn connect(
&self,
did: Did
) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>
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.
sourcepub async fn connect_via(
&self,
did: Did,
next_hop: Did
) -> impl Future<Output = Result<ConnectionRef<WebrtcConnection>, Error>>
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.
sourcepub async fn inspect(&self) -> impl Future<Output = SwarmInspect>
pub async fn inspect(&self) -> impl Future<Output = SwarmInspect>
Check the status of swarm
Trait Implementations§
source§impl<const REDUNDANT: u16> ChordStorageInterface<REDUNDANT> for Swarm
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,
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,
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,
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,
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,
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,
source§impl ConnectionHandshake for Swarm
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
source§impl ConnectionManager for Swarm
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,
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:
- remove from DHT;
- remove from Transport;
- 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,
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,
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
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,
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§impl JudgeConnection for Swarm
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,
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,
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,
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,
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,
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,
should_connect
returns true; otherwise, returns an error.source§impl<T> PayloadSender<T> for Swarmwhere
T: Clone + Serialize + DeserializeOwned + Send + Sync + 'static + Debug,
impl<T> PayloadSender<T> for Swarmwhere T: Clone + Serialize + DeserializeOwned + Send + Sync + 'static + Debug,
source§fn session_sk(&self) -> &SessionSk
fn session_sk(&self) -> &SessionSk
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,
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,
source§fn infer_next_hop(
&self,
next_hop: Option<Did>,
destination: Did
) -> Result<Did, Error>
fn infer_next_hop( &self, next_hop: Option<Did>, destination: Did ) -> Result<Did, Error>
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
source§impl<const REDUNDANT: u16> SubringInterface<REDUNDANT> for Swarm
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,
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.