Mixnet client address config
This commit is contained in:
parent
56b2830d5a
commit
8f442005a5
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")]
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user