From c9aed048d08355c689b282c2ebc6211139ae4adf Mon Sep 17 00:00:00 2001 From: Floriane TUERNAL SABOTINOV Date: Fri, 29 Aug 2025 12:25:26 +0200 Subject: [PATCH] change surb_reply to test relation with nym-node + basic instrumentation --- .../client-core/src/client/base_client/mod.rs | 6 +++- .../gateway-client/src/client/mod.rs | 6 ++++ sdk/rust/nym-sdk/examples/surb_reply.rs | 35 ++++++++++++------- sdk/rust/nym-sdk/src/mixnet/client.rs | 3 ++ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/common/client-core/src/client/base_client/mod.rs b/common/client-core/src/client/base_client/mod.rs index 2a3e30bf64..badd44beaf 100644 --- a/common/client-core/src/client/base_client/mod.rs +++ b/common/client-core/src/client/base_client/mod.rs @@ -433,6 +433,7 @@ where // buffer controlling all messages fetched from provider // required so that other components would be able to use them (say the websocket) + #[instrument(skip_all)] fn start_received_messages_buffer_controller( local_encryption_keypair: Arc, query_receiver: ReceivedBufferRequestReceiver, @@ -465,6 +466,7 @@ where } #[allow(clippy::too_many_arguments)] + #[instrument(skip_all)] async fn start_gateway_client( config: &Config, initialisation_result: InitialisationResult, @@ -571,6 +573,7 @@ where } #[allow(clippy::too_many_arguments)] + #[instrument(skip_all)] async fn setup_gateway_transceiver( custom_gateway_transceiver: Option>, config: &Config, @@ -728,7 +731,7 @@ where shutdown_tracker, ) } - + #[instrument(skip_all)] fn start_mix_traffic_controller( gateway_transceiver: Box, shutdown_tracker: &ShutdownTracker, @@ -838,6 +841,7 @@ where Ok(client.get_key_rotation_info().await?.into()) } + #[instrument(skip_all)] pub async fn start_base(mut self) -> Result where S::ReplyStore: Send + Sync, diff --git a/common/client-libs/gateway-client/src/client/mod.rs b/common/client-libs/gateway-client/src/client/mod.rs index 52e5833eb2..3cb4eee3e0 100644 --- a/common/client-libs/gateway-client/src/client/mod.rs +++ b/common/client-libs/gateway-client/src/client/mod.rs @@ -1043,6 +1043,12 @@ impl GatewayClient { } // Note: this requires prior authentication + #[instrument(skip_all, + fields( + gateway = %self.gateway_identity, + gateway_address = %self.gateway_address + ) + )] pub fn start_listening_for_mixnet_messages(&mut self) -> Result<(), GatewayClientError> { if !self.authenticated { return Err(GatewayClientError::NotAuthenticated); diff --git a/sdk/rust/nym-sdk/examples/surb_reply.rs b/sdk/rust/nym-sdk/examples/surb_reply.rs index 02f183b3a6..f0c3858ccd 100644 --- a/sdk/rust/nym-sdk/examples/surb_reply.rs +++ b/sdk/rust/nym-sdk/examples/surb_reply.rs @@ -1,28 +1,38 @@ use nym_sdk::mixnet::{ AnonymousSenderTag, MixnetClientBuilder, MixnetMessageSender, ReconstructedMessage, - StoragePaths, + // StoragePaths, }; -use std::path::PathBuf; -use tempfile::TempDir; +use tracing::instrument; +// use std::path::PathBuf; +// use tempfile::TempDir; #[tokio::main] +#[instrument(name = "sdk-example-surb-reply", skip_all)] async fn main() { nym_bin_common::opentelemetry::setup_tracing_logger("sdk-example-surb-reply".to_string()).unwrap(); - // Specify some config options - let config_dir: PathBuf = TempDir::new().unwrap().path().to_path_buf(); - let storage_paths = StoragePaths::new_from_dir(&config_dir).unwrap(); + // // Specify some config options + // let config_dir: PathBuf = TempDir::new().unwrap().path().to_path_buf(); + // let storage_paths = StoragePaths::new_from_dir(&config_dir).unwrap(); // Create the client with a storage backend, and enable it by giving it some paths. If keys // exists at these paths, they will be loaded, otherwise they will be generated. - let client = MixnetClientBuilder::new_with_default_storage(storage_paths) - .await - .unwrap() + // let client = MixnetClientBuilder::new_with_default_storage(storage_paths) + // .await + // .unwrap() + // .build() + // .unwrap(); + let client_builder = MixnetClientBuilder::new_ephemeral(); + let mixnet_client = client_builder + .request_gateway("BAF2aYpzcK9KbSS3Y7EdLisxiogkTr88FXkdL8EDNigH".to_string()) + .with_ignore_epoch_roles(true) + .with_extended_topology(true) .build() .unwrap(); + let mut client = mixnet_client.connect_to_mixnet().await.unwrap(); // Now we connect to the mixnet, using keys now stored in the paths provided. - let mut client = client.connect_to_mixnet().await.unwrap(); + // let mut client = client.connect_to_mixnet().await.unwrap(); // Be able to get our client address let our_address = client.nym_address(); @@ -30,9 +40,8 @@ async fn main() { // Send a message through the mixnet to ourselves using our nym address client - .send_plain_message(*our_address, "hello there") - .await - .unwrap(); + .on_messages(|msg| println!("Received: {}", String::from_utf8_lossy(&msg.message))) + .await; // we're going to parse the sender_tag (AnonymousSenderTag) from the incoming message and use it to 'reply' to ourselves instead of our Nym address. // we know there will be a sender_tag since the sdk sends SURBs along with messages by default. diff --git a/sdk/rust/nym-sdk/src/mixnet/client.rs b/sdk/rust/nym-sdk/src/mixnet/client.rs index bee2b086e3..8bcf88f026 100644 --- a/sdk/rust/nym-sdk/src/mixnet/client.rs +++ b/sdk/rust/nym-sdk/src/mixnet/client.rs @@ -38,6 +38,7 @@ use std::path::PathBuf; #[cfg(unix)] use std::sync::Arc; use tokio_util::sync::CancellationToken; +use tracing::instrument; use url::Url; use zeroize::Zeroizing; @@ -665,6 +666,7 @@ where ) } + #[instrument(skip_all)] async fn connect_to_mixnet_common(mut self) -> Result<(BaseClient, Recipient)> { self.setup_client_keys().await?; self.setup_gateway().await?; @@ -801,6 +803,7 @@ where /// let client = client.connect_to_mixnet().await.unwrap(); /// } /// ``` + #[instrument(skip_all)] pub async fn connect_to_mixnet(self) -> Result { if self.socks5_config.is_some() { return Err(Error::Socks5Config { set: true });