From 4d29508b4c6ca8bf8874e5a3afbea26dd6505a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 31 May 2016 20:12:47 +0200 Subject: [PATCH] Minimal System UI --- Cargo.lock | 41 +++++++++++++++++++++++++++++---- signer/Cargo.toml | 3 ++- signer/src/lib.rs | 1 + signer/src/ws_server/mod.rs | 2 +- signer/src/ws_server/session.rs | 23 ++++++++++++++++++ 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c81020f66..c2d455efe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", "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]] @@ -701,6 +702,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" @@ -758,6 +775,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" @@ -921,6 +947,10 @@ dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] +[[package]] +name = "parity-minimal-sysui" +version = "0.1.0" + [[package]] name = "phf" version = "0.7.14" @@ -1426,15 +1456,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]] diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 170c9320e..6b9f2036f 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -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 = { path = "../../parity-dapps-minimal-sysui-rs" } clippy = { version = "0.0.69", optional = true} diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 8391d42b4..fb3e76cca 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -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::*; diff --git a/signer/src/ws_server/mod.rs b/signer/src/ws_server/mod.rs index c987d7a87..0d55fd906 100644 --- a/signer/src/ws_server/mod.rs +++ b/signer/src/ws_server/mod.rs @@ -89,7 +89,7 @@ impl Server { fn start(addr: SocketAddr, handler: Arc, queue: Arc) -> Result { let config = { let mut config = ws::Settings::default(); - config.max_connections = 5; + config.max_connections = 10; config.method_strict = true; config }; diff --git a/signer/src/ws_server/session.rs b/signer/src/ws_server/session.rs index 258e05d5b..02850e739 100644 --- a/signer/src/ws_server/session.rs +++ b/signer/src/ws_server/session.rs @@ -17,6 +17,7 @@ //! Session handlers factory. use ws; +use sysui; use std::sync::Arc; use jsonrpc_core::IoHandler; @@ -26,6 +27,28 @@ 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(|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(), "Parity/SystemUI".as_bytes().to_vec())); + headers.push(("Connection".into(), "Closed".as_bytes().to_vec())); + headers.push(("Content-Length".into(), content_len.as_bytes().to_vec())); + headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec())); + } + Ok(res) + }).unwrap_or_else(|| ws::Response::from_request(req)) + } + fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> { let req = try!(msg.as_text()); match self.handler.handle_request(req) {