Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Move DummySpecialization to sc-network (#4680)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored and gavofyork committed Jan 20, 2020
1 parent 6cf45f2 commit c3af86c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
26 changes: 26 additions & 0 deletions client/network/src/protocol/specialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ pub trait NetworkSpecialization<B: BlockT>: Send + Sync + 'static {
fn on_block_imported(&mut self, _ctx: &mut dyn Context<B>, _hash: B::Hash, _header: &B::Header) { }
}

/// A specialization that does nothing.
#[derive(Clone)]
pub struct DummySpecialization;

impl<B: BlockT> NetworkSpecialization<B> for DummySpecialization {
fn status(&self) -> Vec<u8> {
vec![]
}

fn on_connect(
&mut self,
_ctx: &mut dyn Context<B>,
_peer_id: PeerId,
_status: crate::message::Status<B>
) {}

fn on_disconnect(&mut self, _ctx: &mut dyn Context<B>, _peer_id: PeerId) {}

fn on_message(
&mut self,
_ctx: &mut dyn Context<B>,
_peer_id: PeerId,
_message: Vec<u8>,
) {}
}

/// 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.
Expand Down
27 changes: 1 addition & 26 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -101,32 +102,6 @@ impl<B: BlockT> Verifier<B> for PassThroughVerifier {
}
}

/// The test specialization.
#[derive(Clone)]
pub struct DummySpecialization;

impl NetworkSpecialization<Block> for DummySpecialization {
fn status(&self) -> Vec<u8> {
vec![]
}

fn on_connect(
&mut self,
_ctx: &mut dyn Context<Block>,
_peer_id: PeerId,
_status: sc_network::message::Status<Block>
) {}

fn on_disconnect(&mut self, _ctx: &mut dyn Context<Block>, _peer_id: PeerId) {}

fn on_message(
&mut self,
_ctx: &mut dyn Context<Block>,
_peer_id: PeerId,
_message: Vec<u8>,
) {}
}

pub type PeersFullClient =
sc_client::Client<substrate_test_runtime_client::Backend, substrate_test_runtime_client::Executor, Block, substrate_test_runtime_client::runtime::RuntimeApi>;
pub type PeersLightClient =
Expand Down

0 comments on commit c3af86c

Please sign in to comment.