diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 2508398e0..871b4fc46 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -466,6 +466,10 @@ usage! { "--ws-max-connections=[CONN]", "Maximum number of allowed concurrent WebSockets JSON-RPC connections.", + ARG arg_ws_max_payload: (usize) = 5usize, or |c: &Config| c.websockets.as_ref()?.max_payload, + "--ws-max-payload=[MB]", + "Specify maximum size for WS JSON-RPC requests in megabytes.", + ["Metrics"] FLAG flag_metrics: (bool) = false, or |c: &Config| c.metrics.as_ref()?.enable.clone(), "--metrics", @@ -903,6 +907,7 @@ struct Ws { origins: Option>, hosts: Option>, max_connections: Option, + max_payload: Option, } #[derive(Default, Debug, PartialEq, Deserialize)] @@ -1323,6 +1328,7 @@ mod tests { arg_ws_origins: "none".into(), arg_ws_hosts: "none".into(), arg_ws_max_connections: 100, + arg_ws_max_payload: 5, // IPC flag_no_ipc: false, @@ -1512,6 +1518,7 @@ mod tests { origins: Some(vec!["none".into()]), hosts: None, max_connections: None, + max_payload: None, }), rpc: Some(Rpc { disable: Some(true), diff --git a/parity/configuration.rs b/parity/configuration.rs index c2f3d3c10..5982594e5 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -951,6 +951,7 @@ impl Configuration { signer_path: self.directories().signer.into(), support_token_api, max_connections: self.args.arg_ws_max_connections, + max_payload: self.args.arg_ws_max_payload, }; Ok(conf) @@ -1483,6 +1484,7 @@ mod tests { signer_path: expected.into(), support_token_api: true, max_connections: 100, + max_payload: 5, }, LogConfig { color: !cfg!(windows), diff --git a/parity/rpc.rs b/parity/rpc.rs index 1022cfc9c..4cd639ba6 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -97,6 +97,7 @@ pub struct WsConfiguration { pub hosts: Option>, pub signer_path: PathBuf, pub support_token_api: bool, + pub max_payload: usize, } impl Default for WsConfiguration { @@ -116,6 +117,7 @@ impl Default for WsConfiguration { hosts: Some(Vec::new()), signer_path: replace_home(&data_dir, "$BASE/signer").into(), support_token_api: true, + max_payload: 5, } } } @@ -194,6 +196,7 @@ pub fn new_ws( rpc::WsExtractor::new(path.clone()), rpc::WsExtractor::new(path.clone()), rpc::WsStats::new(deps.stats.clone()), + conf.max_payload, ); // match start_result { diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 6a83c8043..09b8bb4a6 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -223,6 +223,7 @@ pub fn start_ws( extractor: T, middleware: V, stats: U, + max_payload: usize, ) -> Result where M: jsonrpc_core::Metadata, @@ -237,6 +238,7 @@ where .allowed_origins(allowed_origins) .allowed_hosts(allowed_hosts) .max_connections(max_connections) + .max_payload(max_payload * 1024 * 1024) .session_stats(stats) .start(addr) } diff --git a/rpc/src/tests/ws.rs b/rpc/src/tests/ws.rs index ef6991afc..d2953066b 100644 --- a/rpc/src/tests/ws.rs +++ b/rpc/src/tests/ws.rs @@ -44,6 +44,7 @@ pub fn serve() -> (Server, usize, GuardedAuthCodes) { extractors::WsExtractor::new(Some(&authcodes.path)), extractors::WsExtractor::new(Some(&authcodes.path)), extractors::WsStats::new(stats), + 5 * 1024 * 1024, ) .unwrap() });