rpc servers: update jsonrpsee to fix host filtering + WS server-side pings (#11661)

* bump jsonrpsee to fix #11480

In addition it adds WebSocket server-side pings which is configured to
send out pings periodically every 30 seconds.

* use released crates.io version

* Update Cargo.toml
This commit is contained in:
Niklas Adolfsson
2022-06-14 22:43:25 +02:00
committed by GitHub
parent f9ea8b8d0f
commit bed163dceb
22 changed files with 69 additions and 63 deletions
+13 -9
View File
@@ -103,7 +103,7 @@ pub async fn start_http<M: Send + Sync + 'static>(
.max_request_body_size(max_payload_in as u32)
.max_response_body_size(max_payload_out as u32)
.set_access_control(acl.build())
.health_api("/health", "system_health")
.health_api("/health", "system_health")?
.custom_tokio_runtime(rt);
let rpc_api = build_rpc_api(rpc_api);
@@ -141,12 +141,23 @@ pub async fn start_ws<M: Send + Sync + 'static>(
let (max_payload_in, max_payload_out, max_connections, max_subs_per_conn) =
ws_config.deconstruct();
let mut acl = AccessControlBuilder::new();
if let Some(cors) = cors {
// Whitelist listening address.
// NOTE: set_allowed_hosts will whitelist both ports but only one will used.
acl = acl.set_allowed_hosts(format_allowed_hosts(&addrs[..]))?;
acl = acl.set_allowed_origins(cors)?;
};
let mut builder = WsServerBuilder::new()
.max_request_body_size(max_payload_in)
.max_response_body_size(max_payload_out)
.max_connections(max_connections)
.max_subscriptions_per_connection(max_subs_per_conn)
.custom_tokio_runtime(rt);
.ping_interval(std::time::Duration::from_secs(30))
.custom_tokio_runtime(rt)
.set_access_control(acl.build());
if let Some(provider) = id_provider {
builder = builder.set_id_provider(provider);
@@ -154,13 +165,6 @@ pub async fn start_ws<M: Send + Sync + 'static>(
builder = builder.set_id_provider(RandomStringIdProvider::new(16));
};
if let Some(cors) = cors {
// Whitelist listening address.
// NOTE: set_allowed_hosts will whitelist both ports but only one will used.
builder = builder.set_allowed_hosts(format_allowed_hosts(&addrs[..]))?;
builder = builder.set_allowed_origins(cors)?;
}
let rpc_api = build_rpc_api(rpc_api);
let (handle, addr) = if let Some(metrics) = metrics {
let middleware = RpcMiddleware::new(metrics, "ws".into());