Trait phron_finality::network::gossip::Network
source · pub trait Network<D: Data>: Send + 'static {
type Error: Display + Send;
type PeerId: Clone + Debug + Eq + Hash + Send + 'static;
// Required methods
fn send_to(
&mut self,
data: D,
peer_id: Self::PeerId
) -> Result<(), Self::Error>;
fn send_to_random(
&mut self,
data: D,
peer_ids: HashSet<Self::PeerId>
) -> Result<(), Self::Error>;
fn broadcast(&mut self, data: D) -> Result<(), Self::Error>;
fn next<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(D, Self::PeerId), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Interface for the gossip network. This represents a P2P network and a lot of the properties of this interface result from that. In particular we might know the ID of a given peer, but not be connected to them directly.
Required Associated Types§
Required Methods§
sourcefn send_to(&mut self, data: D, peer_id: Self::PeerId) -> Result<(), Self::Error>
fn send_to(&mut self, data: D, peer_id: Self::PeerId) -> Result<(), Self::Error>
Attempt to send data to a peer. Might silently fail if we are not connected to them.
sourcefn send_to_random(
&mut self,
data: D,
peer_ids: HashSet<Self::PeerId>
) -> Result<(), Self::Error>
fn send_to_random( &mut self, data: D, peer_ids: HashSet<Self::PeerId> ) -> Result<(), Self::Error>
Send data to a random peer, preferably from a list. It should send the data to a randomly chosen peer from the provided list, but if it cannot (e.g. because it’s not connected) it will send to a random available peer. No guarantees any peer gets it even if no errors are returned, retry appropriately.
sourcefn broadcast(&mut self, data: D) -> Result<(), Self::Error>
fn broadcast(&mut self, data: D) -> Result<(), Self::Error>
Broadcast data to all directly connected peers. Network-wide broadcasts have to be implemented on top of this abstraction. Note that there might be no currently connected peers, so there are no guarantees any single call sends anything even if no errors are returned, retry appropriately.
sourcefn next<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(D, Self::PeerId), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(D, Self::PeerId), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receive some data from the network, including information about who sent it. This method’s implementation must be cancellation safe.