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( &self, services: Services, min_peers: usize, ) -> impl Future<Output = Result<Vec<Self::PeerId>, Self::Error>> + Send; 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( &self, peer_id: Self::PeerId, close_reason: CloseReason, ) -> impl Future<Output = ()> + Send; fn subscribe_events(&self) -> SubscribeEvents<Self::PeerId>; fn subscribe<T>( &self, ) -> impl Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send where T: Topic + Sync; fn unsubscribe<T>( &self, ) -> impl Future<Output = Result<(), Self::Error>> + Send where T: Topic + Sync; fn publish<T>( &self, item: T::Item, ) -> impl Future<Output = Result<(), Self::Error>> + Send where T: Topic + Sync; fn subscribe_subtopic<T>( &self, subtopic: String, ) -> impl Future<Output = Result<BoxStream<'static, (T::Item, Self::PubsubId)>, Self::Error>> + Send where T: Topic + Sync; fn unsubscribe_subtopic<T>( &self, subtopic: String, ) -> impl Future<Output = Result<(), Self::Error>> + Send where T: Topic + Sync; fn publish_subtopic<T>( &self, subtopic: String, item: T::Item, ) -> impl Future<Output = Result<(), Self::Error>> + Send where T: Topic + Sync; fn validate_message<T>(&self, id: Self::PubsubId, acceptance: MsgAcceptance) where T: Topic + Sync; fn dht_get<K, V, T>( &self, k: &K, ) -> impl Future<Output = Result<Option<V>, Self::Error>> + Send where K: AsRef<[u8]> + Send + Sync, V: Deserialize + Send + Sync + TaggedSignable + Ord, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize; fn dht_put<K, V, T>( &self, k: &K, v: &V, keypair: &T, ) -> impl Future<Output = Result<(), Self::Error>> + Send where K: AsRef<[u8]> + Send + Sync, V: Serialize + Send + Sync + TaggedSignable + Clone + Ord, T: TaggedKeyPair + Send + Sync + Serialize + Deserialize; fn dial_peer( &self, peer_id: Self::PeerId, ) -> impl Future<Output = Result<(), Self::Error>> + Send; fn dial_address( &self, address: Self::AddressType, ) -> impl Future<Output = Result<(), Self::Error>> + Send; fn get_local_peer_id(&self) -> Self::PeerId; fn message<M: Message>( &self, request: M, peer_id: Self::PeerId, ) -> impl Future<Output = Result<(), RequestError>> + Send; fn request<Req: Request>( &self, request: Req, peer_id: Self::PeerId, ) -> impl Future<Output = Result<Req::Response, RequestError>> + Send; 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<Req: Request>( &self, request_id: Self::RequestId, response: Req::Response, ) -> impl Future<Output = Result<(), Self::Error>> + Send;
}

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( &self, services: Services, min_peers: usize, ) -> impl Future<Output = Result<Vec<Self::PeerId>, Self::Error>> + Send

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( &self, peer_id: Self::PeerId, close_reason: CloseReason, ) -> impl Future<Output = ()> + Send

Disconnects a peer with a close reason

Source

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

Subscribes to network events

Source

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

Subscribes to a Gossipsub topic

Source

fn unsubscribe<T>(&self) -> impl Future<Output = Result<(), Self::Error>> + Send
where T: Topic + Sync,

Unsubscribes from a Gossipsub topic

Source

fn publish<T>( &self, item: T::Item, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where T: Topic + Sync,

Publishes a message to a Gossipsub topic

Source

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

Subscribes to a Gossipsub subtopic, providing the subtopic name

Source

fn unsubscribe_subtopic<T>( &self, subtopic: String, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where T: Topic + Sync,

Unsubscribes from a Gossipsub subtopic

Source

fn publish_subtopic<T>( &self, subtopic: String, item: T::Item, ) -> impl Future<Output = Result<(), Self::Error>> + Send
where T: Topic + Sync,

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<K, V, T>( &self, k: &K, ) -> impl Future<Output = Result<Option<V>, Self::Error>> + Send

Gets a value from the distributed hash table

Source

fn dht_put<K, V, T>( &self, k: &K, v: &V, keypair: &T, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Puts a value to the distributed hash table

Source

fn dial_peer( &self, peer_id: Self::PeerId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Dials a peer

Source

fn dial_address( &self, address: Self::AddressType, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Dials an address

Source

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

Gets the local peer ID

Source

fn message<M: Message>( &self, request: M, peer_id: Self::PeerId, ) -> impl Future<Output = Result<(), RequestError>> + Send

Sends a message to a specific peer

Source

fn request<Req: Request>( &self, request: Req, peer_id: Self::PeerId, ) -> impl Future<Output = Result<Req::Response, RequestError>> + Send

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<Req: Request>( &self, request_id: Self::RequestId, response: Req::Response, ) -> impl Future<Output = Result<(), Self::Error>> + Send

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§