diff --git a/client/network/src/protocol/specialization.rs b/client/network/src/protocol/specialization.rs index 9b1452160e535..af6d5f7a239cd 100644 --- a/client/network/src/protocol/specialization.rs +++ b/client/network/src/protocol/specialization.rs @@ -57,6 +57,32 @@ pub trait NetworkSpecialization: Send + Sync + 'static { fn on_block_imported(&mut self, _ctx: &mut dyn Context, _hash: B::Hash, _header: &B::Header) { } } +/// A specialization that does nothing. +#[derive(Clone)] +pub struct DummySpecialization; + +impl NetworkSpecialization for DummySpecialization { + fn status(&self) -> Vec { + vec![] + } + + fn on_connect( + &mut self, + _ctx: &mut dyn Context, + _peer_id: PeerId, + _status: crate::message::Status + ) {} + + fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {} + + fn on_message( + &mut self, + _ctx: &mut dyn Context, + _peer_id: PeerId, + _message: Vec, + ) {} +} + /// Construct a simple protocol that is composed of several sub protocols. /// Each "sub protocol" needs to implement `Specialization` and needs to provide a `new()` function. /// For more fine grained implementations, this macro is not usable. diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index f1b7fa478c6c8..1b13e83343e58 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -62,6 +62,7 @@ use substrate_test_runtime_client::{self, AccountKeyring}; pub use substrate_test_runtime_client::runtime::{Block, Extrinsic, Hash, Transfer}; pub use substrate_test_runtime_client::{TestClient, TestClientBuilder, TestClientBuilderExt}; +pub use sc_network::specialization::DummySpecialization; type AuthorityId = sp_consensus_babe::AuthorityId; @@ -101,32 +102,6 @@ impl Verifier for PassThroughVerifier { } } -/// The test specialization. -#[derive(Clone)] -pub struct DummySpecialization; - -impl NetworkSpecialization for DummySpecialization { - fn status(&self) -> Vec { - vec![] - } - - fn on_connect( - &mut self, - _ctx: &mut dyn Context, - _peer_id: PeerId, - _status: sc_network::message::Status - ) {} - - fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {} - - fn on_message( - &mut self, - _ctx: &mut dyn Context, - _peer_id: PeerId, - _message: Vec, - ) {} -} - pub type PeersFullClient = sc_client::Client; pub type PeersLightClient =