IPC (feature-gated) (#1654)

* moving ipc deriving to trait

* refactoring of the client

* all compiled

* proved all working

* warnings purged

* allow hypervisor to specify initialization payload in two ways

* using binary initialisation payload for sync

* some docs

* logger to separate crate

* log settings for sync bin

* forwarding logging arguments to the sync
This commit is contained in:
Nikolay Volf
2016-07-20 18:13:56 +02:00
committed by Arkadiy Paronyan
parent 7ae9e61d6c
commit 8ab56ea3d1
22 changed files with 439 additions and 88 deletions

View File

@@ -46,3 +46,4 @@ test-heavy = []
dev = ["clippy"]
default = []
benches = []
ipc = []

View File

@@ -235,8 +235,8 @@ impl Client {
}
/// Adds an actor to be notified on certain events
pub fn add_notify(&self, target: &Arc<ChainNotify>) {
self.notify.write().push(Arc::downgrade(target));
pub fn add_notify(&self, target: Arc<ChainNotify>) {
self.notify.write().push(Arc::downgrade(&target));
}
fn notify<F>(&self, f: F) where F: Fn(&ChainNotify) {

View File

@@ -30,7 +30,7 @@ pub use self::test_client::{TestBlockChainClient, EachBlockWith};
pub use types::trace_filter::Filter as TraceFilter;
pub use executive::{Executed, Executive, TransactOptions};
pub use env_info::{LastHashes, EnvInfo};
pub use self::chain_notify::ChainNotify;
pub use self::chain_notify::{ChainNotify, ChainNotifyClient};
pub use types::call_analytics::CallAnalytics;
pub use block_import_error::BlockImportError;

View File

@@ -22,6 +22,12 @@ use spec::Spec;
use error::*;
use client::{Client, ClientConfig, ChainNotify};
use miner::Miner;
use std::sync::atomic::AtomicBool;
#[cfg(feature="ipc")]
use nanoipc;
#[cfg(feature="ipc")]
use client::BlockChainClient;
/// Message type for external and internal events
#[derive(Clone)]
@@ -38,7 +44,8 @@ pub enum ClientIoMessage {
pub struct ClientService {
io_service: Arc<IoService<ClientIoMessage>>,
client: Arc<Client>,
panic_handler: Arc<PanicHandler>
panic_handler: Arc<PanicHandler>,
_stop_guard: ::devtools::StopGuard,
}
impl ClientService {
@@ -62,10 +69,14 @@ impl ClientService {
});
try!(io_service.register_handler(client_io));
let stop_guard = ::devtools::StopGuard::new();
run_ipc(client.clone(), stop_guard.share());
Ok(ClientService {
io_service: Arc::new(io_service),
client: client,
panic_handler: panic_handler,
_stop_guard: stop_guard,
})
}
@@ -90,7 +101,7 @@ impl ClientService {
}
/// Set the actor to be notified on certain chain events
pub fn add_notify(&self, notify: &Arc<ChainNotify>) {
pub fn add_notify(&self, notify: Arc<ChainNotify>) {
self.client.add_notify(notify);
}
}
@@ -130,6 +141,22 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
}
}
#[cfg(feature="ipc")]
fn run_ipc(client: Arc<Client>, stop: Arc<AtomicBool>) {
::std::thread::spawn(move || {
let mut worker = nanoipc::Worker::new(&(client as Arc<BlockChainClient>));
worker.add_reqrep("ipc:///tmp/parity-chain.ipc").expect("Ipc expected to initialize with no issues");
while !stop.load(::std::sync::atomic::Ordering::Relaxed) {
worker.poll();
}
});
}
#[cfg(not(feature="ipc"))]
fn run_ipc(_client: Arc<Client>, _stop: Arc<AtomicBool>) {
}
#[cfg(test)]
mod tests {
use super::*;