Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting the gateway randomly from 2 known good ones. #355

Merged
merged 3 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions clients/native/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ use directory_client::DirectoryClient;
use gateway_client::GatewayClient;
use gateway_requests::registration::handshake::SharedKeys;
use rand::rngs::OsRng;
use rand::seq::SliceRandom;
use std::convert::TryInto;
use std::sync::Arc;
use std::time::Duration;
use topology::{gateway, NymTopology};

const GOOD_GATEWAYS: [&str; 2] = [
"D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr",
"5nrYxPR8gt2Gzo2BbHtsGf66KAEQY91WmM1eW78EphNy",
];

pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("init")
.about("Initialise a Nym client. Do this first!")
Expand All @@ -40,9 +46,8 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
)
.arg(Arg::with_name("gateway")
.long("gateway")
.help("Id of the gateway we are going to connect to. If unsure what to put here - 'D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr' is a safe choice for the testnet")
.help("Id of the gateway we are going to connect to.")
.takes_value(true)
.required(true)
)
.arg(Arg::with_name("directory")
.long("directory")
Expand Down Expand Up @@ -102,13 +107,25 @@ async fn gateway_details(directory_server: &str, gateway_id: &str) -> gateway::N
.clone()
}

fn select_gateway(arg: Option<&str>) -> &str {
if let Some(gateway_id) = arg {
gateway_id
} else {
// TODO1: this should only be done on testnet
// TODO2: it should probably check if chosen gateway is actually online
GOOD_GATEWAYS.choose(&mut rand::thread_rng()).unwrap()
}
}

pub fn execute(matches: &ArgMatches) {
println!("Initialising client...");

let id = matches.value_of("id").unwrap(); // required for now
let mut config = Config::new(id);
let mut rng = OsRng;

// TODO: ideally that should be the last thing that's being done to config.
// However, we are later further overriding it with gateway id
config = override_config(config, matches);
if matches.is_present("fastmode") {
config.get_base_mut().set_high_default_traffic_volume();
Expand All @@ -117,7 +134,8 @@ pub fn execute(matches: &ArgMatches) {
// create identity, encryption and ack keys.
let mut key_manager = KeyManager::new(&mut rng);

let gateway_id = matches.value_of("gateway").unwrap();
let gateway_id = select_gateway(matches.value_of("gateway"));
config.get_base_mut().with_gateway_id(gateway_id);

let registration_fut = async {
let gate_details =
Expand Down Expand Up @@ -146,11 +164,6 @@ pub fn execute(matches: &ArgMatches) {
.save_to_file(None)
.expect("Failed to save the config file");
println!("Saved configuration file to {:?}", config_save_location);

println!(
"Unless overridden in all `nym-client run` we will be talking to the following gateway: {}...",
config.get_base().get_gateway_id(),
);

println!("Using gateway: {}", config.get_base().get_gateway_id(),);
println!("Client configuration completed.\n\n\n")
}
1 change: 0 additions & 1 deletion clients/native/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fn main() {
dotenv::dotenv().ok();
setup_logging();
println!("{}", banner());
println!("\n\nIf unsure which gateway to choose - 'D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr' is a safe choice for the testnet\n\n");

let arg_matches = App::new("Nym Client")
.version(built_info::PKG_VERSION)
Expand Down
32 changes: 22 additions & 10 deletions clients/socks5/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ use crypto::asymmetric::identity;
use directory_client::DirectoryClient;
use gateway_client::GatewayClient;
use gateway_requests::registration::handshake::SharedKeys;
use rand::rngs::OsRng;
use rand::{prelude::SliceRandom, rngs::OsRng};
use std::convert::TryInto;
use std::sync::Arc;
use std::time::Duration;
use topology::{gateway, NymTopology};

const GOOD_GATEWAYS: [&str; 2] = [
"D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr",
"5nrYxPR8gt2Gzo2BbHtsGf66KAEQY91WmM1eW78EphNy",
];

pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("init")
.about("Initialise a Nym client. Do this first!")
Expand All @@ -46,9 +51,8 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
)
.arg(Arg::with_name("gateway")
.long("gateway")
.help("Id of the gateway we are going to connect to. If unsure what to put here - 'D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr' is a safe choice for the testnet")
.help("Id of the gateway we are going to connect to.")
.takes_value(true)
.required(true)
)
.arg(Arg::with_name("directory")
.long("directory")
Expand Down Expand Up @@ -104,6 +108,16 @@ async fn gateway_details(directory_server: &str, gateway_id: &str) -> gateway::N
.clone()
}

fn select_gateway(arg: Option<&str>) -> &str {
if let Some(gateway_id) = arg {
gateway_id
} else {
// TODO1: this should only be done on testnet
// TODO2: it should probably check if chosen gateway is actually online
GOOD_GATEWAYS.choose(&mut rand::thread_rng()).unwrap()
}
}

pub fn execute(matches: &ArgMatches) {
println!("Initialising client...");

Expand All @@ -113,6 +127,8 @@ pub fn execute(matches: &ArgMatches) {
let mut config = Config::new(id, provider_address);
let mut rng = OsRng;

// TODO: ideally that should be the last thing that's being done to config.
// However, we are later further overriding it with gateway id
config = override_config(config, matches);
if matches.is_present("fastmode") {
config.get_base_mut().set_high_default_traffic_volume();
Expand All @@ -121,7 +137,8 @@ pub fn execute(matches: &ArgMatches) {
// create identity, encryption and ack keys.
let mut key_manager = KeyManager::new(&mut rng);

let gateway_id = matches.value_of("gateway").unwrap();
let gateway_id = select_gateway(matches.value_of("gateway"));
config.get_base_mut().with_gateway_id(gateway_id);

let registration_fut = async {
let gate_details =
Expand Down Expand Up @@ -150,11 +167,6 @@ pub fn execute(matches: &ArgMatches) {
.save_to_file(None)
.expect("Failed to save the config file");
println!("Saved configuration file to {:?}", config_save_location);

println!(
"Unless overridden in all `nym-socks5-client run` we will be talking to the following gateway: {}...",
config.get_base().get_gateway_id(),
);

println!("Using gateway: {}", config.get_base().get_gateway_id(),);
println!("Client configuration completed.\n\n\n")
}
1 change: 0 additions & 1 deletion clients/socks5/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fn main() {
dotenv::dotenv().ok();
setup_logging();
println!("{}", banner());
println!("\n\nIf unsure which gateway to choose - 'D6YaMzLSY7mANtSQRKXsmMZpqgqiVkeiagKM4V4oFPFr' is a safe choice for the testnet\n\n");

let arg_matches = App::new("Nym Socks5 Proxy")
.version(built_info::PKG_VERSION)
Expand Down