change surb_reply to test relation with nym-node + basic instrumentation

This commit is contained in:
Floriane TUERNAL SABOTINOV
2025-08-29 12:25:26 +02:00
parent f56edf63b5
commit fee2ae5964
4 changed files with 37 additions and 14 deletions
@@ -475,6 +475,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<x25519::KeyPair>,
query_receiver: ReceivedBufferRequestReceiver,
@@ -507,6 +508,7 @@ where
}
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
async fn start_gateway_client(
config: &Config,
initialisation_result: InitialisationResult,
@@ -613,6 +615,7 @@ where
}
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
async fn setup_gateway_transceiver(
custom_gateway_transceiver: Option<Box<dyn GatewayTransceiver + Send>>,
config: &Config,
@@ -770,7 +773,7 @@ where
shutdown_tracker,
)
}
#[instrument(skip_all)]
fn start_mix_traffic_controller(
gateway_transceiver: Box<dyn GatewayTransceiver + Send>,
shutdown_tracker: &ShutdownTracker,
@@ -887,6 +890,7 @@ where
Ok(client.get_key_rotation_info().await?.into())
}
#[instrument(skip_all)]
pub async fn start_base(mut self) -> Result<BaseClient, ClientCoreError>
where
S::ReplyStore: Send + Sync,
@@ -1043,6 +1043,12 @@ impl<C, St> GatewayClient<C, St> {
}
// 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);
+22 -13
View File
@@ -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.
+4
View File
@@ -38,6 +38,8 @@ use std::path::Path;
use std::path::PathBuf;
#[cfg(unix)]
use std::sync::Arc;
use tokio_util::sync::CancellationToken;
use tracing::instrument;
use url::Url;
use zeroize::Zeroizing;
@@ -694,6 +696,7 @@ where
BandwidthImporter::new(self.storage.credential_store())
}
#[instrument(skip_all)]
async fn connect_to_mixnet_common(mut self) -> Result<(BaseClient, Recipient)> {
self.setup_client_keys().await?;
self.setup_gateway().await?;
@@ -826,6 +829,7 @@ where
/// let client = client.connect_to_mixnet().await.unwrap();
/// }
/// ```
#[instrument(skip_all)]
pub async fn connect_to_mixnet(self) -> Result<MixnetClient> {
if self.socks5_config.is_some() {
return Err(Error::Socks5Config { set: true });