Simplify consensus message sending (#1166)

* Create gossip_consensus_message helper on service, simplify consensus_gossip access
This commit is contained in:
Benjamin Kampmann
2018-11-27 09:06:58 +01:00
committed by GitHub
parent 59af4de4fd
commit dbe31230c3
4 changed files with 17 additions and 13 deletions
+7 -1
View File
@@ -224,7 +224,6 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
&self.sync
}
pub(crate) fn consensus_gossip<'a>(&'a self) -> &'a RwLock<ConsensusGossip<B>> {
&self.consensus_gossip
}
@@ -297,6 +296,13 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
send_message::<B, H>(&self.context_data.peers, io, who, message)
}
pub fn gossip_consensus_message(&self, io: &mut SyncIo, topic: B::Hash, message: Vec<u8>) {
let gossip = self.consensus_gossip();
self.with_spec(io, move |_s, context|{
gossip.write().multicast(context, topic, message);
});
}
/// Called when a new peer is connected
pub fn on_peer_connected(&self, io: &mut SyncIo, who: NodeIndex) {
trace!(target: "sync", "Connected {}: {}", who, io.peer_debug_info(who));