Split specialization context from network context (#2745)

* Split specialization context from network context

* Line width
This commit is contained in:
Pierre Krieger
2019-06-03 20:26:17 +02:00
committed by GitHub
parent b88c46bfd1
commit 4213fe15cf
4 changed files with 45 additions and 11 deletions
+11 -4
View File
@@ -32,7 +32,7 @@ use crate::message::{BlockAttributes, Direction, FromBlock, RequestId};
use crate::message::generic::{Message as GenericMessage, ConsensusMessage};
use crate::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient};
use crate::on_demand::{OnDemandCore, OnDemandNetwork, RequestData};
use crate::specialization::NetworkSpecialization;
use crate::specialization::{NetworkSpecialization, Context as SpecializationContext};
use crate::sync::{ChainSync, Context as SyncContext, Status as SyncStatus, SyncState};
use crate::service::{TransactionPool, ExHashT};
use crate::config::Roles;
@@ -281,9 +281,6 @@ pub trait Context<B: BlockT> {
/// Send a consensus message to a peer.
fn send_consensus(&mut self, who: PeerId, consensus: ConsensusMessage);
/// Send a chain-specific message to a peer.
fn send_chain_specific(&mut self, who: PeerId, message: Vec<u8>);
}
/// Protocol context.
@@ -315,6 +312,16 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> Context<B> for ProtocolContext<'a, B,
GenericMessage::Consensus(consensus)
)
}
}
impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SpecializationContext<B> for ProtocolContext<'a, B, H> {
fn report_peer(&mut self, who: PeerId, reputation: i32) {
self.network_out.report_peer(who, reputation)
}
fn disconnect_peer(&mut self, who: PeerId) {
self.network_out.disconnect_peer(who)
}
fn send_chain_specific(&mut self, who: PeerId, message: Vec<u8>) {
send_message(