1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use super::PushStream;
use crate::data::{Gossip, Peer};
use crate::error::Error;
use async_trait::async_trait;
use futures::stream::Stream;

/// Interface for the blockchain node service implementation responsible for
/// exchanging P2P network gossip.
#[async_trait]
pub trait GossipService {
    async fn peers(&self, limit: u32) -> Result<Gossip, Error>;

    /// The type of outbound asynchronous streams returned by the
    /// `subscription` method.
    type SubscriptionStream: Stream<Item = Result<Gossip, Error>> + Send + Sync;

    /// Called by the protocol implementation to establish a
    /// bidirectional subscription stream.
    /// The inbound stream is passed to the asynchronous method,
    /// which resolves to the outbound stream.
    async fn gossip_subscription(
        &self,
        subscriber: Peer,
        stream: PushStream<Gossip>,
    ) -> Result<Self::SubscriptionStream, Error>;
}