Allow customization of max WS connections. (#8257)
* Allow customization of max WS connections. * remove superflous line. * Add test for CLI argument parsing.
This commit is contained in:
parent
5ea4c22868
commit
c1cced3662
@ -499,6 +499,10 @@ usage! {
|
||||
"--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\".",
|
||||
|
||||
ARG arg_ws_max_connections: (usize) = 100usize, or |c: &Config| c.websockets.as_ref()?.max_connections,
|
||||
"--ws-max-connections=[CONN]",
|
||||
"Maximal number of allowed concurrent WS connections.",
|
||||
|
||||
["API and console options – IPC"]
|
||||
FLAG flag_no_ipc: (bool) = false, or |c: &Config| c.ipc.as_ref()?.disable.clone(),
|
||||
"--no-ipc",
|
||||
@ -1087,6 +1091,7 @@ struct Ws {
|
||||
apis: Option<Vec<String>>,
|
||||
origins: Option<Vec<String>>,
|
||||
hosts: Option<Vec<String>>,
|
||||
max_connections: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@ -1520,6 +1525,7 @@ mod tests {
|
||||
arg_ws_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(),
|
||||
arg_ws_origins: "none".into(),
|
||||
arg_ws_hosts: "none".into(),
|
||||
arg_ws_max_connections: 100,
|
||||
|
||||
// IPC
|
||||
flag_no_ipc: false,
|
||||
@ -1759,6 +1765,7 @@ mod tests {
|
||||
apis: None,
|
||||
origins: Some(vec!["none".into()]),
|
||||
hosts: None,
|
||||
max_connections: None,
|
||||
}),
|
||||
rpc: Some(Rpc {
|
||||
disable: Some(true),
|
||||
|
@ -922,6 +922,7 @@ impl Configuration {
|
||||
support_token_api,
|
||||
ui_address: ui.address(),
|
||||
dapps_address: http.address(),
|
||||
max_connections: self.args.arg_ws_max_connections,
|
||||
};
|
||||
|
||||
Ok(conf)
|
||||
@ -1361,7 +1362,8 @@ mod tests {
|
||||
signer_path: expected.into(),
|
||||
ui_address: None,
|
||||
dapps_address: Some("127.0.0.1:8545".into()),
|
||||
support_token_api: true
|
||||
support_token_api: true,
|
||||
max_connections: 100,
|
||||
}, UiConfiguration {
|
||||
enabled: false,
|
||||
interface: "127.0.0.1".into(),
|
||||
@ -1374,6 +1376,17 @@ mod tests {
|
||||
} ));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ws_max_connections() {
|
||||
let args = vec!["parity", "--ws-max-connections", "1"];
|
||||
let conf = parse(&args);
|
||||
|
||||
assert_eq!(conf.ws_config().unwrap(), WsConfiguration {
|
||||
max_connections: 1,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_run_cmd() {
|
||||
let args = vec!["parity"];
|
||||
|
@ -146,6 +146,7 @@ pub struct WsConfiguration {
|
||||
pub interface: String,
|
||||
pub port: u16,
|
||||
pub apis: ApiSet,
|
||||
pub max_connections: usize,
|
||||
pub origins: Option<Vec<String>>,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub signer_path: PathBuf,
|
||||
@ -162,6 +163,7 @@ impl Default for WsConfiguration {
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8546,
|
||||
apis: ApiSet::UnsafeContext,
|
||||
max_connections: 100,
|
||||
origins: Some(vec!["parity://*".into(),"chrome-extension://*".into(), "moz-extension://*".into()]),
|
||||
hosts: Some(Vec::new()),
|
||||
signer_path: replace_home(&data_dir, "$BASE/signer").into(),
|
||||
@ -240,6 +242,7 @@ pub fn new_ws<D: rpc_apis::Dependencies>(
|
||||
remote.clone(),
|
||||
allowed_origins,
|
||||
allowed_hosts,
|
||||
conf.max_connections,
|
||||
rpc::WsExtractor::new(path.clone()),
|
||||
rpc::WsExtractor::new(path.clone()),
|
||||
rpc::WsStats::new(deps.stats.clone()),
|
||||
|
@ -175,6 +175,7 @@ pub fn start_ws<M, S, H, T, U, V>(
|
||||
remote: tokio_core::reactor::Remote,
|
||||
allowed_origins: ws::DomainsValidation<ws::Origin>,
|
||||
allowed_hosts: ws::DomainsValidation<ws::Host>,
|
||||
max_connections: usize,
|
||||
extractor: T,
|
||||
middleware: V,
|
||||
stats: U,
|
||||
@ -191,6 +192,7 @@ pub fn start_ws<M, S, H, T, U, V>(
|
||||
.request_middleware(middleware)
|
||||
.allowed_origins(allowed_origins)
|
||||
.allowed_hosts(allowed_hosts)
|
||||
.max_connections(max_connections)
|
||||
.session_stats(stats)
|
||||
.start(addr)
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ pub fn serve() -> (Server<ws::Server>, usize, GuardedAuthCodes) {
|
||||
remote,
|
||||
ws::DomainsValidation::Disabled,
|
||||
ws::DomainsValidation::Disabled,
|
||||
5,
|
||||
extractors::WsExtractor::new(Some(&authcodes.path)),
|
||||
extractors::WsExtractor::new(Some(&authcodes.path)),
|
||||
extractors::WsStats::new(stats),
|
||||
|
Loading…
Reference in New Issue
Block a user