Merge pull request #1211 from ethcore/signer-ui

Minimal Signer UI (System UI) exposed over websockets.
This commit is contained in:
Marek Kotewicz 2016-06-06 11:31:45 +02:00
commit 54c20f6f9c
6 changed files with 75 additions and 11 deletions

42
Cargo.lock generated
View File

@ -358,8 +358,9 @@ dependencies = [
"ethcore-util 1.2.0",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-minimal-sysui 0.1.0 (git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git)",
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"ws 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"ws 0.4.6 (git+https://github.com/ethcore/ws-rs.git)",
]
[[package]]
@ -686,6 +687,22 @@ dependencies = [
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mio"
version = "0.5.0"
source = "git+https://github.com/carllerche/mio.git#f4aa49a9d2c4507fb33a4533d5238e0365f67c99"
dependencies = [
"bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"miow 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"net2 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.5.0-pre (git+https://github.com/carllerche/nix-rust?rev=c4257f8a76)",
"slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mio"
version = "0.5.1"
@ -743,6 +760,15 @@ dependencies = [
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.5.0-pre"
source = "git+https://github.com/carllerche/nix-rust?rev=c4257f8a76#c4257f8a76b69b0d2e9a001d83e4bef67c03b23f"
dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.5.0"
@ -906,6 +932,11 @@ dependencies = [
"parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)",
]
[[package]]
name = "parity-minimal-sysui"
version = "0.1.0"
source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#bc5d76f9666ce19993e6f7b636a3a7af329ea19e"
[[package]]
name = "phf"
version = "0.7.14"
@ -1416,15 +1447,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ws"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.4.6"
source = "git+https://github.com/ethcore/ws-rs.git#c0c2a3fc30dc77c4e6d4d90756f8bc3b5cfbc311"
dependencies = [
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.0 (git+https://github.com/carllerche/mio.git)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View File

@ -66,12 +66,12 @@ fn wallet_page(pages: &mut Endpoints) {
#[cfg(not(feature = "parity-dapps-wallet"))]
fn wallet_page(_pages: &mut Endpoints) {}
#[cfg(feature = "parity-dapps-daodapp")]
#[cfg(feature = "parity-dapps-dao")]
fn daodapp_page(pages: &mut Endpoints) {
extern crate parity_dapps_daodapp;
insert::<parity_dapps_daodapp::App>(pages, "dao");
extern crate parity_dapps_dao;
insert::<parity_dapps_dao::App>(pages, "dao");
}
#[cfg(not(feature = "parity-dapps-daodapp"))]
#[cfg(not(feature = "parity-dapps-dao"))]
fn daodapp_page(_pages: &mut Endpoints) {}
#[cfg(feature = "parity-dapps-makerotc")]

View File

@ -14,9 +14,10 @@ rustc_version = "0.1"
jsonrpc-core = "2.0"
log = "0.3"
env_logger = "0.3"
ws = "0.4.7"
ws = { git = "https://github.com/ethcore/ws-rs.git" }
ethcore-util = { path = "../util" }
ethcore-rpc = { path = "../rpc" }
parity-minimal-sysui = { git = "https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git" }
clippy = { version = "0.0.69", optional = true}

View File

@ -50,6 +50,7 @@ extern crate ethcore_util as util;
extern crate ethcore_rpc as rpc;
extern crate jsonrpc_core;
extern crate ws;
extern crate parity_minimal_sysui as sysui;
mod ws_server;
pub use ws_server::*;

View File

@ -89,7 +89,7 @@ impl Server {
fn start(addr: SocketAddr, handler: Arc<IoHandler>, queue: Arc<ConfirmationsQueue>) -> Result<Server, ServerError> {
let config = {
let mut config = ws::Settings::default();
config.max_connections = 5;
config.max_connections = 10;
config.method_strict = true;
config
};

View File

@ -17,6 +17,7 @@
//! Session handlers factory.
use ws;
use sysui;
use std::sync::Arc;
use jsonrpc_core::IoHandler;
@ -26,6 +27,35 @@ pub struct Session {
}
impl ws::Handler for Session {
fn on_request(&mut self, req: &ws::Request) -> ws::Result<(ws::Response)> {
// Detect if it's a websocket request.
if req.header("sec-websocket-key").is_some() {
return ws::Response::from_request(req);
}
// Otherwise try to serve a page.
sysui::handle(req.resource())
.map_or_else(
// return error
|| ws::Response::from_request(req),
// or serve the file
|f| {
let content_len = format!("{}", f.content.as_bytes().len());
let mut res = ws::Response::ok(f.content.into());
{
let mut headers = res.headers_mut();
headers.push(("Server".into(), b"Parity/SystemUI".to_vec()));
headers.push(("Connection".into(), b"Closed".to_vec()));
headers.push(("Content-Length".into(), content_len.as_bytes().to_vec()));
headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec()));
if !f.safe_to_embed {
headers.push(("X-Frame-Options".into(), b"SAMEORIGIN".to_vec()));
}
}
Ok(res)
})
}
fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> {
let req = try!(msg.as_text());
match self.handler.handle_request(req) {