Base for Signer Websockets server (#1158)
* Basic signing queue * Adding docs * WebSockets server for signer * Removing TODO * Shortening the syntax * Exposing types from RPC * Fixing indentation * Update main.rs
This commit is contained in:
@@ -97,6 +97,11 @@ API and Console Options:
|
||||
--dapps-pass PASSWORD Specify password for Dapps server. Use only in
|
||||
conjunction with --dapps-user.
|
||||
|
||||
--signer Enable Trusted Signer WebSocket endpoint used by
|
||||
System UIs.
|
||||
--signer-port PORT Specify the port of Trusted Signer server
|
||||
[default: 8180].
|
||||
|
||||
Sealing/Mining Options:
|
||||
--force-sealing Force the node to author new blocks as if it were
|
||||
always sealing/mining.
|
||||
@@ -234,6 +239,8 @@ pub struct Args {
|
||||
pub flag_dapps_interface: String,
|
||||
pub flag_dapps_user: Option<String>,
|
||||
pub flag_dapps_pass: Option<String>,
|
||||
pub flag_signer: bool,
|
||||
pub flag_signer_port: u16,
|
||||
pub flag_force_sealing: bool,
|
||||
pub flag_author: String,
|
||||
pub flag_usd_per_tx: String,
|
||||
|
||||
@@ -50,6 +50,9 @@ extern crate ethcore_rpc;
|
||||
#[cfg(feature = "dapps")]
|
||||
extern crate ethcore_dapps;
|
||||
|
||||
#[cfg(feature = "ethcore-signer")]
|
||||
extern crate ethcore_signer;
|
||||
|
||||
#[macro_use]
|
||||
mod die;
|
||||
mod price_info;
|
||||
@@ -63,6 +66,7 @@ mod io_handler;
|
||||
mod cli;
|
||||
mod configuration;
|
||||
mod migration;
|
||||
mod signer;
|
||||
|
||||
use std::io::{Write, Read, BufReader, BufRead};
|
||||
use std::ops::Deref;
|
||||
@@ -89,6 +93,7 @@ use informant::Informant;
|
||||
use die::*;
|
||||
use cli::print_version;
|
||||
use rpc::RpcServer;
|
||||
use signer::SignerServer;
|
||||
use dapps::WebappServer;
|
||||
use io_handler::ClientIoHandler;
|
||||
use configuration::Configuration;
|
||||
@@ -231,6 +236,14 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
settings: network_settings.clone(),
|
||||
});
|
||||
|
||||
// Set up a signer
|
||||
let signer_server = signer::start(signer::Configuration {
|
||||
enabled: conf.args.flag_signer,
|
||||
port: conf.args.flag_signer_port,
|
||||
}, signer::Dependencies {
|
||||
panic_handler: panic_handler.clone(),
|
||||
});
|
||||
|
||||
// Register IO handler
|
||||
let io_handler = Arc::new(ClientIoHandler {
|
||||
client: service.client(),
|
||||
@@ -241,7 +254,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
|
||||
service.io().register_handler(io_handler).expect("Error registering IO handler");
|
||||
|
||||
// Handle exit
|
||||
wait_for_exit(panic_handler, rpc_server, dapps_server);
|
||||
wait_for_exit(panic_handler, rpc_server, dapps_server, signer_server);
|
||||
}
|
||||
|
||||
fn flush_stdout() {
|
||||
@@ -453,7 +466,12 @@ fn execute_account_cli(conf: Configuration) {
|
||||
}
|
||||
}
|
||||
|
||||
fn wait_for_exit(panic_handler: Arc<PanicHandler>, _rpc_server: Option<RpcServer>, _dapps_server: Option<WebappServer>) {
|
||||
fn wait_for_exit(
|
||||
panic_handler: Arc<PanicHandler>,
|
||||
_rpc_server: Option<RpcServer>,
|
||||
_dapps_server: Option<WebappServer>,
|
||||
_signer_server: Option<SignerServer>
|
||||
) {
|
||||
let exit = Arc::new(Condvar::new());
|
||||
|
||||
// Handle possible exits
|
||||
|
||||
@@ -27,6 +27,8 @@ pub fn setup_log(init: &Option<String>) -> Arc<RotatingLogger> {
|
||||
|
||||
let mut levels = String::new();
|
||||
let mut builder = LogBuilder::new();
|
||||
// Disable ws info logging by default.
|
||||
builder.filter(Some("ws"), LogLevelFilter::Warn);
|
||||
builder.filter(None, LogLevelFilter::Info);
|
||||
|
||||
if env::var("RUST_LOG").is_ok() {
|
||||
|
||||
67
parity/signer.rs
Normal file
67
parity/signer.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2015, 2016 Ethcore (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 util::panics::{PanicHandler, ForwardPanic};
|
||||
use die::*;
|
||||
|
||||
#[cfg(feature = "ethcore-signer")]
|
||||
use ethcore_signer as signer;
|
||||
#[cfg(feature = "ethcore-signer")]
|
||||
pub use ethcore_signer::Server as SignerServer;
|
||||
#[cfg(not(feature = "ethcore-signer"))]
|
||||
pub struct SignerServer;
|
||||
|
||||
pub struct Configuration {
|
||||
pub enabled: bool,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
pub struct Dependencies {
|
||||
pub panic_handler: Arc<PanicHandler>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "ethcore-signer")]
|
||||
pub fn start(conf: Configuration, deps: Dependencies) -> Option<SignerServer> {
|
||||
if !conf.enabled {
|
||||
return None;
|
||||
}
|
||||
|
||||
let addr = format!("127.0.0.1:{}", conf.port).parse().unwrap_or_else(|_| die!("Invalid port specified: {}", conf.port));
|
||||
let start_result = signer::Server::start(addr);
|
||||
|
||||
match start_result {
|
||||
Err(signer::ServerError::IoError(err)) => die_with_io_error("Trusted Signer", err),
|
||||
Err(e) => die!("Trusted Signer: {:?}", e),
|
||||
Ok(server) => {
|
||||
deps.panic_handler.forward_from(&server);
|
||||
Some(server)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ethcore-signer"))]
|
||||
pub fn start(conf: Configuration) -> Option<SignerServer> {
|
||||
if !conf.enabled {
|
||||
return None;
|
||||
}
|
||||
|
||||
die!("Your Parity version has been compiled without Trusted Signer support.")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user