pub trait Discovery: Send + Sync {
// Required methods
fn start<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DiscoveredPeer> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn on_event(&self, event: PeerConnectionEvent);
fn advertise(&self, item: &[u8], flags: ProtocolFlags);
fn find_peers_with(&self, item: &[u8]) -> Vec<DiscoveredPeer>;
}Expand description
Trait that any discovery protocol must implement.
Discovery implementations find peers and yield them via
recv(). The Node awaits recv() in a loop and handles
connecting - discovery never connects directly.
Required Methods§
Sourcefn start<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn start<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
Start the discovery service. Listen endpoints, if needed by the implementation, must be provided at construction time.
Sourcefn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Shutdown the discovery service.
Sourcefn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DiscoveredPeer> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DiscoveredPeer> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Await the next discovered peer. The Node calls this in a loop; on shutdown the surrounding task is cancelled.
Sourcefn on_event(&self, event: PeerConnectionEvent)
fn on_event(&self, event: PeerConnectionEvent)
Receive a peer connection event from the Node.
Sourcefn advertise(&self, item: &[u8], flags: ProtocolFlags)
fn advertise(&self, item: &[u8], flags: ProtocolFlags)
Advertise an item (protocol id, swarm key, …) to other peers.
REQUIRED items are required from peers, PREFERRED ones are
preferred but not required. Other bits are implementation
defined.
Sourcefn find_peers_with(&self, item: &[u8]) -> Vec<DiscoveredPeer>
fn find_peers_with(&self, item: &[u8]) -> Vec<DiscoveredPeer>
Return peers in the routing table whose advertised bloom may
contain item. Used by application layers (e.g. Swarm) to find
candidates for protocol- or swarm-targeted dials. Implementations
without a routing table may return an empty vector.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".