diff --git a/.github/manifest/vcpkg-configuration.json b/.github/manifest/vcpkg-configuration.json new file mode 100644 index 0000000..a5efe40 --- /dev/null +++ b/.github/manifest/vcpkg-configuration.json @@ -0,0 +1,8 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "9760ce6194ef51aa4faf77b6321e1280daa4545c", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [] +} diff --git a/.github/manifest/vcpkg.json b/.github/manifest/vcpkg.json new file mode 100644 index 0000000..3f8d09a --- /dev/null +++ b/.github/manifest/vcpkg.json @@ -0,0 +1,9 @@ +{ + "dependencies": [ + { + "name": "libsodium", + "version>=": "1.0.20" + } + ], + "builtin-baseline": "9760ce6194ef51aa4faf77b6321e1280daa4545c" +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1122ce..9dbf190 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,9 +38,9 @@ jobs: uses: johnwason/vcpkg-action@v6 id: vcpkg with: - pkgs: libsodium triplet: x64-windows-release token: ${{ github.token }} + manifest-dir: ${{ github.workspace }}/.github/manifest github-binarycache: true - name: Cargo Test Windows diff --git a/Cargo.lock b/Cargo.lock index 59ccd9f..379bc1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1534,7 +1534,7 @@ dependencies = [ [[package]] name = "sbd-bench" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "base64 0.22.1", "criterion", @@ -1545,7 +1545,7 @@ dependencies = [ [[package]] name = "sbd-client" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "base64 0.22.1", "ed25519-dalek", @@ -1559,22 +1559,24 @@ dependencies = [ "tokio", "tokio-rustls", "tokio-tungstenite", + "tracing", "webpki-roots", ] [[package]] name = "sbd-e2e-crypto-client" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "sbd-client", "sbd-server", "sodoken", "tokio", + "tracing", ] [[package]] name = "sbd-o-bahn-client-tester" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "hex", "sbd-server", @@ -1583,7 +1585,7 @@ dependencies = [ [[package]] name = "sbd-o-bahn-server-tester" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "sbd-client", "tokio", @@ -1591,7 +1593,7 @@ dependencies = [ [[package]] name = "sbd-server" -version = "0.0.4-alpha" +version = "0.0.5-alpha" dependencies = [ "anstyle", "base64 0.22.1", @@ -1968,6 +1970,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + [[package]] name = "try-lock" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index a44c185..a57f515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,12 +14,12 @@ panic = "abort" [workspace.dependencies] # workspace member deps -sbd-bench = { version = "0.0.4-alpha", path = "rust/sbd-bench" } -sbd-client = { version = "0.0.4-alpha", path = "rust/sbd-client" } -sbd-e2e-crypto-client = { version = "0.0.4-alpha", path = "rust/sbd-e2e-crypto-client" } -sbd-o-bahn-client-tester = { version = "0.0.4-alpha", path = "rust/sbd-o-bahn-client-tester" } -sbd-o-bahn-server-tester = { version = "0.0.4-alpha", path = "rust/sbd-o-bahn-server-tester" } -sbd-server = { version = "0.0.4-alpha", path = "rust/sbd-server" } +sbd-bench = { version = "0.0.5-alpha", path = "rust/sbd-bench" } +sbd-client = { version = "0.0.5-alpha", path = "rust/sbd-client" } +sbd-e2e-crypto-client = { version = "0.0.5-alpha", path = "rust/sbd-e2e-crypto-client" } +sbd-o-bahn-client-tester = { version = "0.0.5-alpha", path = "rust/sbd-o-bahn-client-tester" } +sbd-o-bahn-server-tester = { version = "0.0.5-alpha", path = "rust/sbd-o-bahn-server-tester" } +sbd-server = { version = "0.0.5-alpha", path = "rust/sbd-server" } # crate deps anstyle = "1.0.6" base64 = "0.22.0" @@ -45,6 +45,7 @@ tempfile = "3.10.1" tokio = { version = "1.37.0", default-features = false } tokio-rustls = "0.25.0" tokio-tungstenite = { version = "0.21.0", default-features = false } +tracing = "0.1.40" webpki-roots = "0.26.1" #[patch.crates-io] diff --git a/rust/sbd-bench/Cargo.toml b/rust/sbd-bench/Cargo.toml index 47820f9..f0402ec 100644 --- a/rust/sbd-bench/Cargo.toml +++ b/rust/sbd-bench/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-bench" -version = "0.0.4-alpha" +version = "0.0.5-alpha" edition = "2021" [dependencies] diff --git a/rust/sbd-client/Cargo.toml b/rust/sbd-client/Cargo.toml index 97e56b3..f87c25a 100644 --- a/rust/sbd-client/Cargo.toml +++ b/rust/sbd-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-client" -version = "0.0.4-alpha" +version = "0.0.5-alpha" description = "simple websocket-based message relay client" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd" @@ -18,7 +18,7 @@ rustls-native-certs = { workspace = true } tokio = { workspace = true, default-features = false, features = [ "io-util", "net", "sync", "time", "rt" ] } tokio-rustls = { workspace = true } tokio-tungstenite = { workspace = true, default-features = false, features = [ "connect", "__rustls-tls" ] } - +tracing = { workspace = true } # optional ed25519-dalek = { workspace = true, features = [ "rand_core" ], optional = true } @@ -31,10 +31,10 @@ webpki-roots = { workspace = true } [dev-dependencies] escargot = { workspace = true, features = [ "print" ] } hex = { workspace = true } -tokio = { workspace = true, features = [ "full" ] } # don't use workspace, because that has a version # use path only so we can cargo publish without circular dep problems sbd-server = { path = "../sbd-server" } +tokio = { workspace = true, features = [ "full" ] } [features] default = [ "crypto" ] diff --git a/rust/sbd-client/src/lib.rs b/rust/sbd-client/src/lib.rs index fd8d50d..bc029e5 100644 --- a/rust/sbd-client/src/lib.rs +++ b/rust/sbd-client/src/lib.rs @@ -276,6 +276,7 @@ impl SbdClient { .await?; let send_buf = send_buf::SendBuf::new( + full_url.clone(), send, config.out_buffer_size, (limit_byte_nanos as f64 * 1.1) as u64, diff --git a/rust/sbd-client/src/send_buf.rs b/rust/sbd-client/src/send_buf.rs index 11c4e2c..b6494cf 100644 --- a/rust/sbd-client/src/send_buf.rs +++ b/rust/sbd-client/src/send_buf.rs @@ -3,6 +3,7 @@ use super::*; use std::collections::VecDeque; pub struct SendBuf { + pub full_url: String, pub ws: raw_client::WsRawSend, pub buf: VecDeque>, pub out_buffer_size: usize, @@ -16,13 +17,24 @@ pub struct SendBuf { impl SendBuf { /// construct a new send buf pub fn new( + full_url: String, ws: raw_client::WsRawSend, out_buffer_size: usize, limit_rate: u64, idle_keepalive: std::time::Duration, pre_sent_bytes: usize, ) -> Self { + let kbps = (8_000_000.0 / limit_rate as f64) as u64; + tracing::debug!( + target: "NETAUDIT", + full_url, + kbps, + m = "sbd-client", + a = "initial_rate_limit", + ); + let mut this = Self { + full_url, ws, buf: VecDeque::default(), out_buffer_size, @@ -59,6 +71,16 @@ impl SendBuf { + (MAX_MSG_SIZE as u64 * self.limit_rate); } self.limit_rate = limit; + let kbps = (8_000_000.0 / limit as f64) as u64; + let next_send_s = self.next_send_at as f64 / 1_000_000_000.0; + tracing::debug!( + target: "NETAUDIT", + full_url = self.full_url, + kbps, + next_send_s, + m = "sbd-client", + a = "new_rate_limit", + ); } /// If we need to wait before taking the next step, this diff --git a/rust/sbd-e2e-crypto-client/Cargo.toml b/rust/sbd-e2e-crypto-client/Cargo.toml index 865a71d..a945c07 100644 --- a/rust/sbd-e2e-crypto-client/Cargo.toml +++ b/rust/sbd-e2e-crypto-client/Cargo.toml @@ -7,13 +7,14 @@ documentation = "https://docs.rs/sbd-e2e-crypto-client" authors = ["Holochain Core Dev Team "] keywords = ["holochain", "holo", "p2p", "networking"] categories = ["network-programming"] -version = "0.0.4-alpha" +version = "0.0.5-alpha" edition = "2021" [dependencies] sbd-client = { workspace = true } sodoken = { workspace = true } tokio = { workspace = true } +tracing = { workspace = true } [dev-dependencies] sbd-server = { workspace = true } diff --git a/rust/sbd-e2e-crypto-client/src/lib.rs b/rust/sbd-e2e-crypto-client/src/lib.rs index cf04bb2..b3beceb 100644 --- a/rust/sbd-e2e-crypto-client/src/lib.rs +++ b/rust/sbd-e2e-crypto-client/src/lib.rs @@ -66,16 +66,25 @@ struct Inner { map: HashMap, } +fn do_close_peer(pk: &PubKey, conn: &mut Conn, cooldown: std::time::Duration) { + tracing::debug!( + target: "NETAUDIT", + pub_key = ?pk, + cooldown_s = cooldown.as_secs_f64(), + m = "sbd-e2e-crypto-client", + a = "close_peer", + ); + *conn = Conn::Cooldown(tokio::time::Instant::now() + cooldown); +} + impl Inner { pub async fn close(&mut self) { self.client.close().await; } - pub async fn close_peer(&mut self, pk: &PubKey) { + pub fn close_peer(&mut self, pk: &PubKey) { if let Some(conn) = self.map.get_mut(pk) { - *conn = Conn::Cooldown( - tokio::time::Instant::now() + self.config.cooldown, - ); + do_close_peer(pk, conn, self.config.cooldown); } } @@ -103,9 +112,7 @@ impl Inner { } .await { - *conn = Conn::Cooldown( - tokio::time::Instant::now() + config.cooldown, - ); + do_close_peer(pk, conn, config.cooldown); Err(err) } else { Ok(()) @@ -143,10 +150,7 @@ impl Inner { match dec.decrypt(msg.message()) { Err(_) => { - *conn = Conn::Cooldown( - tokio::time::Instant::now() - + config.cooldown, - ); + do_close_peer(&pk, conn, config.cooldown); Ok(None) } Ok(None) => Ok(None), @@ -182,9 +186,7 @@ impl Inner { } .await { - *conn = Conn::Cooldown( - tokio::time::Instant::now() + config.cooldown, - ); + do_close_peer(pk, conn, config.cooldown); Err(err) } else { Ok(()) @@ -196,12 +198,10 @@ impl Inner { fn prune(config: &Config, map: &mut HashMap) { let now = tokio::time::Instant::now(); - map.retain(|_, c| { + map.retain(|pk, c| { if let Conn::Active { last_active, .. } = c { if now - *last_active > config.max_idle { - *c = Conn::Cooldown( - tokio::time::Instant::now() + config.cooldown, - ); + do_close_peer(pk, c, config.cooldown); } } @@ -240,8 +240,20 @@ impl Inner { return Err(Error::other("ignore")); } if len >= config.max_connections { + tracing::debug!( + target: "NETAUDIT", + pub_key = ?pk, + m = "sbd-e2e-crypto-client", + "cannot open: too many connections", + ); return Err(Error::other("too many connections")); } + tracing::debug!( + target: "NETAUDIT", + pub_key = ?pk, + m = "sbd-e2e-crypto-client", + a = "open_peer", + ); let (enc, hdr, dec) = crypto.new_enc(pk)?; Ok(( e.insert(Conn::Active { @@ -375,7 +387,7 @@ impl SbdClientCrypto { /// Close a connection to a specific peer. pub async fn close_peer(&self, pk: &PubKey) { if let Some(inner) = self.inner.lock().await.as_mut() { - inner.close_peer(pk).await; + inner.close_peer(pk); } } diff --git a/rust/sbd-o-bahn-client-tester/Cargo.toml b/rust/sbd-o-bahn-client-tester/Cargo.toml index cde62da..a2d29aa 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.4-alpha" +version = "0.0.5-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 84af36f..27b909b 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.4-alpha" +version = "0.0.5-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 257a565..901e409 100644 --- a/rust/sbd-server/Cargo.toml +++ b/rust/sbd-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbd-server" -version = "0.0.4-alpha" +version = "0.0.5-alpha" description = "simple websocket-based message relay server" license = "MIT OR Apache-2.0" repository = "https://github.com/holochain/sbd"