From 45027ea3060048de67bfdc8cfe49d88638e69274 Mon Sep 17 00:00:00 2001 From: keorn Date: Thu, 17 Nov 2016 12:17:48 +0000 Subject: [PATCH] add new client messaging --- ethcore/src/client/client.rs | 9 ++++++--- ethcore/src/service.rs | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index e7aa716bd..6eda89a7c 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -576,6 +576,11 @@ impl Client { } } + /// Used by PoA to communicate with peers. + pub fn broadcast_message(&self, message: Bytes) { + self.notify(|notify| notify.broadcast(message.clone())); + } + /// Attempt to get a copy of a specific block's final state. /// /// This will not fail if given BlockID::Latest. @@ -1231,9 +1236,7 @@ impl BlockChainClient for Client { // TODO: Make it an actual queue, return errors. fn queue_infinity_message(&self, message: Bytes) { - if let Ok(new_message) = self.engine.handle_message(UntrustedRlp::new(&message)) { - self.notify(|notify| notify.broadcast(new_message.clone())); - } + self.engine.handle_message(UntrustedRlp::new(&message)); } fn signing_network_id(&self) -> Option { diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index b19de72e9..1962bec5f 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -52,6 +52,8 @@ pub enum ClientIoMessage { UpdateSealing, /// Submit seal (useful for internal sealing). SubmitSeal(H256, Vec), + /// Broadcast a message to the network. + BroadcastMessage(Bytes) } /// Client service setup. Creates and registers client and network services with the IO subsystem. @@ -222,11 +224,15 @@ impl IoHandler for ClientIoHandler { }, ClientIoMessage::UpdateSealing => { trace!(target: "poa", "message: UpdateSealing"); - self.client.update_sealing() + self.client.update_sealing(); }, ClientIoMessage::SubmitSeal(ref hash, ref seal) => { trace!(target: "poa", "message: SubmitSeal"); - self.client.submit_seal(*hash, seal.clone()) + self.client.submit_seal(*hash, seal.clone()); + }, + ClientIoMessage::BroadcastMessage(ref message) => { + trace!(target: "poa", "message: BroadcastMessage"); + self.client.broadcast_message(message.clone()); }, _ => {} // ignore other messages }