pub use self::bridge::GossipEngine;
pub use self::state_machine::TopicNotification;
pub use self::validator::{DiscardAll, MessageIntent, Validator, ValidatorContext, ValidationResult};
use futures::prelude::*;
use sc_network::{Event, ExHashT, NetworkService, PeerId, ReputationChange};
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
use std::{borrow::Cow, pin::Pin, sync::Arc};
mod bridge;
mod state_machine;
mod validator;
pub trait Network<B: BlockT> {
fn event_stream(&self) -> Pin<Box<dyn Stream<Item = Event> + Send>>;
fn report_peer(&self, peer_id: PeerId, reputation: ReputationChange);
fn disconnect_peer(&self, who: PeerId);
fn write_notification(&self, who: PeerId, engine_id: ConsensusEngineId, message: Vec<u8>);
fn register_notifications_protocol(
&self,
engine_id: ConsensusEngineId,
protocol_name: Cow<'static, str>,
);
fn announce(&self, block: B::Hash, associated_data: Vec<u8>);
}
impl<B: BlockT, H: ExHashT> Network<B> for Arc<NetworkService<B, H>> {
fn event_stream(&self) -> Pin<Box<dyn Stream<Item = Event> + Send>> {
Box::pin(NetworkService::event_stream(self, "network-gossip"))
}
fn report_peer(&self, peer_id: PeerId, reputation: ReputationChange) {
NetworkService::report_peer(self, peer_id, reputation);
}
fn disconnect_peer(&self, who: PeerId) {
NetworkService::disconnect_peer(self, who)
}
fn write_notification(&self, who: PeerId, engine_id: ConsensusEngineId, message: Vec<u8>) {
NetworkService::write_notification(self, who, engine_id, message)
}
fn register_notifications_protocol(
&self,
engine_id: ConsensusEngineId,
protocol_name: Cow<'static, str>,
) {
NetworkService::register_notifications_protocol(self, engine_id, protocol_name)
}
fn announce(&self, block: B::Hash, associated_data: Vec<u8>) {
NetworkService::announce_block(self, block, associated_data)
}
}