From d0e8f579e2633737ce6f7f0a6e9727ae9913b111 Mon Sep 17 00:00:00 2001 From: David Braden Date: Tue, 22 Oct 2024 13:17:12 -0600 Subject: [PATCH] Underflow fix (#35) * disable rate-limiting * underflow fix --- Cargo.lock | 12 ++++++------ Cargo.toml | 12 ++++++------ rust/sbd-bench/Cargo.toml | 2 +- rust/sbd-client/Cargo.toml | 2 +- rust/sbd-client/src/send_buf.rs | 6 +++++- rust/sbd-e2e-crypto-client/Cargo.toml | 2 +- rust/sbd-o-bahn-client-tester/Cargo.toml | 2 +- rust/sbd-o-bahn-server-tester/Cargo.toml | 2 +- rust/sbd-server/Cargo.toml | 2 +- ts/sbd-server/src/signal.ts | 8 ++++++++ 10 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14c1417..c4981c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1534,7 +1534,7 @@ dependencies = [ [[package]] name = "sbd-bench" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "base64 0.22.1", "criterion", @@ -1545,7 +1545,7 @@ dependencies = [ [[package]] name = "sbd-client" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -1565,7 +1565,7 @@ dependencies = [ [[package]] name = "sbd-e2e-crypto-client" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "sbd-client", "sbd-server", @@ -1576,7 +1576,7 @@ dependencies = [ [[package]] name = "sbd-o-bahn-client-tester" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "hex", "sbd-server", @@ -1585,7 +1585,7 @@ dependencies = [ [[package]] name = "sbd-o-bahn-server-tester" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "sbd-client", "tokio", @@ -1593,7 +1593,7 @@ dependencies = [ [[package]] name = "sbd-server" -version = "0.0.6-alpha" +version = "0.0.7-alpha" dependencies = [ "anstyle", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 88f4d4b..1cc4d07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,12 @@ panic = "abort" [workspace.dependencies] # workspace member deps -sbd-bench = { version = "0.0.6-alpha", path = "rust/sbd-bench" } -sbd-client = { version = "0.0.6-alpha", path = "rust/sbd-client" } -sbd-e2e-crypto-client = { version = "0.0.6-alpha", path = "rust/sbd-e2e-crypto-client" } -sbd-o-bahn-client-tester = { version = "0.0.6-alpha", path = "rust/sbd-o-bahn-client-tester" } -sbd-o-bahn-server-tester = { version = "0.0.6-alpha", path = "rust/sbd-o-bahn-server-tester" } -sbd-server = { version = "0.0.6-alpha", path = "rust/sbd-server" } +sbd-bench = { version = "0.0.7-alpha", path = "rust/sbd-bench" } +sbd-client = { version = "0.0.7-alpha", path = "rust/sbd-client" } +sbd-e2e-crypto-client = { version = "0.0.7-alpha", path = "rust/sbd-e2e-crypto-client" } +sbd-o-bahn-client-tester = { version = "0.0.7-alpha", path = "rust/sbd-o-bahn-client-tester" } +sbd-o-bahn-server-tester = { version = "0.0.7-alpha", path = "rust/sbd-o-bahn-server-tester" } +sbd-server = { version = "0.0.7-alpha", path = "rust/sbd-server" } # crate deps anstyle = "1.0.6" base64 = "0.22.0" diff --git a/rust/sbd-bench/Cargo.toml b/rust/sbd-bench/Cargo.toml index a354dec..e97e867 100644 --- a/rust/sbd-bench/Cargo.toml +++ b/rust/sbd-bench/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-bench" -version = "0.0.6-alpha" +version = "0.0.7-alpha" edition = "2021" [dependencies] diff --git a/rust/sbd-client/Cargo.toml b/rust/sbd-client/Cargo.toml index a5ce4e4..fa3d5e5 100644 --- a/rust/sbd-client/Cargo.toml +++ b/rust/sbd-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-client" -version = "0.0.6-alpha" +version = "0.0.7-alpha" description = "simple websocket-based message relay client" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd" diff --git a/rust/sbd-client/src/send_buf.rs b/rust/sbd-client/src/send_buf.rs index 51bb075..8b2bfed 100644 --- a/rust/sbd-client/src/send_buf.rs +++ b/rust/sbd-client/src/send_buf.rs @@ -84,7 +84,11 @@ impl SendBuf { self.limit_rate = limit; let kbps = (8_000_000.0 / limit as f64) as u64; let now = self.origin.elapsed().as_nanos() as u64; - let next_send_s = (now - self.next_send_at) as f64 / 1_000_000_000.0; + let next_send_s = if now > self.next_send_at { + (now - self.next_send_at) as f64 / 1_000_000_000.0 + } else { + 0.0 + }; tracing::debug!( target: "NETAUDIT", full_url = self.full_url, diff --git a/rust/sbd-e2e-crypto-client/Cargo.toml b/rust/sbd-e2e-crypto-client/Cargo.toml index 2feb7c7..d9ce961 100644 --- a/rust/sbd-e2e-crypto-client/Cargo.toml +++ b/rust/sbd-e2e-crypto-client/Cargo.toml @@ -7,7 +7,7 @@ documentation = "https://docs.rs/sbd-e2e-crypto-client" authors = ["Holochain Core Dev Team "] keywords = ["holochain", "holo", "p2p", "networking"] categories = ["network-programming"] -version = "0.0.6-alpha" +version = "0.0.7-alpha" edition = "2021" [dependencies] diff --git a/rust/sbd-o-bahn-client-tester/Cargo.toml b/rust/sbd-o-bahn-client-tester/Cargo.toml index e681091..023c4f9 100644 --- a/rust/sbd-o-bahn-client-tester/Cargo.toml +++ b/rust/sbd-o-bahn-client-tester/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-o-bahn-client-tester" -version = "0.0.6-alpha" +version = "0.0.7-alpha" description = "simple websocket-based message relay client tester" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd" diff --git a/rust/sbd-o-bahn-server-tester/Cargo.toml b/rust/sbd-o-bahn-server-tester/Cargo.toml index d8e5126..7a69f0a 100644 --- a/rust/sbd-o-bahn-server-tester/Cargo.toml +++ b/rust/sbd-o-bahn-server-tester/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-o-bahn-server-tester" -version = "0.0.6-alpha" +version = "0.0.7-alpha" description = "simple websocket-based message relay server tester" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd" diff --git a/rust/sbd-server/Cargo.toml b/rust/sbd-server/Cargo.toml index 0ba605d..f8fd798 100644 --- a/rust/sbd-server/Cargo.toml +++ b/rust/sbd-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-server" -version = "0.0.6-alpha" +version = "0.0.7-alpha" description = "simple websocket-based message relay server" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd" diff --git a/ts/sbd-server/src/signal.ts b/ts/sbd-server/src/signal.ts index 0e81553..04ba3b6 100644 --- a/ts/sbd-server/src/signal.ts +++ b/ts/sbd-server/src/signal.ts @@ -158,6 +158,13 @@ export class DoSignal extends DurableObject { * closing the websocket if we violate the limit. */ async ipRateLimit(ip: string, pk: string, bytes: number, ws: WebSocket) { + // disabling rate limiting temporarily as an experiment + const HACK_NANOS_PER_BYTE = 1; + if (this.curLimit !== HACK_NANOS_PER_BYTE) { + this.curLimit = HACK_NANOS_PER_BYTE; + ws.send(new MsgLbrt(HACK_NANOS_PER_BYTE).encoded()); + } + /* try { const ipId = this.env.RATE_LIMIT.idFromName(ip); const ipStub = this.env.RATE_LIMIT.get( @@ -179,6 +186,7 @@ export class DoSignal extends DurableObject { } catch (e) { throw common.err(`limit ${e}`, 429); } + */ } /**