diff --git a/Cargo.lock b/Cargo.lock index ad14550e51..40b9b6c096 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1808,7 +1808,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "0.10.1" +version = "0.10.2" dependencies = [ "bs58 0.4.0", "clap", diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index bf1ba20d10..d6da5489e8 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-mixnode" -version = "0.10.1" +version = "0.10.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/mixnode/src/commands/describe.rs b/mixnode/src/commands/describe.rs index 2c5494907b..efccf0831d 100644 --- a/mixnode/src/commands/describe.rs +++ b/mixnode/src/commands/describe.rs @@ -48,6 +48,7 @@ pub fn execute(matches: &ArgMatches) { let description = desc_buf.trim().to_string(); let example_url = "https://mixnode.yourdomain.com".bright_cyan(); + let example_location = "City: YourCity, Country: YourCountry"; print!("link, e.g. {}: ", example_url); io::stdout().flush().unwrap(); @@ -55,10 +56,17 @@ pub fn execute(matches: &ArgMatches) { io::stdin().read_line(&mut link_buf).unwrap(); let link = link_buf.trim().to_string(); + print!("location, e.g. {}: ", example_location); + io::stdout().flush().unwrap(); + let mut location_buf = String::new(); + io::stdin().read_line(&mut location_buf).unwrap(); + let location = location_buf.trim().to_string(); + let node_description = NodeDescription { name, description, link, + location, }; // save the struct diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index 4edba5ecd0..53b13aed16 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -133,7 +133,6 @@ fn show_bonding_info(config: &Config) { Address: {} Mix port: {} Layer: {} - Location: [physical location of your node's server] Version: {} ", identity_keypair.public_key().to_base58_string(), diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index be4fd76355..ed1a0f264e 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -140,6 +140,9 @@ pub fn execute(matches: &ArgMatches) { show_binding_warning(config.get_listening_address().to_string()); } + let description = + NodeDescription::load_from_file(Config::default_config_directory(id)).unwrap_or_default(); + println!( "Validator servers: {:?}", config.get_validator_rest_endpoints() @@ -160,7 +163,7 @@ pub fn execute(matches: &ArgMatches) { Address: {} Mix port: {} Layer: {} - Location: [physical location of your node's server] + Location: {} Version: {} ", identity_keypair.public_key().to_base58_string(), @@ -168,10 +171,8 @@ pub fn execute(matches: &ArgMatches) { config.get_announce_address(), config.get_mix_port(), config.get_layer(), + description.location, config.get_version(), ); - - let description = - NodeDescription::load_from_file(Config::default_config_directory(id)).unwrap_or_default(); MixNode::new(config, description, identity_keypair, sphinx_keypair).run(); } diff --git a/mixnode/src/commands/upgrade.rs b/mixnode/src/commands/upgrade.rs index 7c572dcfd4..1317c924ab 100644 --- a/mixnode/src/commands/upgrade.rs +++ b/mixnode/src/commands/upgrade.rs @@ -6,14 +6,16 @@ use crate::config::{ default_validator_rest_endpoints, missing_string_value, Config, DEFAULT_MIXNET_CONTRACT_ADDRESS, MISSING_VALUE, }; +use crate::node::node_description::{NodeDescription, DESCRIPTION_FILE}; use clap::{App, Arg, ArgMatches}; use config::NymConfig; use crypto::asymmetric::identity; +use serde::Deserialize; use std::fmt::Display; use std::net::SocketAddr; use std::path::PathBuf; -use std::process; use std::str::FromStr; +use std::{fs, process}; use version_checker::{parse_version, Version}; const CURRENT_VERSION_ARG_NAME: &str = "current-version"; @@ -313,6 +315,75 @@ fn undetermined_version_upgrade( Ok(upgraded_config) } +fn patch_0_10_2_upgrade( + config: Config, + _matches: &ArgMatches, + config_version: &Version, + package_version: &Version, +) -> Result { + #[derive(Deserialize)] + struct OldNodeDescription { + name: String, + description: String, + link: String, + } + let to_version = package_version; + let id = config.get_id(); + let config_path = Config::default_config_directory(&id); + + print_start_upgrade(&config_version, &to_version); + + let upgraded_config = config.with_custom_version(to_version.to_string().as_ref()); + + upgraded_config.save_to_file(None).map_err(|err| { + ( + to_version.clone(), + format!("failed to overwrite config file! - {:?}", err), + ) + })?; + + let description_file_path: PathBuf = [config_path.to_str().unwrap(), DESCRIPTION_FILE] + .iter() + .collect(); + // If the description file already exists, upgrade it + if description_file_path.is_file() { + let description_content = + fs::read_to_string(description_file_path.clone()).map_err(|err| { + ( + to_version.clone(), + format!("failed to read description file! - {:?}", err), + ) + })?; + let old_description: OldNodeDescription = + toml::from_str(&description_content).map_err(|err| { + ( + to_version.clone(), + format!("failed to deserialize description content! - {:?}", err), + ) + })?; + let mut new_description = NodeDescription::default(); + new_description.name = old_description.name; + new_description.description = old_description.description; + new_description.link = old_description.link; + let description_toml = toml::to_string(&new_description).map_err(|err| { + ( + to_version.clone(), + format!("failed to serialize description content! - {:?}", err), + ) + })?; + fs::write(description_file_path, description_toml).map_err(|err| { + ( + to_version.clone(), + format!("failed to overwrite description file! - {:?}", err), + ) + })?; + } + + print_successful_upgrade(config_version, to_version); + + Ok(upgraded_config) +} + fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version) { loop { let config_version = parse_config_version(&config); @@ -327,6 +398,7 @@ fn do_upgrade(mut config: Config, matches: &ArgMatches, package_version: Version 9 => minor_0_10_upgrade(config, matches, &config_version, &package_version), 10 => match config_version.patch { 0 => patch_0_10_1_upgrade(config, matches, &config_version, &package_version), + 1 => patch_0_10_2_upgrade(config, matches, &config_version, &package_version), _ => undetermined_version_upgrade( config, matches, diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index d3240c975c..7b8320ae4f 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -284,6 +284,10 @@ impl Config { &self.mixnode.version } + pub fn get_id(&self) -> String { + self.mixnode.id.clone() + } + pub fn get_measurement_packets_per_node(&self) -> usize { self.verloc.packets_per_node } diff --git a/mixnode/src/node/node_description.rs b/mixnode/src/node/node_description.rs index fdc6f1072f..cb22cdce59 100644 --- a/mixnode/src/node/node_description.rs +++ b/mixnode/src/node/node_description.rs @@ -10,6 +10,7 @@ pub struct NodeDescription { pub(crate) name: String, pub(crate) description: String, pub(crate) link: String, + pub(crate) location: String, } impl Default for NodeDescription { @@ -18,6 +19,7 @@ impl Default for NodeDescription { name: "This node has not yet set a name".to_string(), description: "This node has not yet set a description".to_string(), link: "https://nymtech.net".to_string(), + location: "This node has not yet set a location".to_string(), } } }