2016-07-15 15:32:29 +02:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-07-15 17:39:59 +02:00
|
|
|
//! Parity sync service
|
2016-07-15 15:32:29 +02:00
|
|
|
|
2016-07-26 00:21:08 +02:00
|
|
|
use std;
|
2016-07-15 15:32:29 +02:00
|
|
|
use std::sync::Arc;
|
2016-08-24 18:35:38 +02:00
|
|
|
use hypervisor::{SYNC_MODULE_ID, HYPERVISOR_IPC_URL};
|
2016-07-16 15:51:06 +02:00
|
|
|
use ethcore::client::{RemoteClient, ChainNotify};
|
2016-07-20 18:13:56 +02:00
|
|
|
use ethsync::{SyncProvider, EthSync, ManageNetwork, ServiceConfiguration};
|
2016-07-15 15:32:29 +02:00
|
|
|
use std::thread;
|
2016-07-26 00:21:08 +02:00
|
|
|
use modules::service_urls;
|
2016-08-24 18:35:38 +02:00
|
|
|
use boot;
|
2016-07-15 15:32:29 +02:00
|
|
|
|
2016-07-26 00:21:08 +02:00
|
|
|
pub fn main() {
|
2016-08-24 18:35:38 +02:00
|
|
|
boot::setup_cli_logger("sync");
|
2016-07-20 18:13:56 +02:00
|
|
|
|
2016-08-24 18:35:38 +02:00
|
|
|
let service_config: ServiceConfiguration = boot::payload()
|
|
|
|
.unwrap_or_else(|e| panic!("Fatal: error reading boot arguments ({:?})", e));
|
2016-07-20 18:13:56 +02:00
|
|
|
|
2016-08-24 18:35:38 +02:00
|
|
|
let remote_client = dependency!(RemoteClient, &service_urls::with_base(&service_config.io_path, service_urls::CLIENT));
|
2016-07-20 18:13:56 +02:00
|
|
|
|
2016-08-24 18:35:38 +02:00
|
|
|
let stop = boot::main_thread();
|
2016-07-20 18:13:56 +02:00
|
|
|
let sync = EthSync::new(service_config.sync, remote_client.service().clone(), service_config.net).unwrap();
|
2016-07-15 15:32:29 +02:00
|
|
|
|
2016-08-24 18:35:38 +02:00
|
|
|
let _ = boot::register(
|
|
|
|
&service_urls::with_base(&service_config.io_path, HYPERVISOR_IPC_URL),
|
|
|
|
SYNC_MODULE_ID
|
|
|
|
);
|
|
|
|
|
|
|
|
boot::host_service(
|
2016-08-22 18:41:58 +02:00
|
|
|
&service_urls::with_base(&service_config.io_path, service_urls::SYNC),
|
|
|
|
stop.clone(),
|
|
|
|
sync.clone() as Arc<SyncProvider>
|
|
|
|
);
|
2016-08-24 18:35:38 +02:00
|
|
|
boot::host_service(
|
2016-08-22 18:41:58 +02:00
|
|
|
&service_urls::with_base(&service_config.io_path, service_urls::NETWORK_MANAGER),
|
|
|
|
stop.clone(),
|
|
|
|
sync.clone() as Arc<ManageNetwork>
|
|
|
|
);
|
2016-08-24 18:35:38 +02:00
|
|
|
boot::host_service(
|
2016-08-22 18:41:58 +02:00
|
|
|
&service_urls::with_base(&service_config.io_path, service_urls::SYNC_NOTIFY),
|
|
|
|
stop.clone(),
|
|
|
|
sync.clone() as Arc<ChainNotify>
|
|
|
|
);
|
|
|
|
|
2016-08-24 18:35:38 +02:00
|
|
|
while !stop.load(::std::sync::atomic::Ordering::Relaxed) {
|
2016-07-15 15:32:29 +02:00
|
|
|
thread::park_timeout(std::time::Duration::from_millis(1000));
|
|
|
|
}
|
|
|
|
}
|