From 82ed88e26ed18ffd00d71202479ff40ecbfe6fc6 Mon Sep 17 00:00:00 2001 From: mfahampshire Date: Fri, 10 Apr 2026 08:01:42 +0000 Subject: [PATCH] Update revs for all tutorials to current release & tweak tutorial (#6659) * Update revs for all tutorials to current release. * Update missed rev * Bump sizes of sent echo messages --- .../docs/components/code-verified.tsx | 4 +- .../developers/rust/client-pool/tutorial.mdx | 8 +-- .../docs/pages/developers/rust/importing.mdx | 2 +- .../pages/developers/rust/mixnet/tutorial.mdx | 6 +- .../pages/developers/rust/stream/tutorial.mdx | 68 ++++++++++--------- .../docs/pages/developers/rust/tcpproxy.mdx | 8 +-- 6 files changed, 50 insertions(+), 46 deletions(-) diff --git a/documentation/docs/components/code-verified.tsx b/documentation/docs/components/code-verified.tsx index b986c21d3d..f3390c6668 100644 --- a/documentation/docs/components/code-verified.tsx +++ b/documentation/docs/components/code-verified.tsx @@ -1,7 +1,7 @@ import { Callout } from "nextra/components"; -const COMMIT_SHORT = "4077717"; -const COMMIT_FULL = "4077717d3"; +const COMMIT_SHORT = "97068b2"; +const COMMIT_FULL = "97068b2aa"; const EXAMPLES_URL = "https://github.com/nymtech/nym/tree/develop/sdk/rust/nym-sdk/examples"; diff --git a/documentation/docs/pages/developers/rust/client-pool/tutorial.mdx b/documentation/docs/pages/developers/rust/client-pool/tutorial.mdx index c0e7f9e9ed..525636c226 100644 --- a/documentation/docs/pages/developers/rust/client-pool/tutorial.mdx +++ b/documentation/docs/pages/developers/rust/client-pool/tutorial.mdx @@ -39,11 +39,11 @@ Add dependencies to `Cargo.toml`: ```toml [dependencies] -nym-sdk = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-network-defaults = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "4077717", features = ["basic_tracing"] } +nym-sdk = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-network-defaults = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "97068b2", features = ["basic_tracing"] } tokio = { version = "1", features = ["full"] } -blake3 = "=1.7.0" # required pin — see https://nymtech.net/developers/rust/importing +blake3 = "=1.7.0" # required pin — see https://nymtech.net/docs/developers/rust/importing ``` ## Step 2: Create and start the pool diff --git a/documentation/docs/pages/developers/rust/importing.mdx b/documentation/docs/pages/developers/rust/importing.mdx index ee0a17426a..dd9c95c976 100644 --- a/documentation/docs/pages/developers/rust/importing.mdx +++ b/documentation/docs/pages/developers/rust/importing.mdx @@ -15,7 +15,7 @@ import { CratesPaused } from '../../../components/crates-paused' ```toml [dependencies] -nym-sdk = { git = "https://github.com/nymtech/nym", rev = "4077717" } +nym-sdk = { git = "https://github.com/nymtech/nym", rev = "97068b2" } blake3 = "=1.7.0" # pin to avoid a transitive dependency conflict — see note below ``` diff --git a/documentation/docs/pages/developers/rust/mixnet/tutorial.mdx b/documentation/docs/pages/developers/rust/mixnet/tutorial.mdx index 94a30cf1a7..0453266998 100644 --- a/documentation/docs/pages/developers/rust/mixnet/tutorial.mdx +++ b/documentation/docs/pages/developers/rust/mixnet/tutorial.mdx @@ -28,10 +28,10 @@ Add dependencies to `Cargo.toml`: ```toml [dependencies] -nym-sdk = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "4077717", features = ["basic_tracing"] } +nym-sdk = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "97068b2", features = ["basic_tracing"] } tokio = { version = "1", features = ["full"] } -blake3 = "=1.7.0" # required pin — see https://nymtech.net/developers/rust/importing +blake3 = "=1.7.0" # required pin — see https://nymtech.net/docs/developers/rust/importing ``` ## Step 2: Connect and send diff --git a/documentation/docs/pages/developers/rust/stream/tutorial.mdx b/documentation/docs/pages/developers/rust/stream/tutorial.mdx index 5ebef6382b..a9ec02f722 100644 --- a/documentation/docs/pages/developers/rust/stream/tutorial.mdx +++ b/documentation/docs/pages/developers/rust/stream/tutorial.mdx @@ -40,10 +40,11 @@ Add dependencies to `Cargo.toml`: ```toml [dependencies] -nym-sdk = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "4077717", features = ["basic_tracing"] } +nym-sdk = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "97068b2", features = ["basic_tracing"] } tokio = { version = "1", features = ["full"] } -blake3 = "=1.7.0" # required pin — see https://nymtech.net/developers/rust/importing +rand = "0.8" +blake3 = "=1.7.0" # required pin — see https://nymtech.net/docs/developers/rust/importing ``` ## Step 2: Build the echo server @@ -83,7 +84,7 @@ async fn main() { // Spawn a task to handle each stream concurrently tokio::spawn(async move { - let mut buf = vec![0u8; 4096]; + let mut buf = vec![0u8; 32_000]; loop { let n = match stream.read(&mut buf).await { @@ -96,11 +97,7 @@ async fn main() { }; let data = &buf[..n]; - println!( - "Stream {stream_id} received {} bytes: {:?}", - n, - String::from_utf8_lossy(data) - ); + println!("Stream {stream_id} received {n} bytes"); // Echo it back if let Err(e) = stream.write_all(data).await { @@ -159,22 +156,26 @@ async fn main() { // the Open, which the server would drop. tokio::time::sleep(Duration::from_secs(5)).await; - // Send three messages and read back the echo for each - for i in 1..=3 { - let msg = format!("message {i}"); - println!("Sending: {msg}"); + // Send three payloads of different sizes and verify the echo. + // Random bytes show that streams are binary-safe — not just text. + let sizes = [320, 25_000, 1280]; - stream.write_all(msg.as_bytes()).await.unwrap(); + for (i, &size) in sizes.iter().enumerate() { + let payload: Vec = (0..size).map(|_| rand::random::()).collect(); + println!("Sending message {} ({size} bytes)", i + 1); + + stream.write_all(&payload).await.unwrap(); stream.flush().await.unwrap(); // Read the echo - let mut buf = vec![0u8; 1024]; + let mut buf = vec![0u8; 32_000]; let n = tokio::time::timeout(TIMEOUT, stream.read(&mut buf)) .await .expect("timed out waiting for echo") .expect("read failed"); - println!("Echo: {}", String::from_utf8_lossy(&buf[..n])); + assert_eq!(&buf[..n], &payload[..], "echo mismatch on message {}", i + 1); + println!("Received echo: {n} bytes ok"); } // Drop the stream to deregister it from the router @@ -211,12 +212,12 @@ You'll see the messages traverse the Mixnet and echo back: ``` Client address: F3qR7...@9nK2m... Stream opened: 12345678 -Sending: message 1 -Echo: message 1 -Sending: message 2 -Echo: message 2 -Sending: message 3 -Echo: message 3 +Sending message 1 (320 bytes) +Received echo: 320 bytes ok +Sending message 2 (25000 bytes) +Received echo: 25000 bytes ok +Sending message 3 (1280 bytes) +Received echo: 1280 bytes ok Done! ``` @@ -224,9 +225,9 @@ On the server side: ``` Accepted stream 12345678 -Stream 12345678 received 9 bytes: "message 1" -Stream 12345678 received 9 bytes: "message 2" -Stream 12345678 received 9 bytes: "message 3" +Stream 12345678 received 320 bytes +Stream 12345678 received 25000 bytes +Stream 12345678 received 1280 bytes Stream 12345678 closed ``` @@ -285,7 +286,7 @@ async fn main() { println!("Accepted stream {stream_id}"); tokio::spawn(async move { - let mut buf = vec![0u8; 4096]; + let mut buf = vec![0u8; 32_000]; loop { let n = match stream.read(&mut buf).await { Ok(0) | Err(_) => break, @@ -330,20 +331,23 @@ async fn main() { // Wait for the Open message to reach the server through the mixnet tokio::time::sleep(Duration::from_secs(5)).await; - for i in 1..=3 { - let msg = format!("message {i}"); - println!("Sending: {msg}"); + let sizes = [320, 25_000, 1280]; - stream.write_all(msg.as_bytes()).await.unwrap(); + for (i, &size) in sizes.iter().enumerate() { + let payload: Vec = (0..size).map(|_| rand::random::()).collect(); + println!("Sending message {} ({size} bytes)", i + 1); + + stream.write_all(&payload).await.unwrap(); stream.flush().await.unwrap(); - let mut buf = vec![0u8; 1024]; + let mut buf = vec![0u8; 32_000]; let n = tokio::time::timeout(TIMEOUT, stream.read(&mut buf)) .await .expect("timed out waiting for echo") .expect("read failed"); - println!("Echo: {}", String::from_utf8_lossy(&buf[..n])); + assert_eq!(&buf[..n], &payload[..], "echo mismatch on message {}", i + 1); + println!("Received echo: {n} bytes ok"); } drop(stream); diff --git a/documentation/docs/pages/developers/rust/tcpproxy.mdx b/documentation/docs/pages/developers/rust/tcpproxy.mdx index af84b9bf07..e25154b474 100644 --- a/documentation/docs/pages/developers/rust/tcpproxy.mdx +++ b/documentation/docs/pages/developers/rust/tcpproxy.mdx @@ -54,12 +54,12 @@ Add dependencies to `Cargo.toml`: ```toml [dependencies] -nym-sdk = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-network-defaults = { git = "https://github.com/nymtech/nym", rev = "4077717" } -nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "4077717", features = ["basic_tracing"] } +nym-sdk = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-network-defaults = { git = "https://github.com/nymtech/nym", rev = "97068b2" } +nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "97068b2", features = ["basic_tracing"] } tokio = { version = "1", features = ["full"] } anyhow = "1" -blake3 = "=1.7.0" # required pin — see https://nymtech.net/developers/rust/importing +blake3 = "=1.7.0" # required pin — see https://nymtech.net/docs/developers/rust/importing [[bin]] name = "proxy_server"