Merge pull request #404 from ethcore/cliopt
Allow path to be configured.
This commit is contained in:
commit
61c8f7b00b
@ -20,7 +20,6 @@ use util::*;
|
|||||||
use util::panics::*;
|
use util::panics::*;
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use error::*;
|
use error::*;
|
||||||
use std::env;
|
|
||||||
use client::Client;
|
use client::Client;
|
||||||
|
|
||||||
/// Message type for external and internal events
|
/// Message type for external and internal events
|
||||||
@ -44,16 +43,14 @@ pub struct ClientService {
|
|||||||
|
|
||||||
impl ClientService {
|
impl ClientService {
|
||||||
/// Start the service in a separate thread.
|
/// Start the service in a separate thread.
|
||||||
pub fn start(spec: Spec, net_config: NetworkConfiguration) -> Result<ClientService, Error> {
|
pub fn start(spec: Spec, net_config: NetworkConfiguration, db_path: &Path) -> Result<ClientService, Error> {
|
||||||
let panic_handler = PanicHandler::new_in_arc();
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
let mut net_service = try!(NetworkService::start(net_config));
|
let mut net_service = try!(NetworkService::start(net_config));
|
||||||
panic_handler.forward_from(&net_service);
|
panic_handler.forward_from(&net_service);
|
||||||
|
|
||||||
info!("Starting {}", net_service.host_info());
|
info!("Starting {}", net_service.host_info());
|
||||||
info!("Configured for {} using {} engine", spec.name, spec.engine_name);
|
info!("Configured for {} using {} engine", spec.name, spec.engine_name);
|
||||||
let mut dir = env::home_dir().unwrap();
|
let client = try!(Client::new(spec, db_path, net_service.io().channel()));
|
||||||
dir.push(".parity");
|
|
||||||
let client = try!(Client::new(spec, &dir, net_service.io().channel()));
|
|
||||||
panic_handler.forward_from(client.deref());
|
panic_handler.forward_from(client.deref());
|
||||||
let client_io = Arc::new(ClientIoHandler {
|
let client_io = Arc::new(ClientIoHandler {
|
||||||
client: client.clone()
|
client: client.clone()
|
||||||
|
@ -60,6 +60,7 @@ Usage:
|
|||||||
Options:
|
Options:
|
||||||
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file
|
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file
|
||||||
or frontier, mainnet, morden, or testnet [default: frontier].
|
or frontier, mainnet, morden, or testnet [default: frontier].
|
||||||
|
-d --db-path PATH Specify the database & configuration directory path [default: $HOME/.parity]
|
||||||
|
|
||||||
--listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304].
|
--listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304].
|
||||||
--public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304].
|
--public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304].
|
||||||
@ -129,7 +130,11 @@ impl Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_spec(&self) -> Spec {
|
fn path(&self) -> String {
|
||||||
|
self.args.flag_db_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spec(&self) -> Spec {
|
||||||
match self.args.flag_chain.as_ref() {
|
match self.args.flag_chain.as_ref() {
|
||||||
"frontier" | "mainnet" => ethereum::new_frontier(),
|
"frontier" | "mainnet" => ethereum::new_frontier(),
|
||||||
"morden" | "testnet" => ethereum::new_morden(),
|
"morden" | "testnet" => ethereum::new_morden(),
|
||||||
@ -138,14 +143,14 @@ impl Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_init_nodes(&self, spec: &Spec) -> Vec<String> {
|
fn init_nodes(&self, spec: &Spec) -> Vec<String> {
|
||||||
match self.args.arg_enode.len() {
|
match self.args.arg_enode.len() {
|
||||||
0 => spec.nodes().clone(),
|
0 => spec.nodes().clone(),
|
||||||
_ => self.args.arg_enode.clone(),
|
_ => self.args.arg_enode.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_net_addresses(&self) -> (SocketAddr, SocketAddr) {
|
fn net_addresses(&self) -> (SocketAddr, SocketAddr) {
|
||||||
let listen_address;
|
let listen_address;
|
||||||
let public_address;
|
let public_address;
|
||||||
|
|
||||||
@ -183,7 +188,7 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let spec = conf.get_spec();
|
let spec = conf.spec();
|
||||||
|
|
||||||
// Setup logging
|
// Setup logging
|
||||||
setup_log(&conf.args.flag_logging);
|
setup_log(&conf.args.flag_logging);
|
||||||
@ -193,13 +198,13 @@ fn main() {
|
|||||||
// Configure network
|
// Configure network
|
||||||
let mut net_settings = NetworkConfiguration::new();
|
let mut net_settings = NetworkConfiguration::new();
|
||||||
net_settings.nat_enabled = conf.args.flag_upnp;
|
net_settings.nat_enabled = conf.args.flag_upnp;
|
||||||
net_settings.boot_nodes = conf.get_init_nodes(&spec);
|
net_settings.boot_nodes = conf.init_nodes(&spec);
|
||||||
let (listen, public) = conf.get_net_addresses();
|
let (listen, public) = conf.net_addresses();
|
||||||
net_settings.listen_address = listen;
|
net_settings.listen_address = listen;
|
||||||
net_settings.public_address = public;
|
net_settings.public_address = public;
|
||||||
|
|
||||||
// Build client
|
// Build client
|
||||||
let mut service = ClientService::start(spec, net_settings).unwrap();
|
let mut service = ClientService::start(spec, net_settings, &Path::new(&conf.path())).unwrap();
|
||||||
let client = service.client().clone();
|
let client = service.client().clone();
|
||||||
client.configure_cache(conf.args.flag_cache_pref_size, conf.args.flag_cache_max_size);
|
client.configure_cache(conf.args.flag_cache_pref_size, conf.args.flag_cache_max_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user