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§
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
Required Methods§
Sourcefn has_peer(&self, peer_id: Self::PeerId) -> bool
fn has_peer(&self, peer_id: Self::PeerId) -> bool
Returns whether the current peer has a connection to another peer
Sourcefn get_peer_info(&self, peer_id: Self::PeerId) -> Option<PeerInfo>
fn get_peer_info(&self, peer_id: Self::PeerId) -> Option<PeerInfo>
Gets a peer information.
If the peer isn’t found, None is returned.
Sourcefn 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 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
Sourcefn peer_provides_required_services(&self, peer_id: Self::PeerId) -> bool
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
Sourcefn peer_provides_services(
&self,
peer_id: Self::PeerId,
services: Services,
) -> bool
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
Sourcefn 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 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
Sourcefn subscribe_events(&self) -> SubscribeEvents<Self::PeerId>
fn subscribe_events(&self) -> SubscribeEvents<Self::PeerId>
Subscribes to network events
Sourcefn subscribe<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send + 'async_trait>>
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>>
Subscribes to a Gossipsub topic
Sourcefn unsubscribe<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
fn unsubscribe<'life0, 'async_trait, T>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
Unsubscribes from a Gossipsub topic
Sourcefn publish<'life0, 'async_trait, T>(
&'life0 self,
item: T::Item,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
fn publish<'life0, 'async_trait, T>( &'life0 self, item: T::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
Publishes a message to a Gossipsub topic
Sourcefn 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>>
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>>
Subscribes to a Gossipsub subtopic, providing the subtopic name
Sourcefn unsubscribe_subtopic<'life0, 'async_trait, T>(
&'life0 self,
subtopic: String,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
fn unsubscribe_subtopic<'life0, 'async_trait, T>( &'life0 self, subtopic: String, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
Unsubscribes from a Gossipsub subtopic
Sourcefn publish_subtopic<'life0, 'async_trait, T>(
&'life0 self,
subtopic: String,
item: T::Item,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + '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>>
Publishes a message to a Gossipsub subtopic
Sourcefn validate_message<T>(&self, id: Self::PubsubId, acceptance: MsgAcceptance)
fn validate_message<T>(&self, id: Self::PubsubId, acceptance: MsgAcceptance)
Validates a message received from a Gossipsub topic
Sourcefn 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_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
Sourcefn 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 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
Sourcefn 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_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
Sourcefn 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 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
Sourcefn get_local_peer_id(&self) -> Self::PeerId
fn get_local_peer_id(&self) -> Self::PeerId
Gets the local peer ID
Sourcefn 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 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
Sourcefn 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 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
Sourcefn receive_messages<M: Message>(&self) -> BoxStream<'static, (M, Self::PeerId)>
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.
Sourcefn receive_requests<Req: Request>(
&self,
) -> BoxStream<'static, (Req, Self::RequestId, Self::PeerId)>
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.
Sourcefn 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,
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".