From 8f442005a5febeafef698de5d3af248b716ed73c Mon Sep 17 00:00:00 2001 From: Gusto Date: Wed, 18 Oct 2023 16:14:24 +0300 Subject: [PATCH] Mixnet client address config --- mixnet/client/src/config.rs | 14 +++++++++++--- mixnet/client/src/error.rs | 2 ++ tests/src/nodes/nomos.rs | 4 +++- tests/src/tests/mixnet.rs | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mixnet/client/src/config.rs b/mixnet/client/src/config.rs index 0de2e867..4d42273a 100644 --- a/mixnet/client/src/config.rs +++ b/mixnet/client/src/config.rs @@ -1,4 +1,4 @@ -use std::{net::SocketAddr, time::Duration}; +use std::{net::ToSocketAddrs, time::Duration}; use futures::{stream, StreamExt}; use mixnet_topology::MixnetTopology; @@ -46,7 +46,7 @@ impl MixnetClientConfig { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub enum MixnetClientMode { Sender, - SenderReceiver(SocketAddr), + SenderReceiver(String), } impl MixnetClientMode { @@ -54,7 +54,15 @@ impl MixnetClientMode { match self { Self::Sender => Ok(stream::empty().boxed()), Self::SenderReceiver(node_address) => { - Ok(Receiver::new(*node_address).run().await?.boxed()) + let mut addrs = node_address + .to_socket_addrs() + .map_err(|e| MixnetClientError::MixnetNodeAddressError(e.to_string()))?; + let socket_addr = addrs + .next() + .ok_or(MixnetClientError::MixnetNodeAddressError( + "No address provided".into(), + ))?; + Ok(Receiver::new(socket_addr).run().await?.boxed()) } } } diff --git a/mixnet/client/src/error.rs b/mixnet/client/src/error.rs index caaae8a8..302363c6 100644 --- a/mixnet/client/src/error.rs +++ b/mixnet/client/src/error.rs @@ -3,6 +3,8 @@ use nym_sphinx::addressing::nodes::NymNodeRoutingAddressError; #[derive(thiserror::Error, Debug)] pub enum MixnetClientError { + #[error("invalid node address: {0}")] + MixnetNodeAddressError(String), #[error("mixnet node connect error")] MixnetNodeConnectError, #[error("mixnode stream has been closed")] diff --git a/tests/src/nodes/nomos.rs b/tests/src/nodes/nomos.rs index 2eb604eb..8d1de83a 100644 --- a/tests/src/nodes/nomos.rs +++ b/tests/src/nodes/nomos.rs @@ -248,7 +248,9 @@ fn create_node_config( mixnet_topology: MixnetTopology, ) -> Config { let mixnet_client_mode = match mixnet_node_config { - Some(node_config) => MixnetClientMode::SenderReceiver(node_config.client_listen_address), + Some(node_config) => { + MixnetClientMode::SenderReceiver(node_config.client_listen_address.to_string()) + } None => MixnetClientMode::Sender, }; diff --git a/tests/src/tests/mixnet.rs b/tests/src/tests/mixnet.rs index 965c6cc0..53a0f1f5 100644 --- a/tests/src/tests/mixnet.rs +++ b/tests/src/tests/mixnet.rs @@ -125,7 +125,7 @@ async fn run_nodes_and_destination_client() -> ( // one of mixnodes the exit layer always will be selected as a destination. let client = MixnetClient::new( MixnetClientConfig { - mode: MixnetClientMode::SenderReceiver(config3.client_listen_address), + mode: MixnetClientMode::SenderReceiver(config3.client_listen_address.to_string()), topology: topology.clone(), connection_pool_size: 255, max_retries: 3,