add new client messaging

This commit is contained in:
keorn 2016-11-17 12:17:48 +00:00
parent 802d5c669d
commit 45027ea306
2 changed files with 14 additions and 5 deletions

View File

@ -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. /// Attempt to get a copy of a specific block's final state.
/// ///
/// This will not fail if given BlockID::Latest. /// This will not fail if given BlockID::Latest.
@ -1231,9 +1236,7 @@ impl BlockChainClient for Client {
// TODO: Make it an actual queue, return errors. // TODO: Make it an actual queue, return errors.
fn queue_infinity_message(&self, message: Bytes) { fn queue_infinity_message(&self, message: Bytes) {
if let Ok(new_message) = self.engine.handle_message(UntrustedRlp::new(&message)) { self.engine.handle_message(UntrustedRlp::new(&message));
self.notify(|notify| notify.broadcast(new_message.clone()));
}
} }
fn signing_network_id(&self) -> Option<u8> { fn signing_network_id(&self) -> Option<u8> {

View File

@ -52,6 +52,8 @@ pub enum ClientIoMessage {
UpdateSealing, UpdateSealing,
/// Submit seal (useful for internal sealing). /// Submit seal (useful for internal sealing).
SubmitSeal(H256, Vec<Bytes>), SubmitSeal(H256, Vec<Bytes>),
/// Broadcast a message to the network.
BroadcastMessage(Bytes)
} }
/// Client service setup. Creates and registers client and network services with the IO subsystem. /// Client service setup. Creates and registers client and network services with the IO subsystem.
@ -222,11 +224,15 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
}, },
ClientIoMessage::UpdateSealing => { ClientIoMessage::UpdateSealing => {
trace!(target: "poa", "message: UpdateSealing"); trace!(target: "poa", "message: UpdateSealing");
self.client.update_sealing() self.client.update_sealing();
}, },
ClientIoMessage::SubmitSeal(ref hash, ref seal) => { ClientIoMessage::SubmitSeal(ref hash, ref seal) => {
trace!(target: "poa", "message: SubmitSeal"); 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 _ => {} // ignore other messages
} }