Skip to main content

Network

Trait Network 

Source
pub trait Network:
    Send
    + Sync
    + Unpin
    + 'static {
    type PeerId: Copy + Debug + Display + Ord + Hash + Send + Sync + Unpin + 'static;
    type AddressType: Debug + Display + 'static;
    type Error: Error;
    type PubsubId: PubsubId<Self::PeerId> + Send + Sync + Unpin;
    type RequestId: Copy + Debug + Display + Eq + Send + Sync + 'static;

Show 25 methods // Required methods fn get_peers(&self) -> Vec<Self::PeerId>; fn has_peer(&self, peer_id: Self::PeerId) -> bool; fn get_peer_info(&self, peer_id: Self::PeerId) -> Option<PeerInfo>; fn get_peers_by_services<'life0, 'async_trait>( &'life0 self, services: Services, min_peers: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::PeerId>, Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn peer_provides_required_services(&self, peer_id: Self::PeerId) -> bool; fn peer_provides_services( &self, peer_id: Self::PeerId, services: Services, ) -> bool; fn disconnect_peer<'life0, 'async_trait>( &'life0 self, peer_id: Self::PeerId, close_reason: CloseReason, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe_events(&self) -> SubscribeEvents<Self::PeerId>; fn subscribe<'life0, 'async_trait, T>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn unsubscribe<'life0, 'async_trait, T>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn publish<'life0, 'async_trait, T>( &'life0 self, item: T::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn subscribe_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn unsubscribe_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn publish_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, item: T::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn validate_message<T>(&self, id: Self::PubsubId, acceptance: MsgAcceptance) where T: Topic + Sync; fn dht_get<'life0, 'life1, 'async_trait, K, V, T>( &'life0 self, k: &'life1 K, ) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>> where K: AsRef<[u8]> + Send + Sync + 'async_trait, V: Deserialize + Send + Sync + TaggedSignable + Ord + 'async_trait, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn dht_put<'life0, 'life1, 'life2, 'life3, 'async_trait, K, V, T>( &'life0 self, k: &'life1 K, v: &'life2 V, keypair: &'life3 T, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where K: AsRef<[u8]> + Send + Sync + 'async_trait, V: Serialize + Send + Sync + TaggedSignable + Clone + Ord + 'async_trait, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn dial_peer<'life0, 'async_trait>( &'life0 self, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn dial_address<'life0, 'async_trait>( &'life0 self, address: Self::AddressType, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_local_peer_id(&self) -> Self::PeerId; fn message<'life0, 'async_trait, M>( &'life0 self, request: M, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<(), RequestError>> + Send + 'async_trait>> where M: 'async_trait + Message, Self: 'async_trait, 'life0: 'async_trait; fn request<'life0, 'async_trait, Req>( &'life0 self, request: Req, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<Req::Response, RequestError>> + Send + 'async_trait>> where Req: 'async_trait + Request, Self: 'async_trait, 'life0: 'async_trait; fn receive_messages<M: Message>( &self, ) -> BoxStream<'static, (M, Self::PeerId)>; fn receive_requests<Req: Request>( &self, ) -> BoxStream<'static, (Req, Self::RequestId, Self::PeerId)>; fn respond<'life0, 'async_trait, Req>( &'life0 self, request_id: Self::RequestId, response: Req::Response, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Req: 'async_trait + Request, Self: 'async_trait, 'life0: 'async_trait;
}

Required Associated Types§

Source

type PeerId: Copy + Debug + Display + Ord + Hash + Send + Sync + Unpin + 'static

Source

type AddressType: Debug + Display + 'static

Source

type Error: Error

Source

type PubsubId: PubsubId<Self::PeerId> + Send + Sync + Unpin

Source

type RequestId: Copy + Debug + Display + Eq + Send + Sync + 'static

Required Methods§

Source

fn get_peers(&self) -> Vec<Self::PeerId>

Gets the set of connected peers

Source

fn has_peer(&self, peer_id: Self::PeerId) -> bool

Returns whether the current peer has a connection to another peer

Source

fn get_peer_info(&self, peer_id: Self::PeerId) -> Option<PeerInfo>

Gets a peer information. If the peer isn’t found, None is returned.

Source

fn get_peers_by_services<'life0, 'async_trait>( &'life0 self, services: Services, min_peers: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::PeerId>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets the set of connected peers that provide the supplied services. If we currently don’t have min number of connected peer that provides those services, we dial peers. If there aren’t enough peers in the network that provides the required services, we return an error

Source

fn peer_provides_required_services(&self, peer_id: Self::PeerId) -> bool

Returns true when the given peer provides the services flags that are required by us

Source

fn peer_provides_services( &self, peer_id: Self::PeerId, services: Services, ) -> bool

Returns true when the given peer provides the services flags that are required by us

Source

fn disconnect_peer<'life0, 'async_trait>( &'life0 self, peer_id: Self::PeerId, close_reason: CloseReason, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disconnects a peer with a close reason

Source

fn subscribe_events(&self) -> SubscribeEvents<Self::PeerId>

Subscribes to network events

Source

fn subscribe<'life0, 'async_trait, T>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send + 'async_trait>>
where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Subscribes to a Gossipsub topic

Source

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

Unsubscribes from a Gossipsub topic

Source

fn publish<'life0, 'async_trait, T>( &'life0 self, item: T::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Publishes a message to a Gossipsub topic

Source

fn subscribe_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send + 'async_trait>>
where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Subscribes to a Gossipsub subtopic, providing the subtopic name

Source

fn unsubscribe_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Unsubscribes from a Gossipsub subtopic

Source

fn publish_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, item: T::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where T: Topic + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Publishes a message to a Gossipsub subtopic

Source

fn validate_message<T>(&self, id: Self::PubsubId, acceptance: MsgAcceptance)
where T: Topic + Sync,

Validates a message received from a Gossipsub topic

Source

fn dht_get<'life0, 'life1, 'async_trait, K, V, T>( &'life0 self, k: &'life1 K, ) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>>
where K: AsRef<[u8]> + Send + Sync + 'async_trait, V: Deserialize + Send + Sync + TaggedSignable + Ord + 'async_trait, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets a value from the distributed hash table

Source

fn dht_put<'life0, 'life1, 'life2, 'life3, 'async_trait, K, V, T>( &'life0 self, k: &'life1 K, v: &'life2 V, keypair: &'life3 T, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where K: AsRef<[u8]> + Send + Sync + 'async_trait, V: Serialize + Send + Sync + TaggedSignable + Clone + Ord + 'async_trait, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Puts a value to the distributed hash table

Source

fn dial_peer<'life0, 'async_trait>( &'life0 self, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Dials a peer

Source

fn dial_address<'life0, 'async_trait>( &'life0 self, address: Self::AddressType, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Dials an address

Source

fn get_local_peer_id(&self) -> Self::PeerId

Gets the local peer ID

Source

fn message<'life0, 'async_trait, M>( &'life0 self, request: M, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<(), RequestError>> + Send + 'async_trait>>
where M: 'async_trait + Message, Self: 'async_trait, 'life0: 'async_trait,

Sends a message to a specific peer

Source

fn request<'life0, 'async_trait, Req>( &'life0 self, request: Req, peer_id: Self::PeerId, ) -> Pin<Box<dyn Future<Output = Result<Req::Response, RequestError>> + Send + 'async_trait>>
where Req: 'async_trait + Request, Self: 'async_trait, 'life0: 'async_trait,

Requests data from a specific peer

Source

fn receive_messages<M: Message>(&self) -> BoxStream<'static, (M, Self::PeerId)>

Receives messages from peers. This function returns a stream where the messages are going to be propagated.

Source

fn receive_requests<Req: Request>( &self, ) -> BoxStream<'static, (Req, Self::RequestId, Self::PeerId)>

Receives requests from peers. This function returns a stream where the requests are going to be propagated.

Source

fn respond<'life0, 'async_trait, Req>( &'life0 self, request_id: Self::RequestId, response: Req::Response, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Req: 'async_trait + Request, Self: 'async_trait, 'life0: 'async_trait,

Sends a response to a specific request

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§