Minimal System UI

This commit is contained in:
Tomasz Drwięga 2016-05-31 20:12:47 +02:00
parent 70cecb49b0
commit 4d29508b4c
5 changed files with 63 additions and 7 deletions

41
Cargo.lock generated
View File

@ -358,8 +358,9 @@ dependencies = [
"ethcore-util 1.2.0", "ethcore-util 1.2.0",
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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]] [[package]]
@ -701,6 +702,22 @@ dependencies = [
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "mio" name = "mio"
version = "0.5.1" version = "0.5.1"
@ -758,6 +775,15 @@ dependencies = [
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "nix" name = "nix"
version = "0.5.0" version = "0.5.0"
@ -921,6 +947,10 @@ dependencies = [
"parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)",
] ]
[[package]]
name = "parity-minimal-sysui"
version = "0.1.0"
[[package]] [[package]]
name = "phf" name = "phf"
version = "0.7.14" version = "0.7.14"
@ -1426,15 +1456,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "ws" name = "ws"
version = "0.4.7" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ethcore/ws-rs.git#c0c2a3fc30dc77c4e6d4d90756f8bc3b5cfbc311"
dependencies = [ dependencies = [
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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]] [[package]]

View File

@ -14,9 +14,10 @@ rustc_version = "0.1"
jsonrpc-core = "2.0" jsonrpc-core = "2.0"
log = "0.3" log = "0.3"
env_logger = "0.3" env_logger = "0.3"
ws = "0.4.7" ws = { git = "https://github.com/ethcore/ws-rs.git" }
ethcore-util = { path = "../util" } ethcore-util = { path = "../util" }
ethcore-rpc = { path = "../rpc" } ethcore-rpc = { path = "../rpc" }
parity-minimal-sysui = { path = "../../parity-dapps-minimal-sysui-rs" }
clippy = { version = "0.0.69", optional = true} 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 ethcore_rpc as rpc;
extern crate jsonrpc_core; extern crate jsonrpc_core;
extern crate ws; extern crate ws;
extern crate parity_minimal_sysui as sysui;
mod ws_server; mod ws_server;
pub use 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> { fn start(addr: SocketAddr, handler: Arc<IoHandler>, queue: Arc<ConfirmationsQueue>) -> Result<Server, ServerError> {
let config = { let config = {
let mut config = ws::Settings::default(); let mut config = ws::Settings::default();
config.max_connections = 5; config.max_connections = 10;
config.method_strict = true; config.method_strict = true;
config config
}; };

View File

@ -17,6 +17,7 @@
//! Session handlers factory. //! Session handlers factory.
use ws; use ws;
use sysui;
use std::sync::Arc; use std::sync::Arc;
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
@ -26,6 +27,28 @@ pub struct Session {
} }
impl ws::Handler for 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<()> { fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> {
let req = try!(msg.as_text()); let req = try!(msg.as_text());
match self.handler.handle_request(req) { match self.handler.handle_request(req) {