WebSockets RPC server (#5425)
* Basic WS server. * CLI for WS server. * Bump jsonrpc * Fixing test.
This commit is contained in:
committed by
Marek Kotewicz
parent
1df30ee83e
commit
ea09aa584d
@@ -52,6 +52,14 @@ cors = "null"
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "rpc"]
|
||||
hosts = ["none"]
|
||||
|
||||
[websockets]
|
||||
disable = false
|
||||
port = 8546
|
||||
interface = "local"
|
||||
origins = ["none"]
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "rpc"]
|
||||
hosts = ["none"]
|
||||
|
||||
[ipc]
|
||||
disable = false
|
||||
path = "$HOME/.parity/jsonrpc.ipc"
|
||||
|
||||
@@ -24,6 +24,9 @@ allow_ips = "public"
|
||||
reserved_only = true
|
||||
reserved_peers = "./path/to/reserved_peers"
|
||||
|
||||
[websockets]
|
||||
disable = true
|
||||
origins = ["none"]
|
||||
|
||||
[rpc]
|
||||
disable = true
|
||||
|
||||
@@ -170,6 +170,20 @@ usage! {
|
||||
flag_jsonrpc_threads: Option<usize> = None,
|
||||
or |c: &Config| otry!(c.rpc).threads.map(Some),
|
||||
|
||||
// WS
|
||||
flag_no_ws: bool = false,
|
||||
or |c: &Config| otry!(c.websockets).disable.clone(),
|
||||
flag_ws_port: u16 = 8546u16,
|
||||
or |c: &Config| otry!(c.websockets).port.clone(),
|
||||
flag_ws_interface: String = "local",
|
||||
or |c: &Config| otry!(c.websockets).interface.clone(),
|
||||
flag_ws_apis: String = "web3,eth,net,parity,traces,rpc",
|
||||
or |c: &Config| otry!(c.websockets).apis.as_ref().map(|vec| vec.join(",")),
|
||||
flag_ws_origins: String = "none",
|
||||
or |c: &Config| otry!(c.websockets).origins.as_ref().map(|vec| vec.join(",")),
|
||||
flag_ws_hosts: String = "none",
|
||||
or |c: &Config| otry!(c.websockets).hosts.as_ref().map(|vec| vec.join(",")),
|
||||
|
||||
// IPC
|
||||
flag_no_ipc: bool = false,
|
||||
or |c: &Config| otry!(c.ipc).disable.clone(),
|
||||
@@ -363,6 +377,7 @@ struct Config {
|
||||
ui: Option<Ui>,
|
||||
network: Option<Network>,
|
||||
rpc: Option<Rpc>,
|
||||
websockets: Option<Ws>,
|
||||
ipc: Option<Ipc>,
|
||||
dapps: Option<Dapps>,
|
||||
secretstore: Option<SecretStore>,
|
||||
@@ -440,6 +455,16 @@ struct Rpc {
|
||||
threads: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
struct Ws {
|
||||
disable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
interface: Option<String>,
|
||||
apis: Option<Vec<String>>,
|
||||
origins: Option<Vec<String>>,
|
||||
hosts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, RustcDecodable)]
|
||||
struct Ipc {
|
||||
disable: Option<bool>,
|
||||
@@ -554,7 +579,7 @@ struct Misc {
|
||||
mod tests {
|
||||
use super::{
|
||||
Args, ArgsError,
|
||||
Config, Operating, Account, Ui, Network, Rpc, Ipc, Dapps, Ipfs, Mining, Footprint,
|
||||
Config, Operating, Account, Ui, Network, Ws, Rpc, Ipc, Dapps, Ipfs, Mining, Footprint,
|
||||
Snapshots, VM, Misc, SecretStore,
|
||||
};
|
||||
use toml;
|
||||
@@ -699,6 +724,14 @@ mod tests {
|
||||
flag_jsonrpc_hosts: "none".into(),
|
||||
flag_jsonrpc_threads: None,
|
||||
|
||||
// WS
|
||||
flag_no_ws: false,
|
||||
flag_ws_port: 8546u16,
|
||||
flag_ws_interface: "local".into(),
|
||||
flag_ws_apis: "web3,eth,net,parity,traces,rpc".into(),
|
||||
flag_ws_origins: "none".into(),
|
||||
flag_ws_hosts: "none".into(),
|
||||
|
||||
// IPC
|
||||
flag_no_ipc: false,
|
||||
flag_ipc_path: "$HOME/.parity/jsonrpc.ipc".into(),
|
||||
@@ -899,6 +932,14 @@ mod tests {
|
||||
reserved_only: Some(true),
|
||||
no_serve_light: None,
|
||||
}),
|
||||
websockets: Some(Ws {
|
||||
disable: Some(true),
|
||||
port: None,
|
||||
interface: None,
|
||||
apis: None,
|
||||
origins: Some(vec!["none".into()]),
|
||||
hosts: None,
|
||||
}),
|
||||
rpc: Some(Rpc {
|
||||
disable: Some(true),
|
||||
port: Some(8180),
|
||||
|
||||
@@ -157,7 +157,28 @@ API and Console Options:
|
||||
vectors. Special options: "all", "none",
|
||||
(default: {flag_jsonrpc_hosts}).
|
||||
--jsonrpc-threads THREADS Enables experimental faster implementation of JSON-RPC server.
|
||||
Requires Dapps server to be disabled using --no-dapps. (default: {flag_jsonrpc_threads:?})
|
||||
Requires Dapps server to be disabled
|
||||
using --no-dapps. (default: {flag_jsonrpc_threads:?})
|
||||
|
||||
--no-ws Disable the WebSockets server. (default: {flag_no_ws})
|
||||
--ws-port PORT Specify the port portion of the WebSockets server
|
||||
(default: {flag_ws_port}).
|
||||
--ws-interface IP Specify the hostname portion of the WebSockets
|
||||
server, IP should be an interface's IP address, or
|
||||
all (all interfaces) or local (default: {flag_ws_interface}).
|
||||
--ws-apis APIS Specify the APIs available through the WebSockets
|
||||
interface. APIS is a comma-delimited list of API
|
||||
name. Possible name are web3, eth, net, personal,
|
||||
parity, parity_set, traces, rpc, parity_accounts.
|
||||
(default: {flag_ws_apis}).
|
||||
--ws-origins URL Specify Origin header values allowed to connect.
|
||||
Special options: "all", "none".
|
||||
(default: {flag_ws_origins})
|
||||
--ws-hosts HOSTS List of allowed Host header values. This option will
|
||||
validate the Host header sent by the browser, it
|
||||
is additional security against some attack
|
||||
vectors. Special options: "all", "none",
|
||||
(default: {flag_ws_hosts}).
|
||||
|
||||
--no-ipc Disable JSON-RPC over IPC service. (default: {flag_no_ipc})
|
||||
--ipc-path PATH Specify custom path for JSON-RPC over IPC service
|
||||
|
||||
Reference in New Issue
Block a user