Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #404 from ethcore/cliopt
Browse files Browse the repository at this point in the history
Allow path to be configured.
  • Loading branch information
arkpar committed Feb 10, 2016
2 parents 3e49c96 + b4faad8 commit 61c8f7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
7 changes: 2 additions & 5 deletions ethcore/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use util::*;
use util::panics::*;
use spec::Spec;
use error::*;
use std::env;
use client::Client;

/// Message type for external and internal events
Expand All @@ -44,16 +43,14 @@ pub struct ClientService {

impl ClientService {
/// 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 mut net_service = try!(NetworkService::start(net_config));
panic_handler.forward_from(&net_service);

info!("Starting {}", net_service.host_info());
info!("Configured for {} using {} engine", spec.name, spec.engine_name);
let mut dir = env::home_dir().unwrap();
dir.push(".parity");
let client = try!(Client::new(spec, &dir, net_service.io().channel()));
let client = try!(Client::new(spec, db_path, net_service.io().channel()));
panic_handler.forward_from(client.deref());
let client_io = Arc::new(ClientIoHandler {
client: client.clone()
Expand Down
19 changes: 12 additions & 7 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Usage:
Options:
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file
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].
--public-address URL Specify the IP/port on which peers may connect [default: 0.0.0.0:30304].
Expand Down Expand Up @@ -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() {
"frontier" | "mainnet" => ethereum::new_frontier(),
"morden" | "testnet" => ethereum::new_morden(),
Expand All @@ -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() {
0 => spec.nodes().clone(),
_ => self.args.arg_enode.clone(),
}
}

fn get_net_addresses(&self) -> (SocketAddr, SocketAddr) {
fn net_addresses(&self) -> (SocketAddr, SocketAddr) {
let listen_address;
let public_address;

Expand Down Expand Up @@ -183,7 +188,7 @@ fn main() {
return;
}

let spec = conf.get_spec();
let spec = conf.spec();

// Setup logging
setup_log(&conf.args.flag_logging);
Expand All @@ -193,13 +198,13 @@ fn main() {
// Configure network
let mut net_settings = NetworkConfiguration::new();
net_settings.nat_enabled = conf.args.flag_upnp;
net_settings.boot_nodes = conf.get_init_nodes(&spec);
let (listen, public) = conf.get_net_addresses();
net_settings.boot_nodes = conf.init_nodes(&spec);
let (listen, public) = conf.net_addresses();
net_settings.listen_address = listen;
net_settings.public_address = public;

// 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();
client.configure_cache(conf.args.flag_cache_pref_size, conf.args.flag_cache_max_size);

Expand Down

0 comments on commit 61c8f7b

Please sign in to comment.