moving to the single binary (#1710)

This commit is contained in:
Nikolay Volf 2016-07-26 01:21:08 +03:00 committed by Gav Wood
parent 856657e39a
commit f614a69929
5 changed files with 33 additions and 32 deletions

View File

@ -65,10 +65,6 @@ ipc = ["ethcore/ipc"]
path = "parity/main.rs"
name = "parity"
[[bin]]
path = "parity/sync/main.rs"
name = "sync"
[profile.release]
debug = true
lto = false

View File

@ -78,6 +78,7 @@ mod account;
mod blockchain;
mod presale;
mod run;
mod sync;
use std::{process, env};
use cli::print_version;
@ -111,6 +112,12 @@ fn start() -> Result<String, String> {
}
fn main() {
// just redirect to the sync::main()
if std::env::args().nth(1).map(|arg| arg == "sync").unwrap_or(false) {
sync::main();
return;
}
match start() {
Ok(result) => {
print!("{}", result);

View File

@ -25,6 +25,13 @@ use self::no_ipc_deps::*;
use self::ipc_deps::*;
use ethcore_logger::Config as LogConfig;
pub mod service_urls {
pub const CLIENT: &'static str = "ipc:///tmp/parity-chain.ipc";
pub const SYNC: &'static str = "ipc:///tmp/parity-sync.ipc";
pub const SYNC_NOTIFY: &'static str = "ipc:///tmp/parity-sync-notify.ipc";
pub const NETWORK_MANAGER: &'static str = "ipc:///tmp/parity-manage-net.ipc";
}
#[cfg(not(feature="ipc"))]
mod no_ipc_deps {
pub use ethsync::{EthSync, SyncProvider, ManageNetwork};
@ -51,7 +58,6 @@ mod ipc_deps {
pub use ipc::binary::serialize;
}
#[cfg(feature="ipc")]
pub fn hypervisor() -> Option<Hypervisor> {
Some(Hypervisor::new())
@ -74,11 +80,11 @@ fn sync_arguments(sync_cfg: SyncConfig, net_cfg: NetworkConfiguration, log_setti
// client service url and logging settings are passed in command line
let mut cli_args = Vec::new();
cli_args.push("ipc:///tmp/parity-chain.ipc".to_owned());
cli_args.push("sync".to_owned());
if !log_settings.color { cli_args.push("--no-color".to_owned()); }
if let Some(ref init) = log_settings.init {
if let Some(ref mode) = log_settings.mode {
cli_args.push("-l".to_owned());
cli_args.push(init.to_owned());
cli_args.push(mode.to_owned());
}
if let Some(ref file) = log_settings.file {
cli_args.push("--log-file".to_owned());
@ -100,14 +106,14 @@ pub fn sync
-> Result<SyncModules, ethcore::error::Error>
{
let mut hypervisor = hypervisor_ref.take().expect("There should be hypervisor for ipc configuration");
hypervisor = hypervisor.module(SYNC_MODULE_ID, "sync", sync_arguments(sync_cfg, net_cfg, log_settings));
hypervisor = hypervisor.module(SYNC_MODULE_ID, "parity", sync_arguments(sync_cfg, net_cfg, log_settings));
hypervisor.start();
hypervisor.wait_for_startup();
let sync_client = init_client::<SyncClient<_>>("ipc:///tmp/parity-sync.ipc").unwrap();
let notify_client = init_client::<ChainNotifyClient<_>>("ipc:///tmp/parity-sync-notify.ipc").unwrap();
let manage_client = init_client::<NetworkManagerClient<_>>("ipc:///tmp/parity-manage-net.ipc").unwrap();
let sync_client = init_client::<SyncClient<_>>(service_urls::SYNC).unwrap();
let notify_client = init_client::<ChainNotifyClient<_>>(service_urls::SYNC_NOTIFY).unwrap();
let manage_client = init_client::<NetworkManagerClient<_>>(service_urls::NETWORK_MANAGER).unwrap();
*hypervisor_ref = Some(hypervisor);
Ok((sync_client, manage_client, notify_client))

View File

@ -28,6 +28,8 @@ use ethcore::account_provider::AccountProvider;
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
use ethsync::SyncConfig;
use informant::Informant;
#[cfg(feature="ipc")]
use ethcore::client::ChainNotify;
use rpc::{HttpServer, IpcServer, HttpConfiguration, IpcConfiguration};
use signer::SignerServer;

View File

@ -16,18 +16,9 @@
//! Parity sync service
extern crate ethcore_ipc_nano as nanoipc;
extern crate ethcore_ipc_hypervisor as hypervisor;
extern crate ethcore_ipc as ipc;
extern crate ctrlc;
#[macro_use] extern crate log;
extern crate ethsync;
extern crate rustc_serialize;
extern crate docopt;
extern crate ethcore;
extern crate ethcore_util as util;
extern crate ethcore_logger;
use nanoipc;
use ipc;
use std;
use std::sync::Arc;
use hypervisor::{HypervisorServiceClient, SYNC_MODULE_ID, HYPERVISOR_IPC_URL};
use ctrlc::CtrlC;
@ -37,13 +28,13 @@ use ethcore::client::{RemoteClient, ChainNotify};
use ethsync::{SyncProvider, EthSync, ManageNetwork, ServiceConfiguration};
use std::thread;
use nanoipc::IpcInterface;
use modules::service_urls;
use ethcore_logger::{Config as LogConfig, setup_log};
const USAGE: &'static str = "
Ethcore sync service
Usage:
sync <client-url> [options]
parity sync [options]
Options:
-l --logging LOGGING Specify the logging level. Must conform to the same
@ -55,7 +46,6 @@ Usage:
#[derive(Debug, RustcDecodable)]
struct Args {
arg_client_url: String,
flag_logging: Option<String>,
flag_log_file: Option<String>,
flag_no_color: bool,
@ -83,7 +73,7 @@ fn run_service<T: ?Sized + Send + Sync + 'static>(addr: &str, stop_guard: Arc<At
});
}
fn main() {
pub fn main() {
use std::io::{self, Read};
let args: Args = Docopt::new(USAGE)
@ -96,16 +86,16 @@ fn main() {
io::stdin().read_to_end(&mut buffer).expect("Failed to read initialisation payload");
let service_config = ipc::binary::deserialize::<ServiceConfiguration>(&buffer).expect("Failed deserializing initialisation payload");
let remote_client = nanoipc::init_client::<RemoteClient<_>>(&args.arg_client_url).unwrap();
let remote_client = nanoipc::init_client::<RemoteClient<_>>(service_urls::CLIENT).unwrap();
remote_client.handshake().unwrap();
let stop = Arc::new(AtomicBool::new(false));
let sync = EthSync::new(service_config.sync, remote_client.service().clone(), service_config.net).unwrap();
run_service("ipc:///tmp/parity-sync.ipc", stop.clone(), sync.clone() as Arc<SyncProvider>);
run_service("ipc:///tmp/parity-manage-net.ipc", stop.clone(), sync.clone() as Arc<ManageNetwork>);
run_service("ipc:///tmp/parity-sync-notify.ipc", stop.clone(), sync.clone() as Arc<ChainNotify>);
run_service(service_urls::SYNC, stop.clone(), sync.clone() as Arc<SyncProvider>);
run_service(service_urls::NETWORK_MANAGER, stop.clone(), sync.clone() as Arc<ManageNetwork>);
run_service(service_urls::SYNC_NOTIFY, stop.clone(), sync.clone() as Arc<ChainNotify>);
let hypervisor_client = nanoipc::init_client::<HypervisorServiceClient<_>>(HYPERVISOR_IPC_URL).unwrap();
hypervisor_client.handshake().unwrap();