diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 08be8de478..d2da563ec0 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -122,7 +122,7 @@ pub struct NymClient { // to be used by "send" function or socket, etc input_rx: mpsc::UnboundedReceiver, socket_listening_address: SocketAddr, - is_local: bool, + directory: String, auth_token: Option, socket_type: SocketType, } @@ -134,7 +134,7 @@ impl NymClient { pub fn new( address: DestinationAddressBytes, socket_listening_address: SocketAddr, - is_local: bool, + directory: String, auth_token: Option, socket_type: SocketType, ) -> Self { @@ -145,7 +145,7 @@ impl NymClient { input_tx, input_rx, socket_listening_address, - is_local, + directory, auth_token, socket_type, } @@ -222,7 +222,7 @@ impl NymClient { println!("Starting nym client"); let mut rt = Runtime::new()?; - let topology = get_topology(self.is_local); + let topology = get_topology(self.directory.clone()); // this is temporary and assumes there exists only a single provider. let provider_address: SocketAddr = topology .mix_provider_nodes diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index 8c160a5ee0..d609f00d1b 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -9,13 +9,17 @@ use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - let is_local = matches.is_present("local"); let id = matches.value_of("id").unwrap().to_string(); let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; + let directory_server = matches + .value_of("directory") + .unwrap_or("https://directory.nymtech.net") + .to_string(); + println!("Starting TCP socket on port: {:?}", port); println!("Listening for messages..."); @@ -31,7 +35,7 @@ pub fn execute(matches: &ArgMatches) { let client = NymClient::new( keypair.public_bytes(), socket_address.clone(), - is_local, + directory_server, auth_token, SocketType::TCP, ); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 913417c31e..1b8ccd69b2 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -8,13 +8,17 @@ use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - let is_local = matches.is_present("local"); let id = matches.value_of("id").unwrap().to_string(); let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; + let directory_server = matches + .value_of("directory") + .unwrap_or("https://directory.nymtech.net") + .to_string(); + println!("Starting websocket on port: {:?}", port); println!("Listening for messages..."); @@ -30,7 +34,7 @@ pub fn execute(matches: &ArgMatches) { let client = NymClient::new( keypair.public_bytes(), socket_address, - is_local, + directory_server, auth_token, SocketType::WebSocket, ); diff --git a/src/main.rs b/src/main.rs index a753b97a82..6d73a64713 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,10 +37,11 @@ fn main() { .takes_value(true) .required(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) ) .subcommand( @@ -54,10 +55,11 @@ fn main() { .takes_value(true) .required(true), ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) .arg(Arg::with_name("id") .long("id") @@ -76,10 +78,11 @@ fn main() { .help("Port for websocket to listen on") .takes_value(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) .arg(Arg::with_name("id") .long("id") diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 08eb1ab5e1..5e11de7aa7 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -5,22 +5,16 @@ use crate::clients::directory::requests::presence_topology_get::PresenceTopology use crate::clients::directory::DirectoryClient; use crate::utils::{addressing, bytes}; use curve25519_dalek::montgomery::MontgomeryPoint; -use futures::AsyncReadExt; use rand::seq::SliceRandom; use sphinx::route::Node as SphinxNode; use std::collections::HashMap; -use std::convert::TryFrom; -use std::net::{IpAddr, SocketAddr}; -use std::string::ToString; +use std::net::SocketAddr; -pub(crate) fn get_topology(is_local: bool) -> Topology { - let url = if is_local { - "http://localhost:8080".to_string() - } else { - "https://directory.nymtech.net".to_string() +pub(crate) fn get_topology(directory_server: String) -> Topology { + println!("Using directory server: {:?}", directory_server); + let directory_config = directory::Config { + base_url: directory_server, }; - println!("Using directory server: {:?}", url); - let directory_config = directory::Config { base_url: url }; let directory = directory::Client::new(directory_config); let topology = directory