New version of jsonrpc.
This commit is contained in:
@@ -23,9 +23,8 @@ use ethcore_rpc::informant::RpcStats;
|
||||
use ethsync::SyncProvider;
|
||||
use hash_fetch::fetch::Client as FetchClient;
|
||||
use helpers::replace_home;
|
||||
use io::PanicHandler;
|
||||
use jsonrpc_core::reactor::Remote;
|
||||
use rpc_apis::{self, SignerService};
|
||||
use parity_reactor;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Configuration {
|
||||
@@ -60,11 +59,10 @@ impl Default for Configuration {
|
||||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
pub client: Arc<Client>,
|
||||
pub sync: Arc<SyncProvider>,
|
||||
pub remote: Remote,
|
||||
pub remote: parity_reactor::TokioRemote,
|
||||
pub fetch: FetchClient,
|
||||
pub signer: Arc<SignerService>,
|
||||
pub stats: Arc<RpcStats>,
|
||||
@@ -137,9 +135,9 @@ mod server {
|
||||
use ansi_term::Colour;
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
use ethcore::client::{Client, BlockChainClient, BlockId};
|
||||
use ethcore_dapps::{AccessControlAllowOrigin, Host};
|
||||
use ethcore_rpc::is_major_importing;
|
||||
use hash_fetch::urlhint::ContractClient;
|
||||
use jsonrpc_core::reactor::RpcHandler;
|
||||
use parity_reactor;
|
||||
use rpc_apis;
|
||||
|
||||
@@ -162,6 +160,8 @@ mod server {
|
||||
Arc::new(Registrar { client: deps.client.clone() }),
|
||||
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());
|
||||
|
||||
let sync = deps.sync.clone();
|
||||
let client = deps.client.clone();
|
||||
@@ -172,8 +172,8 @@ mod server {
|
||||
.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)
|
||||
.extra_cors_headers(cors);
|
||||
.allowed_hosts(allowed_hosts.into())
|
||||
.extra_cors_headers(cors.into());
|
||||
|
||||
let api_set = if all_apis {
|
||||
warn!("{}", Colour::Red.bold().paint("*** INSECURE *** Running Dapps with all APIs exposed."));
|
||||
@@ -183,13 +183,12 @@ mod server {
|
||||
rpc_apis::ApiSet::UnsafeContext
|
||||
};
|
||||
let apis = rpc_apis::setup_rpc(deps.stats, deps.apis.clone(), api_set);
|
||||
let handler = RpcHandler::new(Arc::new(apis), deps.remote);
|
||||
let start_result = match auth {
|
||||
None => {
|
||||
server.start_unsecured_http(url, handler)
|
||||
server.start_unsecured_http(url, apis, deps.remote)
|
||||
},
|
||||
Some((username, password)) => {
|
||||
server.start_basic_auth_http(url, &username, &password, handler)
|
||||
server.start_basic_auth_http(url, &username, &password, apis, deps.remote)
|
||||
},
|
||||
};
|
||||
|
||||
@@ -199,13 +198,7 @@ mod server {
|
||||
_ => Err(format!("WebApps io error: {}", err)),
|
||||
},
|
||||
Err(e) => Err(format!("WebApps error: {:?}", e)),
|
||||
Ok(server) => {
|
||||
let ph = deps.panic_handler;
|
||||
server.set_panic_handler(move || {
|
||||
ph.notify_all("Panic in WebApp thread.".to_owned());
|
||||
});
|
||||
Ok(server)
|
||||
},
|
||||
Ok(server) => Ok(server),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,59 @@
|
||||
// Copyright 2015-2017 Parity Technologies (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/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use parity_ipfs_api;
|
||||
use parity_ipfs_api::{self, AccessControlAllowOrigin, Host};
|
||||
use parity_ipfs_api::error::ServerError;
|
||||
use ethcore::client::BlockChainClient;
|
||||
use hyper::server::Listening;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Configuration {
|
||||
pub enabled: bool,
|
||||
pub port: u16,
|
||||
pub interface: String,
|
||||
pub cors: Option<Vec<String>>,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub enabled: bool,
|
||||
pub port: u16,
|
||||
pub interface: String,
|
||||
pub cors: Option<Vec<String>>,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
fn default() -> Self {
|
||||
Configuration {
|
||||
enabled: false,
|
||||
port: 5001,
|
||||
interface: "127.0.0.1".into(),
|
||||
cors: None,
|
||||
hosts: Some(Vec::new()),
|
||||
}
|
||||
}
|
||||
fn default() -> Self {
|
||||
Configuration {
|
||||
enabled: false,
|
||||
port: 5001,
|
||||
interface: "127.0.0.1".into(),
|
||||
cors: None,
|
||||
hosts: Some(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_server(conf: Configuration, client: Arc<BlockChainClient>) -> Result<Option<Listening>, ServerError> {
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
if !conf.enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
parity_ipfs_api::start_server(
|
||||
conf.port,
|
||||
conf.interface,
|
||||
conf.cors,
|
||||
conf.hosts,
|
||||
client
|
||||
).map(Some)
|
||||
let cors = conf.cors.map(|cors| cors.into_iter().map(AccessControlAllowOrigin::from).collect());
|
||||
let hosts = conf.hosts.map(|hosts| hosts.into_iter().map(Host::from).collect());
|
||||
|
||||
parity_ipfs_api::start_server(
|
||||
conf.port,
|
||||
conf.interface,
|
||||
cors.into(),
|
||||
hosts.into(),
|
||||
client
|
||||
).map(Some)
|
||||
}
|
||||
|
||||
@@ -18,19 +18,18 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::net::SocketAddr;
|
||||
use std::io;
|
||||
use io::PanicHandler;
|
||||
|
||||
use dir::default_data_path;
|
||||
use ethcore_rpc::{self as rpc, RpcServerError, IpcServerError, Metadata, Origin};
|
||||
use ethcore_rpc::{self as rpc, HttpServerError, IpcServerError, Metadata, Origin, AccessControlAllowOrigin, Host};
|
||||
use ethcore_rpc::informant::{RpcStats, Middleware};
|
||||
use helpers::parity_ipc_path;
|
||||
use hyper;
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
use jsonrpc_core::reactor::{RpcHandler, Remote};
|
||||
use rpc_apis;
|
||||
use rpc_apis::ApiSet;
|
||||
use parity_reactor::TokioRemote;
|
||||
|
||||
pub use ethcore_rpc::{IpcServer, Server as HttpServer};
|
||||
pub use ethcore_rpc::{IpcServer, HttpServer};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct HttpConfiguration {
|
||||
@@ -84,9 +83,8 @@ impl fmt::Display for IpcConfiguration {
|
||||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
pub remote: Remote,
|
||||
pub remote: TokioRemote,
|
||||
pub stats: Arc<RpcStats>,
|
||||
}
|
||||
|
||||
@@ -123,12 +121,13 @@ pub fn setup_http_rpc_server(
|
||||
allowed_hosts: Option<Vec<String>>,
|
||||
apis: ApiSet
|
||||
) -> Result<HttpServer, String> {
|
||||
let apis = setup_apis(apis, dependencies);
|
||||
let handler = RpcHandler::new(Arc::new(apis), dependencies.remote.clone());
|
||||
let ph = dependencies.panic_handler.clone();
|
||||
let start_result = rpc::start_http(url, cors_domains, allowed_hosts, ph, handler, RpcExtractor);
|
||||
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);
|
||||
match start_result {
|
||||
Err(RpcServerError::IoError(err)) => match err.kind() {
|
||||
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)),
|
||||
_ => Err(format!("RPC io error: {}", err)),
|
||||
},
|
||||
@@ -143,9 +142,9 @@ pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Result<Option<Ipc
|
||||
}
|
||||
|
||||
pub fn setup_ipc_rpc_server(dependencies: &Dependencies, addr: &str, apis: ApiSet) -> Result<IpcServer<Metadata, Middleware>, String> {
|
||||
let apis = setup_apis(apis, dependencies);
|
||||
let handler = RpcHandler::new(Arc::new(apis), dependencies.remote.clone());
|
||||
match rpc::start_ipc(addr, handler) {
|
||||
let handler = setup_apis(apis, dependencies);
|
||||
let remote = dependencies.remote.clone();
|
||||
match rpc::start_ipc(addr, handler, remote) {
|
||||
Err(IpcServerError::Io(io_error)) => Err(format!("RPC io error: {}", io_error)),
|
||||
Err(any_error) => Err(format!("Rpc error: {:?}", any_error)),
|
||||
Ok(server) => Ok(server)
|
||||
|
||||
@@ -434,7 +434,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
});
|
||||
|
||||
let dependencies = rpc::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
remote: event_loop.raw_remote(),
|
||||
stats: rpc_stats.clone(),
|
||||
@@ -446,7 +445,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
|
||||
// the dapps server
|
||||
let dapps_deps = dapps::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
client: client.clone(),
|
||||
sync: sync_provider.clone(),
|
||||
@@ -459,7 +457,6 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
|
||||
// the signer server
|
||||
let signer_deps = signer::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
apis: deps_for_rpc_apis.clone(),
|
||||
remote: event_loop.raw_remote(),
|
||||
rpc_stats: rpc_stats.clone(),
|
||||
|
||||
@@ -26,8 +26,7 @@ use ethcore_rpc::informant::RpcStats;
|
||||
use ethcore_rpc;
|
||||
use ethcore_signer as signer;
|
||||
use helpers::replace_home;
|
||||
use io::{ForwardPanic, PanicHandler};
|
||||
use jsonrpc_core::reactor::{RpcHandler, Remote};
|
||||
use parity_reactor::TokioRemote;
|
||||
use rpc_apis;
|
||||
use util::path::restrict_permissions_owner;
|
||||
use util::H256;
|
||||
@@ -57,9 +56,8 @@ impl Default for Configuration {
|
||||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
pub apis: Arc<rpc_apis::Dependencies>,
|
||||
pub remote: Remote,
|
||||
pub remote: TokioRemote,
|
||||
pub rpc_stats: Arc<RpcStats>,
|
||||
}
|
||||
|
||||
@@ -143,9 +141,9 @@ fn do_start(conf: Configuration, deps: Dependencies) -> Result<SignerServer, Str
|
||||
}
|
||||
let server = server.skip_origin_validation(conf.skip_origin_validation);
|
||||
let server = server.stats(deps.rpc_stats.clone());
|
||||
let apis = rpc_apis::setup_rpc(deps.rpc_stats, deps.apis, rpc_apis::ApiSet::SafeContext);
|
||||
let handler = RpcHandler::new(Arc::new(apis), deps.remote);
|
||||
server.start_with_extractor(addr, handler, StandardExtractor)
|
||||
let handler = rpc_apis::setup_rpc(deps.rpc_stats, deps.apis, rpc_apis::ApiSet::SafeContext);
|
||||
let remote = deps.remote.clone();
|
||||
server.start_with_extractor(addr, handler, remote, StandardExtractor)
|
||||
};
|
||||
|
||||
match start_result {
|
||||
@@ -154,10 +152,7 @@ fn do_start(conf: Configuration, deps: Dependencies) -> Result<SignerServer, Str
|
||||
_ => Err(format!("Trusted Signer io error: {}", err)),
|
||||
},
|
||||
Err(e) => Err(format!("Trusted Signer Error: {:?}", e)),
|
||||
Ok(server) => {
|
||||
deps.panic_handler.forward_from(&server);
|
||||
Ok(server)
|
||||
},
|
||||
Ok(server) => Ok(server),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user