Skip to content

Commit 1a64d58

Browse files
committed
patch(hermes): improve ws reliability
- Add max message size for incoming messages - Add sent message rate limit and ip whitelisting
1 parent 5fdc0d2 commit 1a64d58

File tree

5 files changed

+182
-33
lines changed

5 files changed

+182
-33
lines changed

hermes/Cargo.lock

Lines changed: 68 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermes/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

@@ -19,10 +19,13 @@ env_logger = { version = "0.10.0" }
1919
futures = { version = "0.3.28" }
2020
hex = { version = "0.4.3", features = ["serde"] }
2121
humantime = { version = "2.1.0" }
22+
ipnet = { version = "2.8.0" }
23+
governor = { version = "0.6.0" }
2224
lazy_static = { version = "1.4.0" }
2325
libc = { version = "0.2.140" }
2426
log = { version = "0.4.17" }
2527
mock_instant = { version = "0.3.1", features = ["sync"] }
28+
nonzero_ext = { version = "0.3.0" }
2629
prometheus-client = { version = "0.21.1" }
2730
pyth-sdk = { version = "0.8.0" }
2831
pythnet-sdk = { path = "../pythnet/pythnet_sdk/", version = "2.0.0", features = ["strum"] }

hermes/src/api.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ use {
1111
routing::get,
1212
Router,
1313
},
14+
ipnet::IpNet,
1415
serde_qs::axum::QsQueryConfig,
15-
std::sync::{
16-
atomic::Ordering,
17-
Arc,
16+
std::{
17+
net::SocketAddr,
18+
sync::{
19+
atomic::Ordering,
20+
Arc,
21+
},
1822
},
1923
tokio::{
2024
signal,
@@ -36,10 +40,10 @@ pub struct ApiState {
3640
}
3741

3842
impl ApiState {
39-
pub fn new(state: Arc<State>) -> Self {
43+
pub fn new(state: Arc<State>, ws_whitelist: Vec<IpNet>) -> Self {
4044
Self {
4145
state,
42-
ws: Arc::new(ws::WsState::new()),
46+
ws: Arc::new(ws::WsState::new(ws_whitelist)),
4347
}
4448
}
4549
}
@@ -84,7 +88,7 @@ pub async fn run(
8488
)]
8589
struct ApiDoc;
8690

87-
let state = ApiState::new(state);
91+
let state = ApiState::new(state, opts.rpc.ws_whitelist);
8892

8993
// Initialize Axum Router. Note the type here is a `Router<State>` due to the use of the
9094
// `with_state` method which replaces `Body` with `State` in the type signature.
@@ -131,7 +135,7 @@ pub async fn run(
131135
// Binds the axum's server to the configured address and port. This is a blocking call and will
132136
// not return until the server is shutdown.
133137
axum::Server::try_bind(&opts.rpc.addr)?
134-
.serve(app.into_make_service())
138+
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
135139
.with_graceful_shutdown(async {
136140
// Ignore Ctrl+C errors, either way we need to shut down. The main Ctrl+C handler
137141
// should also have triggered so we will let that one print the shutdown warning.

0 commit comments

Comments
 (0)