diff --git a/Cargo.toml b/Cargo.toml index 6c71a1f6d..6623db741 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/parity/main.rs b/parity/main.rs index 50b2d9c4b..b5c68d27b 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -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 { } 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); diff --git a/parity/modules.rs b/parity/modules.rs index de8e68027..4e2e22ffb 100644 --- a/parity/modules.rs +++ b/parity/modules.rs @@ -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 { 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 { 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::>("ipc:///tmp/parity-sync.ipc").unwrap(); - let notify_client = init_client::>("ipc:///tmp/parity-sync-notify.ipc").unwrap(); - let manage_client = init_client::>("ipc:///tmp/parity-manage-net.ipc").unwrap(); + let sync_client = init_client::>(service_urls::SYNC).unwrap(); + let notify_client = init_client::>(service_urls::SYNC_NOTIFY).unwrap(); + let manage_client = init_client::>(service_urls::NETWORK_MANAGER).unwrap(); *hypervisor_ref = Some(hypervisor); Ok((sync_client, manage_client, notify_client)) diff --git a/parity/run.rs b/parity/run.rs index f31bcf916..446f8e0af 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -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; diff --git a/parity/sync/main.rs b/parity/sync.rs similarity index 80% rename from parity/sync/main.rs rename to parity/sync.rs index f99d3b2bc..447f3678c 100644 --- a/parity/sync/main.rs +++ b/parity/sync.rs @@ -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 [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, flag_log_file: Option, flag_no_color: bool, @@ -83,7 +73,7 @@ fn run_service(addr: &str, stop_guard: Arc(&buffer).expect("Failed deserializing initialisation payload"); - let remote_client = nanoipc::init_client::>(&args.arg_client_url).unwrap(); + let remote_client = nanoipc::init_client::>(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); - run_service("ipc:///tmp/parity-manage-net.ipc", stop.clone(), sync.clone() as Arc); - run_service("ipc:///tmp/parity-sync-notify.ipc", stop.clone(), sync.clone() as Arc); + run_service(service_urls::SYNC, stop.clone(), sync.clone() as Arc); + run_service(service_urls::NETWORK_MANAGER, stop.clone(), sync.clone() as Arc); + run_service(service_urls::SYNC_NOTIFY, stop.clone(), sync.clone() as Arc); let hypervisor_client = nanoipc::init_client::>(HYPERVISOR_IPC_URL).unwrap(); hypervisor_client.handshake().unwrap();