Merge branch 'lightcli' into light-filters
This commit is contained in:
@@ -167,6 +167,8 @@ usage! {
|
||||
or |c: &Config| otry!(c.rpc).apis.as_ref().map(|vec| vec.join(",")),
|
||||
flag_jsonrpc_hosts: String = "none",
|
||||
or |c: &Config| otry!(c.rpc).hosts.as_ref().map(|vec| vec.join(",")),
|
||||
flag_jsonrpc_threads: Option<usize> = None,
|
||||
or |c: &Config| otry!(c.rpc).threads.map(Some),
|
||||
|
||||
// IPC
|
||||
flag_no_ipc: bool = false,
|
||||
@@ -179,21 +181,8 @@ usage! {
|
||||
// DAPPS
|
||||
flag_no_dapps: bool = false,
|
||||
or |c: &Config| otry!(c.dapps).disable.clone(),
|
||||
flag_dapps_port: u16 = 8080u16,
|
||||
or |c: &Config| otry!(c.dapps).port.clone(),
|
||||
flag_dapps_interface: String = "local",
|
||||
or |c: &Config| otry!(c.dapps).interface.clone(),
|
||||
flag_dapps_hosts: String = "none",
|
||||
or |c: &Config| otry!(c.dapps).hosts.as_ref().map(|vec| vec.join(",")),
|
||||
flag_dapps_cors: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).cors.clone().map(Some),
|
||||
flag_dapps_path: String = "$BASE/dapps",
|
||||
or |c: &Config| otry!(c.dapps).path.clone(),
|
||||
flag_dapps_user: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).user.clone().map(Some),
|
||||
flag_dapps_pass: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).pass.clone().map(Some),
|
||||
flag_dapps_apis_all: bool = false, or |_| None,
|
||||
|
||||
// Secret Store
|
||||
flag_no_secretstore: bool = false,
|
||||
@@ -333,6 +322,22 @@ usage! {
|
||||
or |c: &Config| otry!(c.misc).log_file.clone().map(Some),
|
||||
flag_no_color: bool = false,
|
||||
or |c: &Config| otry!(c.misc).color.map(|c| !c).clone(),
|
||||
|
||||
|
||||
// -- Legacy Options supported in configs
|
||||
flag_dapps_port: Option<u16> = None,
|
||||
or |c: &Config| otry!(c.dapps).port.clone().map(Some),
|
||||
flag_dapps_interface: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).interface.clone().map(Some),
|
||||
flag_dapps_hosts: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).hosts.as_ref().map(|vec| Some(vec.join(","))),
|
||||
flag_dapps_cors: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).cors.clone().map(Some),
|
||||
flag_dapps_user: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).user.clone().map(Some),
|
||||
flag_dapps_pass: Option<String> = None,
|
||||
or |c: &Config| otry!(c.dapps).pass.clone().map(Some),
|
||||
flag_dapps_apis_all: Option<bool> = None, or |_| None,
|
||||
}
|
||||
{
|
||||
// Values with optional default value.
|
||||
@@ -424,6 +429,7 @@ struct Rpc {
|
||||
cors: Option<String>,
|
||||
apis: Option<Vec<String>>,
|
||||
hosts: Option<Vec<String>>,
|
||||
threads: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
@@ -679,6 +685,7 @@ mod tests {
|
||||
flag_jsonrpc_cors: Some("null".into()),
|
||||
flag_jsonrpc_apis: "web3,eth,net,parity,traces,rpc".into(),
|
||||
flag_jsonrpc_hosts: "none".into(),
|
||||
flag_jsonrpc_threads: None,
|
||||
|
||||
// IPC
|
||||
flag_no_ipc: false,
|
||||
@@ -686,15 +693,8 @@ mod tests {
|
||||
flag_ipc_apis: "web3,eth,net,parity,parity_accounts,personal,traces,rpc".into(),
|
||||
|
||||
// DAPPS
|
||||
flag_no_dapps: false,
|
||||
flag_dapps_port: 8080u16,
|
||||
flag_dapps_interface: "local".into(),
|
||||
flag_dapps_hosts: "none".into(),
|
||||
flag_dapps_cors: None,
|
||||
flag_dapps_path: "$HOME/.parity/dapps".into(),
|
||||
flag_dapps_user: Some("test_user".into()),
|
||||
flag_dapps_pass: Some("test_pass".into()),
|
||||
flag_dapps_apis_all: false,
|
||||
flag_no_dapps: false,
|
||||
|
||||
flag_no_secretstore: false,
|
||||
flag_secretstore_port: 8082u16,
|
||||
@@ -799,6 +799,14 @@ mod tests {
|
||||
flag_extradata: None,
|
||||
flag_cache: None,
|
||||
flag_warp: Some(true),
|
||||
// Legacy-Dapps
|
||||
flag_dapps_port: Some(8080),
|
||||
flag_dapps_interface: Some("local".into()),
|
||||
flag_dapps_hosts: Some("none".into()),
|
||||
flag_dapps_cors: None,
|
||||
flag_dapps_user: Some("test_user".into()),
|
||||
flag_dapps_pass: Some("test_pass".into()),
|
||||
flag_dapps_apis_all: None,
|
||||
|
||||
// -- Miscellaneous Options
|
||||
flag_version: false,
|
||||
@@ -882,6 +890,7 @@ mod tests {
|
||||
cors: None,
|
||||
apis: None,
|
||||
hosts: None,
|
||||
threads: None,
|
||||
}),
|
||||
ipc: Some(Ipc {
|
||||
disable: None,
|
||||
|
||||
@@ -72,9 +72,9 @@ Operating Options:
|
||||
--identity NAME Specify your node's name. (default: {flag_identity})
|
||||
--light Experimental: run in light client mode. Light clients
|
||||
synchronize a bare minimum of data and fetch necessary
|
||||
data on-demand from the network. Much lower in storage,
|
||||
potentially higher in bandwidth. Has no effect with
|
||||
subcommands (default: {flag_light})
|
||||
data on-demand from the network. Much lower in storage,
|
||||
potentially higher in bandwidth. Has no effect with
|
||||
subcommands (default: {flag_light}).
|
||||
|
||||
Account Options:
|
||||
--unlock ACCOUNTS Unlock ACCOUNTS for the duration of the execution.
|
||||
@@ -155,6 +155,8 @@ API and Console Options:
|
||||
is additional security against some attack
|
||||
vectors. Special options: "all", "none",
|
||||
(default: {flag_jsonrpc_hosts}).
|
||||
--jsonrpc-threads THREADS Enables experimental faster implementation of JSON-RPC server.
|
||||
Requires Dapps server to be disabled using --no-dapps. (default: {flag_jsonrpc_threads:?})
|
||||
|
||||
--no-ipc Disable JSON-RPC over IPC service. (default: {flag_no_ipc})
|
||||
--ipc-path PATH Specify custom path for JSON-RPC over IPC service
|
||||
@@ -163,29 +165,8 @@ API and Console Options:
|
||||
IPC (default: {flag_ipc_apis}).
|
||||
|
||||
--no-dapps Disable the Dapps server (e.g. status page). (default: {flag_no_dapps})
|
||||
--dapps-port PORT Specify the port portion of the Dapps server
|
||||
(default: {flag_dapps_port}).
|
||||
--dapps-interface IP Specify the hostname portion of the Dapps
|
||||
server, IP should be an interface's IP address,
|
||||
or local (default: {flag_dapps_interface}).
|
||||
--dapps-hosts HOSTS List of allowed Host header values. This option will
|
||||
validate the Host header sent by the browser, it
|
||||
is additional security against some attack
|
||||
vectors. Special options: "all", "none",
|
||||
(default: {flag_dapps_hosts}).
|
||||
--dapps-cors URL Specify CORS headers for Dapps server APIs.
|
||||
(default: {flag_dapps_cors:?})
|
||||
--dapps-user USERNAME Specify username for Dapps server. It will be
|
||||
used in HTTP Basic Authentication Scheme.
|
||||
If --dapps-pass is not specified you will be
|
||||
asked for password on startup. (default: {flag_dapps_user:?})
|
||||
--dapps-pass PASSWORD Specify password for Dapps server. Use only in
|
||||
conjunction with --dapps-user. (default: {flag_dapps_pass:?})
|
||||
--dapps-path PATH Specify directory where dapps should be installed.
|
||||
(default: {flag_dapps_path})
|
||||
--dapps-apis-all Expose all possible RPC APIs on Dapps port.
|
||||
WARNING: INSECURE. Used only for development.
|
||||
(default: {flag_dapps_apis_all})
|
||||
--ipfs-api Enable IPFS-compatible HTTP API. (default: {flag_ipfs_api})
|
||||
--ipfs-api-port PORT Configure on which port the IPFS HTTP API should listen.
|
||||
(default: {flag_ipfs_api_port})
|
||||
@@ -398,6 +379,13 @@ Legacy Options:
|
||||
--jsonrpc-off Equivalent to --no-jsonrpc.
|
||||
-w --webapp Does nothing; dapps server is on by default now.
|
||||
--dapps-off Equivalent to --no-dapps.
|
||||
--dapps-user USERNAME Dapps server authentication has been removed. (default: {flag_dapps_user:?})
|
||||
--dapps-pass PASSWORD Dapps server authentication has been removed. (default: {flag_dapps_pass:?})
|
||||
--dapps-apis-all Dapps server is merged with RPC server. Use --jsonrpc-apis. (default: {flag_dapps_apis_all:?})
|
||||
--dapps-cors URL Dapps server is merged with RPC server. Use --jsonrpc-cors. (default: {flag_dapps_cors:?})
|
||||
--dapps-hosts HOSTS Dapps server is merged with RPC server. Use --jsonrpc-hosts. (default: {flag_dapps_hosts:?})
|
||||
--dapps-interface IP Dapps server is merged with RPC server. Use --jsonrpc-interface. (default: {flag_dapps_interface:?})
|
||||
--dapps-port PORT Dapps server is merged with RPC server. Use --jsonrpc-port. (default: {flag_dapps_port:?})
|
||||
--rpc Does nothing; JSON-RPC is on by default now.
|
||||
--warp Does nothing; Warp sync is on by default. (default: {flag_warp})
|
||||
--rpcaddr IP Equivalent to --jsonrpc-interface IP.
|
||||
|
||||
@@ -132,12 +132,17 @@ impl Configuration {
|
||||
let warp_sync = !self.args.flag_no_warp && fat_db != Switch::On && tracing != Switch::On && pruning != Pruning::Specific(Algorithm::Archive);
|
||||
let geth_compatibility = self.args.flag_geth;
|
||||
let ui_address = self.ui_port().map(|port| (self.ui_interface(), port));
|
||||
let dapps_conf = self.dapps_config();
|
||||
let mut dapps_conf = self.dapps_config();
|
||||
let ipfs_conf = self.ipfs_config();
|
||||
let signer_conf = self.signer_config();
|
||||
let secretstore_conf = self.secretstore_config();
|
||||
let format = self.format()?;
|
||||
|
||||
if self.args.flag_jsonrpc_threads.is_some() && dapps_conf.enabled {
|
||||
dapps_conf.enabled = false;
|
||||
writeln!(&mut stderr(), "Warning: Disabling Dapps server because fast RPC server was enabled.").expect("Error writing to stderr.")
|
||||
}
|
||||
|
||||
let cmd = if self.args.flag_version {
|
||||
Cmd::Version
|
||||
} else if self.args.cmd_signer {
|
||||
@@ -556,19 +561,12 @@ impl Configuration {
|
||||
fn dapps_config(&self) -> DappsConfiguration {
|
||||
DappsConfiguration {
|
||||
enabled: self.dapps_enabled(),
|
||||
interface: self.dapps_interface(),
|
||||
port: self.args.flag_dapps_port,
|
||||
hosts: self.dapps_hosts(),
|
||||
cors: self.dapps_cors(),
|
||||
user: self.args.flag_dapps_user.clone(),
|
||||
pass: self.args.flag_dapps_pass.clone(),
|
||||
dapps_path: PathBuf::from(self.directories().dapps),
|
||||
extra_dapps: if self.args.cmd_dapp {
|
||||
self.args.arg_path.iter().map(|path| PathBuf::from(path)).collect()
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
all_apis: self.args.flag_dapps_apis_all,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,14 +746,10 @@ impl Configuration {
|
||||
Self::cors(self.args.flag_ipfs_api_cors.as_ref())
|
||||
}
|
||||
|
||||
fn dapps_cors(&self) -> Option<Vec<String>> {
|
||||
Self::cors(self.args.flag_dapps_cors.as_ref())
|
||||
}
|
||||
|
||||
fn hosts(hosts: &str) -> Option<Vec<String>> {
|
||||
match hosts {
|
||||
"none" => return Some(Vec::new()),
|
||||
"all" => return None,
|
||||
"*" | "all" | "any" => return None,
|
||||
_ => {}
|
||||
}
|
||||
let hosts = hosts.split(',').map(Into::into).collect();
|
||||
@@ -766,10 +760,6 @@ impl Configuration {
|
||||
Self::hosts(&self.args.flag_jsonrpc_hosts)
|
||||
}
|
||||
|
||||
fn dapps_hosts(&self) -> Option<Vec<String>> {
|
||||
Self::hosts(&self.args.flag_dapps_hosts)
|
||||
}
|
||||
|
||||
fn ipfs_hosts(&self) -> Option<Vec<String>> {
|
||||
Self::hosts(&self.args.flag_ipfs_api_hosts)
|
||||
}
|
||||
@@ -795,12 +785,17 @@ impl Configuration {
|
||||
|
||||
fn http_config(&self) -> Result<HttpConfiguration, String> {
|
||||
let conf = HttpConfiguration {
|
||||
enabled: !self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc,
|
||||
enabled: self.rpc_enabled(),
|
||||
interface: self.rpc_interface(),
|
||||
port: self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port),
|
||||
apis: self.rpc_apis().parse()?,
|
||||
hosts: self.rpc_hosts(),
|
||||
cors: self.rpc_cors(),
|
||||
threads: match self.args.flag_jsonrpc_threads {
|
||||
Some(threads) if threads > 0 => Some(threads),
|
||||
None => None,
|
||||
_ => return Err("--jsonrpc-threads number needs to be positive.".into()),
|
||||
}
|
||||
};
|
||||
|
||||
Ok(conf)
|
||||
@@ -811,7 +806,7 @@ impl Configuration {
|
||||
name: self.args.flag_identity.clone(),
|
||||
chain: self.chain(),
|
||||
network_port: self.args.flag_port,
|
||||
rpc_enabled: !self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc,
|
||||
rpc_enabled: self.rpc_enabled(),
|
||||
rpc_interface: self.args.flag_rpcaddr.clone().unwrap_or(self.args.flag_jsonrpc_interface.clone()),
|
||||
rpc_port: self.args.flag_rpcport.unwrap_or(self.args.flag_jsonrpc_port),
|
||||
}
|
||||
@@ -918,13 +913,6 @@ impl Configuration {
|
||||
Self::interface(&self.network_settings().rpc_interface)
|
||||
}
|
||||
|
||||
fn dapps_interface(&self) -> String {
|
||||
match self.args.flag_dapps_interface.as_str() {
|
||||
"local" => "127.0.0.1",
|
||||
x => x,
|
||||
}.into()
|
||||
}
|
||||
|
||||
fn ipfs_interface(&self) -> String {
|
||||
Self::interface(&self.args.flag_ipfs_api_interface)
|
||||
}
|
||||
@@ -940,8 +928,12 @@ impl Configuration {
|
||||
Self::interface(&self.args.flag_stratum_interface)
|
||||
}
|
||||
|
||||
fn rpc_enabled(&self) -> bool {
|
||||
!self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc
|
||||
}
|
||||
|
||||
fn dapps_enabled(&self) -> bool {
|
||||
!self.args.flag_dapps_off && !self.args.flag_no_dapps && cfg!(feature = "dapps")
|
||||
!self.args.flag_dapps_off && !self.args.flag_no_dapps && self.rpc_enabled() && cfg!(feature = "dapps")
|
||||
}
|
||||
|
||||
fn secretstore_enabled(&self) -> bool {
|
||||
@@ -1321,23 +1313,6 @@ mod tests {
|
||||
assert_eq!(conf3.rpc_hosts(), Some(vec!["ethcore.io".into(), "something.io".into()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_dapps_hosts() {
|
||||
// given
|
||||
|
||||
// when
|
||||
let conf0 = parse(&["parity"]);
|
||||
let conf1 = parse(&["parity", "--dapps-hosts", "none"]);
|
||||
let conf2 = parse(&["parity", "--dapps-hosts", "all"]);
|
||||
let conf3 = parse(&["parity", "--dapps-hosts", "ethcore.io,something.io"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.dapps_hosts(), Some(Vec::new()));
|
||||
assert_eq!(conf1.dapps_hosts(), Some(Vec::new()));
|
||||
assert_eq!(conf2.dapps_hosts(), None);
|
||||
assert_eq!(conf3.dapps_hosts(), Some(vec!["ethcore.io".into(), "something.io".into()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_ipfs_hosts() {
|
||||
// given
|
||||
|
||||
152
parity/dapps.rs
152
parity/dapps.rs
@@ -20,26 +20,18 @@ use std::sync::Arc;
|
||||
use dir::default_data_path;
|
||||
use ethcore::client::{Client, BlockChainClient, BlockId};
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
use ethcore_rpc::informant::RpcStats;
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use hash_fetch::urlhint::ContractClient;
|
||||
use helpers::replace_home;
|
||||
use rpc_apis::{self, SignerService};
|
||||
use rpc_apis::SignerService;
|
||||
use parity_reactor;
|
||||
use util::{Bytes, Address, U256};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Configuration {
|
||||
pub enabled: bool,
|
||||
pub interface: String,
|
||||
pub port: u16,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub cors: Option<Vec<String>>,
|
||||
pub user: Option<String>,
|
||||
pub pass: Option<String>,
|
||||
pub dapps_path: PathBuf,
|
||||
pub extra_dapps: Vec<PathBuf>,
|
||||
pub all_apis: bool,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
@@ -47,15 +39,8 @@ impl Default for Configuration {
|
||||
let data_dir = default_data_path();
|
||||
Configuration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8080,
|
||||
hosts: Some(Vec::new()),
|
||||
cors: None,
|
||||
user: None,
|
||||
pass: None,
|
||||
dapps_path: replace_home(&data_dir, "$BASE/dapps").into(),
|
||||
extra_dapps: vec![],
|
||||
all_apis: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,70 +81,52 @@ impl ContractClient for FullRegistrar {
|
||||
|
||||
// TODO: light client implementation forwarding to OnDemand and waiting for future
|
||||
// to resolve.
|
||||
|
||||
pub struct Dependencies<D: rpc_apis::Dependencies> {
|
||||
pub apis: Arc<D>,
|
||||
pub sync_status: Arc<::ethcore_dapps::SyncStatus>,
|
||||
pub struct Dependencies {
|
||||
pub sync_status: Arc<::parity_dapps::SyncStatus>,
|
||||
pub contract_client: Arc<ContractClient>,
|
||||
pub remote: parity_reactor::TokioRemote,
|
||||
pub fetch: FetchClient,
|
||||
pub signer: Arc<SignerService>,
|
||||
pub stats: Arc<RpcStats>,
|
||||
}
|
||||
|
||||
pub fn new<D>(configuration: Configuration, deps: Dependencies<D>) -> Result<Option<WebappServer>, String>
|
||||
where D: rpc_apis::Dependencies
|
||||
pub fn new(configuration: Configuration, deps: Dependencies)
|
||||
-> Result<Option<Middleware>, String>
|
||||
{
|
||||
if !configuration.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let url = format!("{}:{}", configuration.interface, configuration.port);
|
||||
let addr = url.parse().map_err(|_| format!("Invalid Webapps listen host/port given: {}", url))?;
|
||||
|
||||
let auth = configuration.user.as_ref().map(|username| {
|
||||
let password = configuration.pass.as_ref().map_or_else(|| {
|
||||
use rpassword::read_password;
|
||||
println!("Type password for WebApps server (user: {}): ", username);
|
||||
let pass = read_password().unwrap();
|
||||
println!("OK, got it. Starting server...");
|
||||
pass
|
||||
}, |pass| pass.to_owned());
|
||||
(username.to_owned(), password)
|
||||
});
|
||||
|
||||
Ok(Some(setup_dapps_server(
|
||||
dapps_middleware(
|
||||
deps,
|
||||
configuration.dapps_path,
|
||||
configuration.extra_dapps,
|
||||
&addr,
|
||||
configuration.hosts,
|
||||
configuration.cors,
|
||||
auth,
|
||||
configuration.all_apis,
|
||||
)?))
|
||||
).map(Some)
|
||||
}
|
||||
|
||||
pub use self::server::WebappServer;
|
||||
pub use self::server::setup_dapps_server;
|
||||
pub use self::server::Middleware;
|
||||
pub use self::server::dapps_middleware;
|
||||
|
||||
#[cfg(not(feature = "dapps"))]
|
||||
mod server {
|
||||
use super::Dependencies;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use ethcore_rpc::{hyper, RequestMiddleware, RequestMiddlewareAction};
|
||||
|
||||
pub struct WebappServer;
|
||||
pub fn setup_dapps_server(
|
||||
pub struct Middleware;
|
||||
|
||||
impl RequestMiddleware for Middleware {
|
||||
fn on_request(
|
||||
&self, req: &hyper::server::Request<hyper::net::HttpStream>, control: &hyper::Control
|
||||
) -> RequestMiddlewareAction {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dapps_middleware(
|
||||
_deps: Dependencies,
|
||||
_dapps_path: PathBuf,
|
||||
_extra_dapps: Vec<PathBuf>,
|
||||
_url: &SocketAddr,
|
||||
_allowed_hosts: Option<Vec<String>>,
|
||||
_cors: Option<Vec<String>>,
|
||||
_auth: Option<(String, String)>,
|
||||
_all_apis: bool,
|
||||
) -> Result<WebappServer, String> {
|
||||
) -> Result<Middleware, String> {
|
||||
Err("Your Parity version has been compiled without WebApps support.".into())
|
||||
}
|
||||
}
|
||||
@@ -169,70 +136,31 @@ mod server {
|
||||
use super::Dependencies;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use std::io;
|
||||
|
||||
use ansi_term::Colour;
|
||||
use ethcore_dapps::{AccessControlAllowOrigin, Host};
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use parity_dapps;
|
||||
use parity_reactor;
|
||||
use rpc_apis;
|
||||
|
||||
pub use ethcore_dapps::Server as WebappServer;
|
||||
pub type Middleware = parity_dapps::Middleware<FetchClient>;
|
||||
|
||||
pub fn setup_dapps_server<D: rpc_apis::Dependencies>(
|
||||
deps: Dependencies<D>,
|
||||
pub fn dapps_middleware(
|
||||
deps: Dependencies,
|
||||
dapps_path: PathBuf,
|
||||
extra_dapps: Vec<PathBuf>,
|
||||
url: &SocketAddr,
|
||||
allowed_hosts: Option<Vec<String>>,
|
||||
cors: Option<Vec<String>>,
|
||||
auth: Option<(String, String)>,
|
||||
all_apis: bool,
|
||||
) -> Result<WebappServer, String> {
|
||||
use ethcore_dapps as dapps;
|
||||
|
||||
let server = dapps::ServerBuilder::new(
|
||||
&dapps_path,
|
||||
deps.contract_client,
|
||||
parity_reactor::Remote::new(deps.remote.clone()),
|
||||
);
|
||||
let allowed_hosts: Option<Vec<_>> = allowed_hosts.map(|hosts| hosts.into_iter().map(Host::from).collect());
|
||||
let cors: Option<Vec<_>> = cors.map(|cors| cors.into_iter().map(AccessControlAllowOrigin::from).collect());
|
||||
|
||||
) -> Result<Middleware, String> {
|
||||
let signer = deps.signer.clone();
|
||||
let server = server
|
||||
.fetch(deps.fetch.clone())
|
||||
.sync_status(deps.sync_status)
|
||||
.web_proxy_tokens(Arc::new(move |token| signer.is_valid_web_proxy_access_token(&token)))
|
||||
.extra_dapps(&extra_dapps)
|
||||
.signer_address(deps.signer.address())
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
.extra_cors_headers(cors.into());
|
||||
let parity_remote = parity_reactor::Remote::new(deps.remote.clone());
|
||||
let web_proxy_tokens = Arc::new(move |token| signer.is_valid_web_proxy_access_token(&token));
|
||||
|
||||
let api_set = if all_apis {
|
||||
warn!("{}", Colour::Red.bold().paint("*** INSECURE *** Running Dapps with all APIs exposed."));
|
||||
info!("If you do not intend this, exit now.");
|
||||
rpc_apis::ApiSet::SafeContext
|
||||
} else {
|
||||
rpc_apis::ApiSet::UnsafeContext
|
||||
};
|
||||
let apis = rpc_apis::setup_rpc(deps.stats, &*deps.apis, api_set);
|
||||
let start_result = match auth {
|
||||
None => {
|
||||
server.start_unsecured_http(url, apis, deps.remote)
|
||||
},
|
||||
Some((username, password)) => {
|
||||
server.start_basic_auth_http(url, &username, &password, apis, deps.remote)
|
||||
},
|
||||
};
|
||||
|
||||
match start_result {
|
||||
Err(dapps::ServerError::IoError(err)) => match err.kind() {
|
||||
io::ErrorKind::AddrInUse => Err(format!("WebApps address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --dapps-port and --dapps-interface options.", url)),
|
||||
_ => Err(format!("WebApps io error: {}", err)),
|
||||
},
|
||||
Err(e) => Err(format!("WebApps error: {:?}", e)),
|
||||
Ok(server) => Ok(server),
|
||||
}
|
||||
Ok(parity_dapps::Middleware::new(
|
||||
parity_remote,
|
||||
deps.signer.address(),
|
||||
dapps_path,
|
||||
extra_dapps,
|
||||
deps.contract_client,
|
||||
deps.sync_status,
|
||||
web_proxy_tokens,
|
||||
deps.fetch.clone(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,94 +21,89 @@ use cli::Args;
|
||||
pub enum Deprecated {
|
||||
DoesNothing(&'static str),
|
||||
Replaced(&'static str, &'static str),
|
||||
Removed(&'static str),
|
||||
}
|
||||
|
||||
impl fmt::Display for Deprecated {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
Deprecated::DoesNothing(s) => write!(f, "Option '{}' does nothing. It's on by default", s),
|
||||
Deprecated::Replaced(old, new) => write!(f, "Option '{}' is deprecated. Please use '{}' instead", old, new),
|
||||
Deprecated::DoesNothing(s) => write!(f, "Option '{}' does nothing. It's on by default.", s),
|
||||
Deprecated::Replaced(old, new) => write!(f, "Option '{}' is deprecated. Please use '{}' instead.", old, new),
|
||||
Deprecated::Removed(s) => write!(f, "Option '{}' has been removed and is no longer supported.", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deprecated {
|
||||
fn jsonrpc() -> Self {
|
||||
Deprecated::DoesNothing("--jsonrpc")
|
||||
}
|
||||
|
||||
fn rpc() -> Self {
|
||||
Deprecated::DoesNothing("--rpc")
|
||||
}
|
||||
|
||||
fn jsonrpc_off() -> Self {
|
||||
Deprecated::Replaced("--jsonrpc-off", "--no-jsonrpc")
|
||||
}
|
||||
|
||||
fn webapp() -> Self {
|
||||
Deprecated::DoesNothing("--webapp")
|
||||
}
|
||||
|
||||
fn dapps_off() -> Self {
|
||||
Deprecated::Replaced("--dapps-off", "--no-dapps")
|
||||
}
|
||||
|
||||
fn ipcdisable() -> Self {
|
||||
Deprecated::Replaced("--ipcdisable", "--no-ipc")
|
||||
}
|
||||
|
||||
fn ipc_off() -> Self {
|
||||
Deprecated::Replaced("--ipc-off", "--no-ipc")
|
||||
}
|
||||
|
||||
fn etherbase() -> Self {
|
||||
Deprecated::Replaced("--etherbase", "--author")
|
||||
}
|
||||
|
||||
fn extradata() -> Self {
|
||||
Deprecated::Replaced("--extradata", "--extra-data")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_deprecated(args: &Args) -> Vec<Deprecated> {
|
||||
let mut result = vec![];
|
||||
|
||||
if args.flag_jsonrpc {
|
||||
result.push(Deprecated::jsonrpc());
|
||||
result.push(Deprecated::DoesNothing("--jsonrpc"));
|
||||
}
|
||||
|
||||
if args.flag_rpc {
|
||||
result.push(Deprecated::rpc());
|
||||
result.push(Deprecated::DoesNothing("--rpc"));
|
||||
}
|
||||
|
||||
if args.flag_jsonrpc_off {
|
||||
result.push(Deprecated::jsonrpc_off());
|
||||
result.push(Deprecated::Replaced("--jsonrpc-off", "--no-jsonrpc"));
|
||||
}
|
||||
|
||||
if args.flag_webapp {
|
||||
result.push(Deprecated::webapp())
|
||||
result.push(Deprecated::DoesNothing("--webapp"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_off {
|
||||
result.push(Deprecated::dapps_off());
|
||||
result.push(Deprecated::Replaced("--dapps-off", "--no-dapps"));
|
||||
}
|
||||
|
||||
if args.flag_ipcdisable {
|
||||
result.push(Deprecated::ipcdisable());
|
||||
result.push(Deprecated::Replaced("--ipcdisable", "--no-ipc"));
|
||||
}
|
||||
|
||||
if args.flag_ipc_off {
|
||||
result.push(Deprecated::ipc_off());
|
||||
result.push(Deprecated::Replaced("--ipc-off", "--no-ipc"));
|
||||
}
|
||||
|
||||
if args.flag_etherbase.is_some() {
|
||||
result.push(Deprecated::etherbase());
|
||||
result.push(Deprecated::Replaced("--etherbase", "--author"));
|
||||
}
|
||||
|
||||
if args.flag_extradata.is_some() {
|
||||
result.push(Deprecated::extradata());
|
||||
result.push(Deprecated::Replaced("--extradata", "--extra-data"));
|
||||
}
|
||||
|
||||
// Removed in 1.7
|
||||
if args.flag_dapps_port.is_some() {
|
||||
result.push(Deprecated::Replaced("--dapps-port", "--jsonrpc-port"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_interface.is_some() {
|
||||
result.push(Deprecated::Replaced("--dapps-interface", "--jsonrpc-interface"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_hosts.is_some() {
|
||||
result.push(Deprecated::Replaced("--dapps-hosts", "--jsonrpc-hosts"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_cors.is_some() {
|
||||
result.push(Deprecated::Replaced("--dapps-cors", "--jsonrpc-cors"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_user.is_some() {
|
||||
result.push(Deprecated::Removed("--dapps-user"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_pass.is_some() {
|
||||
result.push(Deprecated::Removed("--dapps-pass"));
|
||||
}
|
||||
|
||||
if args.flag_dapps_apis_all.is_some() {
|
||||
result.push(Deprecated::Replaced("--dapps-apis-all", "--jsonrpc-apis"));
|
||||
}
|
||||
|
||||
// Removed in 1.8
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
@@ -131,17 +126,31 @@ mod tests {
|
||||
args.flag_ipc_off = true;
|
||||
args.flag_etherbase = Some(Default::default());
|
||||
args.flag_extradata = Some(Default::default());
|
||||
args.flag_dapps_port = Some(Default::default());
|
||||
args.flag_dapps_interface = Some(Default::default());
|
||||
args.flag_dapps_hosts = Some(Default::default());
|
||||
args.flag_dapps_cors = Some(Default::default());
|
||||
args.flag_dapps_user = Some(Default::default());
|
||||
args.flag_dapps_pass = Some(Default::default());
|
||||
args.flag_dapps_apis_all = Some(Default::default());
|
||||
args
|
||||
}), vec![
|
||||
Deprecated::jsonrpc(),
|
||||
Deprecated::rpc(),
|
||||
Deprecated::jsonrpc_off(),
|
||||
Deprecated::webapp(),
|
||||
Deprecated::dapps_off(),
|
||||
Deprecated::ipcdisable(),
|
||||
Deprecated::ipc_off(),
|
||||
Deprecated::etherbase(),
|
||||
Deprecated::extradata(),
|
||||
Deprecated::DoesNothing("--jsonrpc"),
|
||||
Deprecated::DoesNothing("--rpc"),
|
||||
Deprecated::Replaced("--jsonrpc-off", "--no-jsonrpc"),
|
||||
Deprecated::DoesNothing("--webapp"),
|
||||
Deprecated::Replaced("--dapps-off", "--no-dapps"),
|
||||
Deprecated::Replaced("--ipcdisable", "--no-ipc"),
|
||||
Deprecated::Replaced("--ipc-off", "--no-ipc"),
|
||||
Deprecated::Replaced("--etherbase", "--author"),
|
||||
Deprecated::Replaced("--extradata", "--extra-data"),
|
||||
Deprecated::Replaced("--dapps-port", "--jsonrpc-port"),
|
||||
Deprecated::Replaced("--dapps-interface", "--jsonrpc-interface"),
|
||||
Deprecated::Replaced("--dapps-hosts", "--jsonrpc-hosts"),
|
||||
Deprecated::Replaced("--dapps-cors", "--jsonrpc-cors"),
|
||||
Deprecated::Removed("--dapps-user"),
|
||||
Deprecated::Removed("--dapps-pass"),
|
||||
Deprecated::Replaced("--dapps-apis-all", "--jsonrpc-apis"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use parity_ipfs_api::{self, AccessControlAllowOrigin, Host};
|
||||
use parity_ipfs_api::{self, AccessControlAllowOrigin, Host, Listening};
|
||||
use parity_ipfs_api::error::ServerError;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use hyper::server::Listening;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Configuration {
|
||||
|
||||
@@ -29,7 +29,6 @@ extern crate docopt;
|
||||
extern crate env_logger;
|
||||
extern crate fdlimit;
|
||||
extern crate futures;
|
||||
extern crate hyper;
|
||||
extern crate isatty;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate num_cpus;
|
||||
@@ -55,6 +54,7 @@ extern crate ethcore_logger;
|
||||
extern crate ethcore_rpc;
|
||||
extern crate ethcore_signer;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate ethkey;
|
||||
extern crate ethsync;
|
||||
extern crate parity_hash_fetch as hash_fetch;
|
||||
extern crate parity_ipfs_api;
|
||||
@@ -74,7 +74,11 @@ extern crate ethcore_stratum;
|
||||
extern crate ethcore_secretstore;
|
||||
|
||||
#[cfg(feature = "dapps")]
|
||||
extern crate ethcore_dapps;
|
||||
extern crate parity_dapps;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
|
||||
#[cfg(windows)] extern crate ws2_32;
|
||||
#[cfg(windows)] extern crate winapi;
|
||||
|
||||
150
parity/rpc.rs
150
parity/rpc.rs
@@ -14,24 +14,21 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::fmt;
|
||||
use std::{io, fmt};
|
||||
use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use std::io;
|
||||
|
||||
use dapps;
|
||||
use dir::default_data_path;
|
||||
use ethcore_rpc::{self as rpc, HttpServerError, Metadata, Origin, AccessControlAllowOrigin, Host};
|
||||
use ethcore_rpc::informant::{RpcStats, Middleware};
|
||||
use ethcore_rpc::{self as rpc, HttpServerError, Metadata, Origin, AccessControlAllowOrigin, Host};
|
||||
use helpers::parity_ipc_path;
|
||||
use hyper;
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
use rpc_apis;
|
||||
use rpc_apis::ApiSet;
|
||||
use parity_reactor::TokioRemote;
|
||||
use rpc_apis::{self, ApiSet};
|
||||
|
||||
pub use ethcore_rpc::{IpcServer, HttpServer};
|
||||
pub use ethcore_rpc::{IpcServer, HttpServer, RequestMiddleware};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct HttpConfiguration {
|
||||
pub enabled: bool,
|
||||
pub interface: String,
|
||||
@@ -39,6 +36,7 @@ pub struct HttpConfiguration {
|
||||
pub apis: ApiSet,
|
||||
pub cors: Option<Vec<String>>,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub threads: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for HttpConfiguration {
|
||||
@@ -50,6 +48,7 @@ impl Default for HttpConfiguration {
|
||||
apis: ApiSet::UnsafeContext,
|
||||
cors: None,
|
||||
hosts: Some(Vec::new()),
|
||||
threads: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,13 +88,17 @@ pub struct Dependencies<D: rpc_apis::Dependencies> {
|
||||
}
|
||||
|
||||
pub struct RpcExtractor;
|
||||
impl rpc::HttpMetaExtractor<Metadata> for RpcExtractor {
|
||||
fn read_metadata(&self, req: &hyper::server::Request<hyper::net::HttpStream>) -> Metadata {
|
||||
let origin = req.headers().get::<hyper::header::Origin>()
|
||||
.map(|origin| format!("{}://{}", origin.scheme, origin.host))
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
impl rpc::HttpMetaExtractor for RpcExtractor {
|
||||
type Metadata = Metadata;
|
||||
|
||||
fn read_metadata(&self, origin: String, dapps_origin: Option<String>) -> Metadata {
|
||||
let mut metadata = Metadata::default();
|
||||
metadata.origin = Origin::Rpc(origin);
|
||||
|
||||
metadata.origin = match (origin.as_str(), dapps_origin) {
|
||||
("null", Some(dapp)) => Origin::Dapps(dapp.into()),
|
||||
_ => Origin::Rpc(origin),
|
||||
};
|
||||
|
||||
metadata
|
||||
}
|
||||
}
|
||||
@@ -109,56 +112,101 @@ impl rpc::IpcMetaExtractor<Metadata> for RpcExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_http<D>(conf: HttpConfiguration, deps: &Dependencies<D>) -> Result<Option<HttpServer>, String>
|
||||
where D: rpc_apis::Dependencies
|
||||
{
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let url = format!("{}:{}", conf.interface, conf.port);
|
||||
let addr = url.parse().map_err(|_| format!("Invalid JSONRPC listen host/port given: {}", url))?;
|
||||
Ok(Some(setup_http_rpc_server(deps, &addr, conf.cors, conf.hosts, conf.apis)?))
|
||||
}
|
||||
|
||||
fn setup_apis<D>(apis: ApiSet, deps: &Dependencies<D>) -> MetaIoHandler<Metadata, Middleware<D::Notifier>>
|
||||
where D: rpc_apis::Dependencies
|
||||
{
|
||||
rpc_apis::setup_rpc(deps.stats.clone(), &*deps.apis, apis)
|
||||
}
|
||||
|
||||
pub fn setup_http_rpc_server<D: rpc_apis::Dependencies>(
|
||||
dependencies: &Dependencies<D>,
|
||||
url: &SocketAddr,
|
||||
cors_domains: Option<Vec<String>>,
|
||||
allowed_hosts: Option<Vec<String>>,
|
||||
apis: ApiSet
|
||||
) -> Result<HttpServer, String> {
|
||||
let handler = setup_apis(apis, dependencies);
|
||||
let remote = dependencies.remote.clone();
|
||||
let cors_domains: Option<Vec<_>> = cors_domains.map(|domains| domains.into_iter().map(AccessControlAllowOrigin::from).collect());
|
||||
let allowed_hosts: Option<Vec<_>> = allowed_hosts.map(|hosts| hosts.into_iter().map(Host::from).collect());
|
||||
let start_result = rpc::start_http(url, cors_domains.into(), allowed_hosts.into(), handler, remote, RpcExtractor);
|
||||
pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
conf: HttpConfiguration,
|
||||
deps: &Dependencies<D>,
|
||||
middleware: Option<dapps::Middleware>
|
||||
) -> Result<Option<HttpServer>, String> {
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let url = format!("{}:{}", conf.interface, conf.port);
|
||||
let addr = url.parse().map_err(|_| format!("Invalid JSONRPC listen host/port given: {}", url))?;
|
||||
let handler = setup_apis(conf.apis, deps);
|
||||
let remote = deps.remote.clone();
|
||||
|
||||
let cors_domains: Option<Vec<_>> = conf.cors.map(|domains| domains.into_iter().map(AccessControlAllowOrigin::from).collect());
|
||||
let allowed_hosts: Option<Vec<_>> = conf.hosts.map(|hosts| hosts.into_iter().map(Host::from).collect());
|
||||
|
||||
let start_result = rpc::start_http(
|
||||
&addr,
|
||||
cors_domains.into(),
|
||||
allowed_hosts.into(),
|
||||
handler,
|
||||
remote,
|
||||
RpcExtractor,
|
||||
match (conf.threads, middleware) {
|
||||
(Some(threads), None) => rpc::HttpSettings::Threads(threads),
|
||||
(None, middleware) => rpc::HttpSettings::Dapps(middleware),
|
||||
(Some(_), Some(_)) => {
|
||||
return Err("Dapps and fast multi-threaded RPC server cannot be enabled at the same time.".into())
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
match start_result {
|
||||
Err(HttpServerError::IoError(err)) => match err.kind() {
|
||||
io::ErrorKind::AddrInUse => Err(format!("RPC address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --jsonrpc-port and --jsonrpc-interface options.", url)),
|
||||
Ok(server) => Ok(Some(server)),
|
||||
Err(HttpServerError::Io(err)) => match err.kind() {
|
||||
io::ErrorKind::AddrInUse => Err(
|
||||
format!("RPC address {} is already in use, make sure that another instance of an Ethereum client is not running or change the address using the --jsonrpc-port and --jsonrpc-interface options.", url)
|
||||
),
|
||||
_ => Err(format!("RPC io error: {}", err)),
|
||||
},
|
||||
Err(e) => Err(format!("RPC error: {:?}", e)),
|
||||
Ok(server) => Ok(server),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_ipc<D: rpc_apis::Dependencies>(conf: IpcConfiguration, deps: &Dependencies<D>) -> Result<Option<IpcServer>, String> {
|
||||
if !conf.enabled { return Ok(None); }
|
||||
Ok(Some(setup_ipc_rpc_server(deps, &conf.socket_addr, conf.apis)?))
|
||||
}
|
||||
|
||||
pub fn setup_ipc_rpc_server<D: rpc_apis::Dependencies>(dependencies: &Dependencies<D>, addr: &str, apis: ApiSet) -> Result<IpcServer, String> {
|
||||
let handler = setup_apis(apis, dependencies);
|
||||
pub fn new_ipc<D: rpc_apis::Dependencies>(
|
||||
conf: IpcConfiguration,
|
||||
dependencies: &Dependencies<D>
|
||||
) -> Result<Option<IpcServer>, String> {
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
let handler = setup_apis(conf.apis, dependencies);
|
||||
let remote = dependencies.remote.clone();
|
||||
match rpc::start_ipc(addr, handler, remote, RpcExtractor) {
|
||||
match rpc::start_ipc(&conf.socket_addr, handler, remote, RpcExtractor) {
|
||||
Ok(server) => Ok(Some(server)),
|
||||
Err(io_error) => Err(format!("RPC io error: {}", io_error)),
|
||||
Ok(server) => Ok(server)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::RpcExtractor;
|
||||
use ethcore_rpc::{HttpMetaExtractor, Origin};
|
||||
|
||||
#[test]
|
||||
fn should_extract_rpc_origin() {
|
||||
// given
|
||||
let extractor = RpcExtractor;
|
||||
|
||||
// when
|
||||
let meta = extractor.read_metadata("http://parity.io".into(), None);
|
||||
let meta1 = extractor.read_metadata("http://parity.io".into(), Some("ignored".into()));
|
||||
|
||||
// then
|
||||
assert_eq!(meta.origin, Origin::Rpc("http://parity.io".into()));
|
||||
assert_eq!(meta1.origin, Origin::Rpc("http://parity.io".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_dapps_origin() {
|
||||
// given
|
||||
let extractor = RpcExtractor;
|
||||
let dapp = "https://wallet.ethereum.org".to_owned();
|
||||
|
||||
// when
|
||||
let meta = extractor.read_metadata("null".into(), Some(dapp.clone()));
|
||||
|
||||
// then
|
||||
assert_eq!(meta.origin, Origin::Dapps(dapp.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl FromStr for Api {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ApiSet {
|
||||
SafeContext,
|
||||
UnsafeContext,
|
||||
|
||||
@@ -37,7 +37,6 @@ use updater::{UpdatePolicy, Updater};
|
||||
use parity_reactor::EventLoop;
|
||||
use hash_fetch::fetch::{Fetch, Client as FetchClient};
|
||||
|
||||
use rpc::{HttpConfiguration, IpcConfiguration};
|
||||
use params::{
|
||||
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
|
||||
tracing_switch_to_bool, fatdb_switch_to_bool, mode_switch_to_bool
|
||||
@@ -81,8 +80,8 @@ pub struct RunCmd {
|
||||
pub daemon: Option<String>,
|
||||
pub logger_config: LogConfig,
|
||||
pub miner_options: MinerOptions,
|
||||
pub http_conf: HttpConfiguration,
|
||||
pub ipc_conf: IpcConfiguration,
|
||||
pub http_conf: rpc::HttpConfiguration,
|
||||
pub ipc_conf: rpc::IpcConfiguration,
|
||||
pub net_conf: NetworkConfiguration,
|
||||
pub network_id: Option<u64>,
|
||||
pub warp_sync: bool,
|
||||
@@ -117,11 +116,7 @@ pub struct RunCmd {
|
||||
pub light: bool,
|
||||
}
|
||||
|
||||
pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> {
|
||||
if !dapps_conf.enabled {
|
||||
return Err("Cannot use UI command with Dapps turned off.".into())
|
||||
}
|
||||
|
||||
pub fn open_ui(signer_conf: &signer::Configuration) -> Result<(), String> {
|
||||
if !signer_conf.enabled {
|
||||
return Err("Cannot use UI command with UI turned off.".into())
|
||||
}
|
||||
@@ -134,12 +129,12 @@ pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configur
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn open_dapp(dapps_conf: &dapps::Configuration, dapp: &str) -> Result<(), String> {
|
||||
pub fn open_dapp(dapps_conf: &dapps::Configuration, rpc_conf: &rpc::HttpConfiguration, dapp: &str) -> Result<(), String> {
|
||||
if !dapps_conf.enabled {
|
||||
return Err("Cannot use DAPP command with Dapps turned off.".into())
|
||||
}
|
||||
|
||||
let url = format!("http://{}:{}/{}/", dapps_conf.interface, dapps_conf.port, dapp);
|
||||
let url = format!("http://{}:{}/{}/", rpc_conf.interface, rpc_conf.port, dapp);
|
||||
url::open(&url);
|
||||
Ok(())
|
||||
}
|
||||
@@ -282,11 +277,11 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
cache: cache,
|
||||
transaction_queue: txq,
|
||||
dapps_interface: match cmd.dapps_conf.enabled {
|
||||
true => Some(cmd.dapps_conf.interface.clone()),
|
||||
true => Some(cmd.http_conf.interface.clone()),
|
||||
false => None,
|
||||
},
|
||||
dapps_port: match cmd.dapps_conf.enabled {
|
||||
true => Some(cmd.dapps_conf.port),
|
||||
true => Some(cmd.http_conf.port),
|
||||
false => None,
|
||||
},
|
||||
fetch: fetch,
|
||||
@@ -300,7 +295,7 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
};
|
||||
|
||||
// start rpc servers
|
||||
let _http_server = rpc::new_http(cmd.http_conf, &dependencies)?;
|
||||
let _http_server = rpc::new_http(cmd.http_conf, &dependencies, None)?;
|
||||
let _ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
||||
|
||||
// the signer server
|
||||
@@ -329,9 +324,9 @@ fn execute_light(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) ->
|
||||
pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> Result<(bool, Option<String>), String> {
|
||||
if cmd.ui && cmd.dapps_conf.enabled {
|
||||
// Check if Parity is already running
|
||||
let addr = format!("{}:{}", cmd.dapps_conf.interface, cmd.dapps_conf.port);
|
||||
let addr = format!("{}:{}", cmd.signer_conf.interface, cmd.signer_conf.port);
|
||||
if !TcpListener::bind(&addr as &str).is_ok() {
|
||||
return open_ui(&cmd.dapps_conf, &cmd.signer_conf).map(|_| (false, None));
|
||||
return open_ui(&cmd.signer_conf).map(|_| (false, None));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,11 +604,11 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
updater: updater.clone(),
|
||||
geth_compatibility: cmd.geth_compatibility,
|
||||
dapps_interface: match cmd.dapps_conf.enabled {
|
||||
true => Some(cmd.dapps_conf.interface.clone()),
|
||||
true => Some(cmd.http_conf.interface.clone()),
|
||||
false => None,
|
||||
},
|
||||
dapps_port: match cmd.dapps_conf.enabled {
|
||||
true => Some(cmd.dapps_conf.port),
|
||||
true => Some(cmd.http_conf.port),
|
||||
false => None,
|
||||
},
|
||||
fetch: fetch.clone(),
|
||||
@@ -625,26 +620,24 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
stats: rpc_stats.clone(),
|
||||
};
|
||||
|
||||
// start rpc servers
|
||||
let http_server = rpc::new_http(cmd.http_conf, &dependencies)?;
|
||||
let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
||||
|
||||
// the dapps server
|
||||
let dapps_deps = {
|
||||
let (sync, client) = (sync_provider.clone(), client.clone());
|
||||
let contract_client = Arc::new(::dapps::FullRegistrar { client: client.clone() });
|
||||
|
||||
dapps::Dependencies {
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
sync_status: Arc::new(move || is_major_importing(Some(sync.status().state), client.queue_info())),
|
||||
contract_client: contract_client,
|
||||
remote: event_loop.raw_remote(),
|
||||
fetch: fetch.clone(),
|
||||
signer: deps_for_rpc_apis.signer_service.clone(),
|
||||
stats: rpc_stats.clone(),
|
||||
}
|
||||
};
|
||||
let dapps_server = dapps::new(cmd.dapps_conf.clone(), dapps_deps)?;
|
||||
let dapps_middleware = dapps::new(cmd.dapps_conf.clone(), dapps_deps)?;
|
||||
|
||||
// start rpc servers
|
||||
let http_server = rpc::new_http(cmd.http_conf.clone(), &dependencies, dapps_middleware)?;
|
||||
let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
||||
|
||||
// the signer server
|
||||
let signer_deps = signer::Dependencies {
|
||||
@@ -710,18 +703,18 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
|
||||
// start ui
|
||||
if cmd.ui {
|
||||
open_ui(&cmd.dapps_conf, &cmd.signer_conf)?;
|
||||
open_ui(&cmd.signer_conf)?;
|
||||
}
|
||||
|
||||
if let Some(dapp) = cmd.dapp {
|
||||
open_dapp(&cmd.dapps_conf, &dapp)?;
|
||||
open_dapp(&cmd.dapps_conf, &cmd.http_conf, &dapp)?;
|
||||
}
|
||||
|
||||
// Handle exit
|
||||
let restart = wait_for_exit(panic_handler, Some(updater), Some(client), can_restart);
|
||||
|
||||
// drop this stuff as soon as exit detected.
|
||||
drop((http_server, ipc_server, dapps_server, signer_server, secretstore_key_server, ipfs_server, event_loop));
|
||||
drop((http_server, ipc_server, signer_server, secretstore_key_server, ipfs_server, event_loop));
|
||||
|
||||
info!("Finishing work, please wait...");
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ mod server {
|
||||
|
||||
#[cfg(feature="secretstore")]
|
||||
mod server {
|
||||
use ethkey;
|
||||
use ethcore_secretstore;
|
||||
use super::{Configuration, Dependencies};
|
||||
|
||||
@@ -64,10 +65,35 @@ mod server {
|
||||
impl KeyServer {
|
||||
/// Create new key server
|
||||
pub fn new(conf: Configuration, _deps: Dependencies) -> Result<Self, String> {
|
||||
let key_pairs = vec![
|
||||
ethkey::KeyPair::from_secret("6c26a76e9b31048d170873a791401c7e799a11f0cefc0171cc31a49800967509".parse().unwrap()).unwrap(),
|
||||
ethkey::KeyPair::from_secret("7e94018b3731afdb3b4e6f4c3e179475640166da12e1d1b0c7d80729b1a5b452".parse().unwrap()).unwrap(),
|
||||
ethkey::KeyPair::from_secret("5ab6ed2a52c33142380032c39a03a86b12eacb3fa4b53bc16d84f51318156f8c".parse().unwrap()).unwrap(),
|
||||
];
|
||||
let conf = ethcore_secretstore::ServiceConfiguration {
|
||||
listener_addr: conf.interface,
|
||||
listener_port: conf.port,
|
||||
data_path: conf.data_path,
|
||||
listener_address: ethcore_secretstore::NodeAddress {
|
||||
address: conf.interface.clone(),
|
||||
port: conf.port,
|
||||
},
|
||||
data_path: conf.data_path.clone(),
|
||||
// TODO: this is test configuration. how it will be configured in production?
|
||||
cluster_config: ethcore_secretstore::ClusterConfiguration {
|
||||
threads: 4,
|
||||
self_private: (***key_pairs[(conf.port - 8082) as usize].secret()).into(),
|
||||
listener_address: ethcore_secretstore::NodeAddress {
|
||||
address: conf.interface.clone(),
|
||||
port: conf.port + 10,
|
||||
},
|
||||
nodes: key_pairs.iter().enumerate().map(|(i, kp)| (kp.public().clone(),
|
||||
ethcore_secretstore::NodeAddress {
|
||||
address: conf.interface.clone(),
|
||||
port: 8082 + 10 + (i as u16),
|
||||
})).collect(),
|
||||
allow_connecting_to_higher_nodes: true,
|
||||
encryption_config: ethcore_secretstore::EncryptionConfiguration {
|
||||
key_check_timeout_ms: 1000,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let key_server = ethcore_secretstore::start(conf)
|
||||
|
||||
Reference in New Issue
Block a user