Merge branch 'master' of github.com:ethcore/parity
This commit is contained in:
@@ -30,6 +30,7 @@ extern crate env_logger;
|
||||
extern crate ctrlc;
|
||||
extern crate fdlimit;
|
||||
extern crate daemonize;
|
||||
extern crate time;
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
extern crate ethcore_rpc as rpc;
|
||||
@@ -38,7 +39,6 @@ use std::net::{SocketAddr};
|
||||
use std::env;
|
||||
use std::process::exit;
|
||||
use std::path::PathBuf;
|
||||
use rlog::{LogLevelFilter};
|
||||
use env_logger::LogBuilder;
|
||||
use ctrlc::CtrlC;
|
||||
use util::*;
|
||||
@@ -52,7 +52,7 @@ use ethsync::EthSync;
|
||||
use docopt::Docopt;
|
||||
use daemonize::Daemonize;
|
||||
|
||||
const USAGE: &'static str = "
|
||||
const USAGE: &'static str = r#"
|
||||
Parity. Ethereum Client.
|
||||
By Wood/Paronyan/Kotewicz/Drwięga/Volf.
|
||||
Copyright 2015, 2016 Ethcore (UK) Limited
|
||||
@@ -71,9 +71,9 @@ Options:
|
||||
--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.
|
||||
--address URL Equivalent to --listen-address URL --public-address URL.
|
||||
--peers NUM Try to manintain that many peers [default: 25].
|
||||
--peers NUM Try to maintain that many peers [default: 25].
|
||||
--no-discovery Disable new peer discovery.
|
||||
--upnp Use UPnP to try to figure out the correct network settings.
|
||||
--no-upnp Disable trying to figure out the correct public adderss over UPnP.
|
||||
--node-key KEY Specify node secret key, either as 64-character hex string or input to SHA3 operation.
|
||||
|
||||
--cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes [default: 16384].
|
||||
@@ -81,11 +81,12 @@ Options:
|
||||
|
||||
-j --jsonrpc Enable the JSON-RPC API sever.
|
||||
--jsonrpc-url URL Specify URL for JSON-RPC API server [default: 127.0.0.1:8545].
|
||||
--jsonrpc-cors URL Specify CORS header for JSON-RPC API responses [default: null].
|
||||
|
||||
-l --logging LOGGING Specify the logging level.
|
||||
-v --version Show information about version.
|
||||
-h --help Show this screen.
|
||||
";
|
||||
"#;
|
||||
|
||||
#[derive(Debug, RustcDecodable)]
|
||||
struct Args {
|
||||
@@ -101,17 +102,20 @@ struct Args {
|
||||
flag_address: Option<String>,
|
||||
flag_peers: u32,
|
||||
flag_no_discovery: bool,
|
||||
flag_upnp: bool,
|
||||
flag_no_upnp: bool,
|
||||
flag_node_key: Option<String>,
|
||||
flag_cache_pref_size: usize,
|
||||
flag_cache_max_size: usize,
|
||||
flag_jsonrpc: bool,
|
||||
flag_jsonrpc_url: String,
|
||||
flag_jsonrpc_cors: String,
|
||||
flag_logging: Option<String>,
|
||||
flag_version: bool,
|
||||
}
|
||||
|
||||
fn setup_log(init: &Option<String>) {
|
||||
use rlog::*;
|
||||
|
||||
let mut builder = LogBuilder::new();
|
||||
builder.filter(None, LogLevelFilter::Info);
|
||||
|
||||
@@ -123,11 +127,20 @@ fn setup_log(init: &Option<String>) {
|
||||
builder.parse(s);
|
||||
}
|
||||
|
||||
let format = |record: &LogRecord| {
|
||||
let timestamp = time::strftime("%Y-%m-%d %H:%M:%S %Z", &time::now()).unwrap();
|
||||
if max_log_level() <= LogLevelFilter::Info {
|
||||
format!("{}{}", timestamp, record.args())
|
||||
} else {
|
||||
format!("{}{}:{}: {}", timestamp, record.level(), record.target(), record.args())
|
||||
}
|
||||
};
|
||||
builder.format(format);
|
||||
builder.init().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str, cors_domain: &str) {
|
||||
use rpc::v1::*;
|
||||
|
||||
let mut server = rpc::HttpServer::new(1);
|
||||
@@ -135,7 +148,7 @@ fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
||||
server.add_delegate(EthClient::new(client.clone(), sync.clone()).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(client).to_delegate());
|
||||
server.add_delegate(NetClient::new(sync).to_delegate());
|
||||
server.start_async(url);
|
||||
server.start_async(url, cors_domain);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "rpc"))]
|
||||
@@ -181,7 +194,7 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn _keys_path(&self) -> String {
|
||||
self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
|
||||
self.args.flag_keys_path.replace("$HOME", env::home_dir().unwrap().to_str().unwrap())
|
||||
}
|
||||
|
||||
fn spec(&self) -> Spec {
|
||||
@@ -194,9 +207,10 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn normalize_enode(e: &str) -> Option<String> {
|
||||
match is_valid_node_url(e) {
|
||||
true => Some(e.to_owned()),
|
||||
false => None,
|
||||
if is_valid_node_url(e) {
|
||||
Some(e.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,34 +223,35 @@ impl Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature="dev", allow(useless_format))]
|
||||
fn net_addresses(&self) -> (Option<SocketAddr>, Option<SocketAddr>) {
|
||||
let mut listen_address = None;
|
||||
let mut public_address = None;
|
||||
|
||||
if let Some(ref a) = self.args.flag_address {
|
||||
public_address = Some(SocketAddr::from_str(a.as_ref()).expect("Invalid listen/public address given with --address"));
|
||||
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --address", a)));
|
||||
listen_address = public_address;
|
||||
}
|
||||
if listen_address.is_none() {
|
||||
listen_address = Some(SocketAddr::from_str(self.args.flag_listen_address.as_ref()).expect("Invalid listen address given with --listen-address"));
|
||||
listen_address = Some(SocketAddr::from_str(self.args.flag_listen_address.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --listen-address", self.args.flag_listen_address)));
|
||||
}
|
||||
if let Some(ref a) = self.args.flag_public_address {
|
||||
if public_address.is_some() {
|
||||
panic!("Conflicting flags: --address and --public-address");
|
||||
die!("Conflicting flags provided: --address and --public-address");
|
||||
}
|
||||
public_address = Some(SocketAddr::from_str(a.as_ref()).expect("Invalid listen address given with --public-address"));
|
||||
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --public-address", a)));
|
||||
}
|
||||
(listen_address, public_address)
|
||||
}
|
||||
|
||||
fn net_settings(&self, spec: &Spec) -> NetworkConfiguration {
|
||||
let mut ret = NetworkConfiguration::new();
|
||||
ret.nat_enabled = self.args.flag_upnp;
|
||||
ret.nat_enabled = !self.args.flag_no_upnp;
|
||||
ret.boot_nodes = self.init_nodes(spec);
|
||||
let (listen, public) = self.net_addresses();
|
||||
ret.listen_address = listen;
|
||||
ret.public_address = public;
|
||||
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| Secret::from_str(&s).expect("Invalid key string"));
|
||||
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| Secret::from_str(&s).unwrap_or_else(|_| s.sha3()));
|
||||
ret.discovery_enabled = !self.args.flag_no_discovery;
|
||||
ret.ideal_peers = self.args.flag_peers;
|
||||
let mut net_path = PathBuf::from(&self.path());
|
||||
@@ -279,7 +294,8 @@ impl Configuration {
|
||||
|
||||
// Setup rpc
|
||||
if self.args.flag_jsonrpc {
|
||||
setup_rpc_server(service.client(), sync.clone(), &self.args.flag_jsonrpc_url);
|
||||
setup_rpc_server(service.client(), sync.clone(), &self.args.flag_jsonrpc_url, &self.args.flag_jsonrpc_cors);
|
||||
SocketAddr::from_str(&self.args.flag_jsonrpc_url).unwrap_or_else(|_|die!("{}: Invalid JSONRPC listen address given with --jsonrpc-url. Should be of the form 'IP:port'.", self.args.flag_jsonrpc_url));
|
||||
}
|
||||
|
||||
// Register IO handler
|
||||
|
||||
Reference in New Issue
Block a user