diff --git a/clients/native/src/client/config/mod.rs b/clients/native/src/client/config/mod.rs index 95fb58acf0..ae586ad217 100644 --- a/clients/native/src/client/config/mod.rs +++ b/clients/native/src/client/config/mod.rs @@ -1,9 +1,9 @@ // Copyright 2021-2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::client::config::persistence::ClientPaths; use crate::client::config::template::CONFIG_TEMPLATE; use nym_bin_common::logging::LoggingSettings; -use nym_client_core::config::disk_persistence::CommonClientPaths; use nym_config::defaults::DEFAULT_WEBSOCKET_LISTENING_PORT; use nym_config::{ must_get_home, read_config_from_toml_file, save_formatted_config_to_file, NymConfigTemplate, @@ -16,7 +16,6 @@ use std::net::{IpAddr, Ipv4Addr}; use std::path::{Path, PathBuf}; use std::str::FromStr; -use crate::client::config::persistence::ClientPaths; pub use nym_client_core::config::Config as BaseClientConfig; pub use nym_client_core::config::{DebugConfig, GatewayEndpointConfig}; diff --git a/clients/native/src/client/config/old_config_v1_1_13.rs b/clients/native/src/client/config/old_config_v1_1_13.rs index d0f3da819b..c4dd107b2d 100644 --- a/clients/native/src/client/config/old_config_v1_1_13.rs +++ b/clients/native/src/client/config/old_config_v1_1_13.rs @@ -1,60 +1,35 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use crate::client::config::{Config, Socket}; +use crate::client::config::old_config_v1_1_19::{ConfigV1_1_19, SocketV1_1_19}; use nym_client_core::config::old_config_v1_1_13::OldConfigV1_1_13 as OldBaseConfigV1_1_13; +use nym_config::legacy_helpers::nym_config::MigrationNymConfig; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -#[derive(Debug, Default, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct OldConfigV1_1_13 { #[serde(flatten)] - base: OldBaseConfigV1_1_13, + pub base: OldBaseConfigV1_1_13, - socket: Socket, + pub socket: SocketV1_1_19, } -// impl NymConfig for OldConfigV1_1_13 { -// fn template() -> &'static str { -// // not intended to be used -// unimplemented!() -// } -// -// fn default_root_directory() -> PathBuf { -// dirs::home_dir() -// .expect("Failed to evaluate $HOME value") -// .join(".nym") -// .join("clients") -// } -// -// fn try_default_root_directory() -> Option { -// dirs::home_dir().map(|path| path.join(".nym").join("clients")) -// } -// -// fn root_directory(&self) -> PathBuf { -// self.base.client.nym_root_directory.clone() -// } -// -// fn config_directory(&self) -> PathBuf { -// self.root_directory() -// .join(&self.base.client.id) -// .join("config") -// } -// -// fn data_directory(&self) -> PathBuf { -// self.root_directory() -// .join(&self.base.client.id) -// .join("data") -// } -// } - -impl From for Config { - fn from(value: OldConfigV1_1_13) -> Self { - todo!() - // Config { - // base: value.base.into(), - // socket: value.socket, - // } +impl MigrationNymConfig for OldConfigV1_1_13 { + fn default_root_directory() -> PathBuf { + dirs::home_dir() + .expect("Failed to evaluate $HOME value") + .join(".nym") + .join("clients") + } +} + +impl From for ConfigV1_1_19 { + fn from(value: OldConfigV1_1_13) -> Self { + ConfigV1_1_19 { + base: value.base.into(), + socket: value.socket, + } } } diff --git a/clients/native/src/client/config/old_config_v1_1_19.rs b/clients/native/src/client/config/old_config_v1_1_19.rs index 38dc36ebc3..04aa4be274 100644 --- a/clients/native/src/client/config/old_config_v1_1_19.rs +++ b/clients/native/src/client/config/old_config_v1_1_19.rs @@ -1,2 +1,112 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 + +use crate::client::config::persistence::ClientPaths; +use crate::client::config::{Config, Socket, SocketType}; +use nym_bin_common::logging::LoggingSettings; +use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths; +use nym_client_core::config::disk_persistence::CommonClientPaths; +use nym_client_core::config::old_config_v1_1_19::ConfigV1_1_19 as BaseConfigV1_1_19; +use nym_client_core::config::{Client, Config as BaseConfig}; +use nym_config::defaults::DEFAULT_WEBSOCKET_LISTENING_PORT; +use nym_config::legacy_helpers::nym_config::MigrationNymConfig; +use serde::{Deserialize, Serialize}; +use std::fmt::Debug; +use std::net::{IpAddr, Ipv4Addr}; +use std::path::PathBuf; + +#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone, Copy)] +#[serde(deny_unknown_fields)] +pub enum SocketTypeV1_1_19 { + WebSocket, + None, +} + +impl From for SocketType { + fn from(value: SocketTypeV1_1_19) -> Self { + match value { + SocketTypeV1_1_19::WebSocket => SocketType::WebSocket, + SocketTypeV1_1_19::None => SocketType::None, + } + } +} + +#[derive(Debug, Deserialize, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct ConfigV1_1_19 { + #[serde(flatten)] + pub base: BaseConfigV1_1_19, + + pub socket: SocketV1_1_19, +} + +impl From for Config { + fn from(value: ConfigV1_1_19) -> Self { + Config { + base: BaseConfig { + client: Client { + version: value.base.client.version, + id: value.base.client.id, + disabled_credentials_mode: value.base.client.disabled_credentials_mode, + nyxd_urls: value.base.client.nyxd_urls, + nym_api_urls: value.base.client.nym_api_urls, + gateway_endpoint: value.base.client.gateway_endpoint.into(), + }, + debug: value.base.debug.into(), + }, + socket: value.socket.into(), + storage_paths: ClientPaths { + common_paths: CommonClientPaths { + keys: ClientKeysPaths { + private_identity_key_file: value.base.client.private_identity_key_file, + public_identity_key_file: value.base.client.public_identity_key_file, + private_encryption_key_file: value.base.client.private_encryption_key_file, + public_encryption_key_file: value.base.client.public_encryption_key_file, + gateway_shared_key_file: value.base.client.gateway_shared_key_file, + ack_key_file: value.base.client.ack_key_file, + }, + credentials_database: value.base.client.database_path, + reply_surb_database: value.base.client.reply_surb_database_path, + }, + }, + logging: LoggingSettings::default(), + } + } +} + +impl MigrationNymConfig for ConfigV1_1_19 { + fn default_root_directory() -> PathBuf { + dirs::home_dir() + .expect("Failed to evaluate $HOME value") + .join(".nym") + .join("clients") + } +} + +#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct SocketV1_1_19 { + socket_type: SocketTypeV1_1_19, + host: IpAddr, + listening_port: u16, +} + +impl From for Socket { + fn from(value: SocketV1_1_19) -> Self { + Socket { + socket_type: value.socket_type.into(), + host: value.host, + listening_port: value.listening_port, + } + } +} + +impl Default for SocketV1_1_19 { + fn default() -> Self { + SocketV1_1_19 { + socket_type: SocketTypeV1_1_19::WebSocket, + host: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), + listening_port: DEFAULT_WEBSOCKET_LISTENING_PORT, + } + } +} diff --git a/clients/native/src/client/config/template.rs b/clients/native/src/client/config/template.rs index 86cb249dc2..24a7c29374 100644 --- a/clients/native/src/client/config/template.rs +++ b/clients/native/src/client/config/template.rs @@ -36,39 +36,35 @@ nym_api_urls = [ {{/each}} ] +[storage_paths] + # Path to file containing private identity key. -private_identity_key_file = '{{ client.private_identity_key_file }}' +keys.private_identity_key_file = '{{ storage_paths.keys.private_identity_key_file }}' # Path to file containing public identity key. -public_identity_key_file = '{{ client.public_identity_key_file }}' +keys.public_identity_key_file = '{{ storage_paths.keys.public_identity_key_file }}' # Path to file containing private encryption key. -private_encryption_key_file = '{{ client.private_encryption_key_file }}' +keys.private_encryption_key_file = '{{ storage_paths.keys.private_encryption_key_file }}' # Path to file containing public encryption key. -public_encryption_key_file = '{{ client.public_encryption_key_file }}' - -# Path to the database containing bandwidth credentials -database_path = '{{ client.database_path }}' - -# Path to the persistent store for received reply surbs, unused encryption keys and used sender tags. -reply_surb_database_path = '{{ client.reply_surb_database_path }}' - -##### additional client config options ##### +keys.public_encryption_key_file = '{{ storage_paths.keys.public_encryption_key_file }}' # A gateway specific, optional, base58 stringified shared key used for # communication with particular gateway. -gateway_shared_key_file = '{{ client.gateway_shared_key_file }}' +keys.gateway_shared_key_file = '{{ storage_paths.keys.gateway_shared_key_file }}' # Path to file containing key used for encrypting and decrypting the content of an # acknowledgement so that nobody besides the client knows which packet it refers to. -ack_key_file = '{{ client.ack_key_file }}' - -##### advanced configuration options ##### +keys.ack_key_file = '{{ storage_paths.keys.ack_key_file }}' -# Absolute path to the home Nym Clients directory. -nym_root_directory = '{{ client.nym_root_directory }}' +# Path to the database containing bandwidth credentials +credentials_database = '{{ storage_paths.credentials_database }}' +# Path to the persistent store for received reply surbs, unused encryption keys and used sender tags. +reply_surb_database = '{{ storage_paths.reply_surb_database }}' + +# DEPRECATED [client.gateway_endpoint] # ID of the gateway from which the client should be fetching messages. gateway_id = '{{ client.gateway_endpoint.gateway_id }}' diff --git a/clients/native/src/client/mod.rs b/clients/native/src/client/mod.rs index 277ea3806f..9078f79dce 100644 --- a/clients/native/src/client/mod.rs +++ b/clients/native/src/client/mod.rs @@ -17,7 +17,6 @@ use nym_client_core::client::key_manager::persistence::OnDiskKeys; use nym_client_core::client::received_buffer::{ ReceivedBufferMessage, ReceivedBufferRequestSender, ReconstructedMessagesReceiver, }; -use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths; use nym_credential_storage::persistent_storage::PersistentStorage; use nym_sphinx::anonymous_replies::requests::AnonymousSenderTag; use nym_sphinx::params::PacketType; @@ -107,7 +106,7 @@ impl SocketClient { } fn key_store(&self) -> OnDiskKeys { - OnDiskKeys::new(self.config.storage_paths.common_paths.keys_paths.clone()) + OnDiskKeys::new(self.config.storage_paths.common_paths.keys.clone()) } // TODO: see if this could also be shared with socks5 client / nym-sdk maybe @@ -124,11 +123,7 @@ impl SocketClient { self.key_store(), bandwidth_controller, non_wasm_helpers::setup_fs_reply_surb_backend( - &self - .config - .storage_paths - .common_paths - .reply_surb_database_path, + &self.config.storage_paths.common_paths.reply_surb_database, &self.config.base.debug.reply_surbs, ) .await?, diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index 8c05ce7251..340b984cd8 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -1,10 +1,10 @@ -// Copyright 2021 - Nym Technologies SA +// Copyright 2021-2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 use crate::client::config::{ default_config_directory, default_config_filepath, default_data_directory, }; -use crate::commands::try_upgrade_v1_1_13_config; +use crate::commands::try_upgrade_config; use crate::{ client::config::Config, commands::{override_config, OverrideConfig}, @@ -135,7 +135,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> { let already_init = if default_config_filepath(id).exists() { // in case we're using old config, try to upgrade it // (if we're using the current version, it's a no-op) - try_upgrade_v1_1_13_config(id)?; + try_upgrade_config(id)?; eprintln!("Client \"{id}\" was already initialised before"); true } else { @@ -163,7 +163,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> { // Setup gateway by either registering a new one, or creating a new config from the selected // one but with keys kept, or reusing the gateway configuration. - let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone()); + let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone()); let gateway = nym_client_core::init::setup_gateway_from_config::<_>( &key_store, register_gateway, @@ -186,7 +186,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), ClientError> { ); let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys( - &config.storage_paths.common_paths.keys_paths, + &config.storage_paths.common_paths.keys, &config.base.client.gateway_endpoint, )?; diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index 7b9bfbb342..fedb57960e 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 use crate::client::config::old_config_v1_1_13::OldConfigV1_1_13; +use crate::client::config::old_config_v1_1_19::ConfigV1_1_19; use crate::client::config::{BaseClientConfig, Config}; +use crate::error::ClientError; use clap::CommandFactory; use clap::{Parser, Subcommand}; use lazy_static::lazy_static; -use log::info; +use log::{error, info}; use nym_bin_common::build_information::BinaryBuildInformation; use nym_bin_common::completions::{fig_generate, ArgShell}; use nym_config::OptionalSet; @@ -107,19 +109,67 @@ pub(crate) fn override_config(config: Config, args: OverrideConfig) -> Config { ) } -fn try_upgrade_v1_1_13_config(id: &str) -> std::io::Result<()> { - todo!() - // // explicitly load it as v1.1.13 (which is incompatible with the current, i.e. 1.1.14+) - // let Ok(old_config) = OldConfigV1_1_13::load_from_file(id) else { - // // if we failed to load it, there might have been nothing to upgrade - // // or maybe it was an even older file. in either way. just ignore it and carry on with our day - // return Ok(()); - // }; - // info!("It seems the client is using <= v1.1.13 config template."); - // info!("It is going to get updated to the current specification."); - // - // let updated: Config = old_config.into(); - // updated.save_to_file(None) +fn try_upgrade_v1_1_13_config(id: &str) -> Result { + use nym_config::legacy_helpers::nym_config::MigrationNymConfig; + + // explicitly load it as v1.1.13 (which is incompatible with the next step, i.e. 1.1.19) + let Ok(old_config) = OldConfigV1_1_13::load_from_file(id) else { + // if we failed to load it, there might have been nothing to upgrade + // or maybe it was an even older file. in either way. just ignore it and carry on with our day + return Ok(false); + }; + info!("It seems the client is using <= v1.1.13 config template."); + info!("It is going to get updated to the current specification."); + + let updated_step1: ConfigV1_1_19 = old_config.into(); + let updated: Config = updated_step1.into(); + + updated.save_to_default_location()?; + Ok(true) +} + +fn try_upgrade_v1_1_19_config(id: &str) -> Result { + use nym_config::legacy_helpers::nym_config::MigrationNymConfig; + + // explicitly load it as v1.1.19 (which is incompatible with the current one, i.e. +1.1.20) + let Ok(old_config) = ConfigV1_1_19::load_from_file(id) else { + // if we failed to load it, there might have been nothing to upgrade + // or maybe it was an even older file. in either way. just ignore it and carry on with our day + return Ok(false); + }; + info!("It seems the client is using <= v1.1.20 config template."); + info!("It is going to get updated to the current specification."); + + let updated: Config = old_config.into(); + updated.save_to_default_location()?; + Ok(true) +} + +fn try_upgrade_config(id: &str) -> Result<(), ClientError> { + let upgraded = try_upgrade_v1_1_13_config(id)?; + if !upgraded { + try_upgrade_v1_1_19_config(id)?; + } + + Ok(()) +} + +fn try_load_current_config(id: &str) -> Result { + try_upgrade_config(id)?; + + let config = match Config::read_from_default_path(id) { + Ok(cfg) => cfg, + Err(err) => { + error!("Failed to load config for {id}. Are you sure you have run `init` before? (Error was: {err})"); + return Err(ClientError::FailedToLoadConfig(id.to_string())); + } + }; + + if !config.validate() { + return Err(ClientError::ConfigValidationFailure); + } + + Ok(config) } #[cfg(test)] diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index d73743ca4f..23cf54588b 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -1,10 +1,7 @@ // Copyright 2021-2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use std::error::Error; -use std::net::IpAddr; - -use crate::commands::try_upgrade_v1_1_13_config; +use crate::commands::try_load_current_config; use crate::{ client::{config::Config, SocketClient}, commands::{override_config, OverrideConfig}, @@ -14,6 +11,8 @@ use clap::Args; use log::*; use nym_bin_common::version_checker::is_minor_version_compatible; use nym_crypto::asymmetric::identity; +use std::error::Error; +use std::net::IpAddr; #[derive(Args, Clone)] pub(crate) struct Run { @@ -97,26 +96,10 @@ fn version_check(cfg: &Config) -> bool { } pub(crate) async fn execute(args: &Run) -> Result<(), Box> { - let id = &args.id; + eprintln!("Starting client {}...", args.id); - // in case we're using old config, try to upgrade it - // (if we're using the current version, it's a no-op) - try_upgrade_v1_1_13_config(id)?; - - let mut config = match Config::read_from_default_path(id) { - Ok(cfg) => cfg, - Err(err) => { - error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {err})", id); - return Err(Box::new(ClientError::FailedToLoadConfig(id.to_string()))); - } - }; - - if !config.validate() { - return Err(Box::new(ClientError::ConfigValidationFailure)); - } - - let override_config_fields = OverrideConfig::from(args.clone()); - config = override_config(config, override_config_fields); + let mut config = try_load_current_config(&args.id)?; + config = override_config(config, OverrideConfig::from(args.clone())); if !version_check(&config) { error!("failed the local version check"); diff --git a/clients/native/src/commands/upgrade.rs b/clients/native/src/commands/upgrade.rs index 8b823ca431..b4c2d45ad3 100644 --- a/clients/native/src/commands/upgrade.rs +++ b/clients/native/src/commands/upgrade.rs @@ -2,44 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 use crate::client::config::Config; +use crate::commands::try_load_current_config; use clap::Args; use nym_bin_common::version_checker::Version; -use std::fmt::Display; use std::process; -#[allow(dead_code)] -fn fail_upgrade(from_version: D1, to_version: D2) -> ! { - print_failed_upgrade(from_version, to_version); - process::exit(1) -} - -fn print_start_upgrade(from: D1, to: D2) { - println!("\n==================\nTrying to upgrade client from {from} to {to} ..."); -} - -fn print_failed_upgrade(from: D1, to: D2) { - eprintln!("Upgrade from {from} to {to} failed!\n==================\n"); -} - -fn print_successful_upgrade(from: D1, to: D2) { - println!("Upgrade from {from} to {to} was successful!\n==================\n"); -} - -fn outdated_upgrade(config_version: &Version, package_version: &Version) -> ! { - eprintln!( - "Cannot perform upgrade from {config_version} to {package_version}. Your version is too old to perform the upgrade.!" - ); - process::exit(1) -} - -fn unsupported_upgrade(current_version: &Version, config_version: &Version) -> ! { - eprintln!("Cannot perform upgrade from {config_version} to {current_version}. Please let the developers know about this issue if you expected it to work!"); - process::exit(1) -} - fn unimplemented_upgrade(current_version: &Version, config_version: &Version) -> ! { eprintln!("Cannot perform upgrade from {config_version} to {current_version} as it hasn't been implemented yet"); - todo!(); process::exit(1) } @@ -80,25 +49,14 @@ fn parse_package_version() -> Version { version } -fn do_upgrade(mut config: Config, args: &Upgrade, package_version: &Version) { - loop { - let config_version = parse_config_version(&config); - - if &config_version == package_version { - println!("You're using the most recent version!"); - return; - } - - config = match config_version.major { - 0 => outdated_upgrade(&config_version, package_version), - 1 => match config_version.minor { - n if n <= 13 => outdated_upgrade(&config_version, package_version), - n if n > 13 && n < 19 => unimplemented_upgrade(&config_version, package_version), - _ => unsupported_upgrade(&config_version, package_version), - }, - _ => unsupported_upgrade(&config_version, package_version), - } +fn do_upgrade(config: Config, _args: &Upgrade, package_version: &Version) { + let config_version = parse_config_version(&config); + if &config_version == package_version { + println!("You're using the most recent version!"); + return; } + + unimplemented_upgrade(package_version, &config_version) } pub(crate) fn execute(args: &Upgrade) { @@ -106,7 +64,7 @@ pub(crate) fn execute(args: &Upgrade) { let id = &args.id; - let existing_config = Config::read_from_default_path(id).unwrap_or_else(|err| { + let existing_config = try_load_current_config(id).unwrap_or_else(|err| { eprintln!("failed to load existing config file! - {err}"); process::exit(1) }); @@ -116,6 +74,5 @@ pub(crate) fn execute(args: &Upgrade) { process::exit(1); } - // here be upgrade path to 0.9.X and beyond based on version number from config do_upgrade(existing_config, args, &package_version) } diff --git a/clients/socks5/src/commands/init.rs b/clients/socks5/src/commands/init.rs index 89cc6f1e10..5b44bafdac 100644 --- a/clients/socks5/src/commands/init.rs +++ b/clients/socks5/src/commands/init.rs @@ -169,7 +169,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> { // Setup gateway by either registering a new one, or creating a new config from the selected // one but with keys kept, or reusing the gateway configuration. - let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone()); + let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone()); let gateway = nym_client_core::init::setup_gateway_from_config::<_>( &key_store, register_gateway, @@ -194,7 +194,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), Socks5ClientError> { ); let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys( - &config.storage_paths.common_paths.keys_paths, + &config.storage_paths.common_paths.keys, &config.core.base.client.gateway_endpoint, )?; let init_results = InitResults::new(&config, &address); diff --git a/common/bin-common/src/logging/mod.rs b/common/bin-common/src/logging/mod.rs index b0a3358298..e1f009662c 100644 --- a/common/bin-common/src/logging/mod.rs +++ b/common/bin-common/src/logging/mod.rs @@ -10,7 +10,7 @@ pub use tracing_subscriber; #[cfg(feature = "tracing")] pub use tracing_tree; -#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, Serialize)] +#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq, Serialize)] #[serde(deny_unknown_fields)] pub struct LoggingSettings { // well, we need to implement something here at some point... diff --git a/common/client-core/src/client/base_client/storage/mod.rs b/common/client-core/src/client/base_client/storage/mod.rs index f9e939ec57..b64242eb88 100644 --- a/common/client-core/src/client/base_client/storage/mod.rs +++ b/common/client-core/src/client/base_client/storage/mod.rs @@ -100,10 +100,10 @@ impl OnDiskPersistent { paths: CommonClientPaths, debug_config: &config::DebugConfig, ) -> Result { - let key_store = OnDiskKeys::new(paths.keys_paths); + let key_store = OnDiskKeys::new(paths.keys); let reply_store = non_wasm_helpers::setup_fs_reply_surb_backend( - paths.reply_surb_database_path, + paths.reply_surb_database, &debug_config.reply_surbs, ) .await?; diff --git a/common/client-core/src/config/disk_persistence/mod.rs b/common/client-core/src/config/disk_persistence/mod.rs index 339d085abe..9b4532e153 100644 --- a/common/client-core/src/config/disk_persistence/mod.rs +++ b/common/client-core/src/config/disk_persistence/mod.rs @@ -12,16 +12,15 @@ pub const DEFAULT_CREDENTIALS_DB_FILENAME: &str = "credentials_database.db"; #[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] pub struct CommonClientPaths { - pub keys_paths: ClientKeysPaths, + pub keys: ClientKeysPaths, // TODO: // pub gateway_config_pathfinder: (), /// Path to the database containing bandwidth credentials of this client. - #[serde(alias = "database_path")] pub credentials_database: PathBuf, /// Path to the persistent store for received reply surbs, unused encryption keys and used sender tags. - pub reply_surb_database_path: PathBuf, + pub reply_surb_database: PathBuf, } impl CommonClientPaths { @@ -30,8 +29,8 @@ impl CommonClientPaths { CommonClientPaths { credentials_database: base_dir.join(DEFAULT_CREDENTIALS_DB_FILENAME), - reply_surb_database_path: base_dir.join(DEFAULT_REPLY_SURB_DB_FILENAME), - keys_paths: ClientKeysPaths::new_default(base_data_directory), + reply_surb_database: base_dir.join(DEFAULT_REPLY_SURB_DB_FILENAME), + keys: ClientKeysPaths::new_default(base_data_directory), } } } diff --git a/common/client-core/src/config/mod.rs b/common/client-core/src/config/mod.rs index b9481272aa..b2bd7bdd5e 100644 --- a/common/client-core/src/config/mod.rs +++ b/common/client-core/src/config/mod.rs @@ -5,7 +5,6 @@ use nym_config::defaults::NymNetworkDetails; use nym_crypto::asymmetric::identity; use nym_sphinx::params::{PacketSize, PacketType}; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; use std::time::Duration; use url::Url; @@ -15,6 +14,7 @@ use wasm_bindgen::prelude::*; pub mod disk_persistence; pub mod old_config_v1_1_13; +pub mod old_config_v1_1_19; // 'DEBUG' const DEFAULT_ACK_WAIT_MULTIPLIER: f64 = 1.5; diff --git a/common/client-core/src/config/old_config_v1_1_13.rs b/common/client-core/src/config/old_config_v1_1_13.rs index 54addf2dcf..09c0ed1f3d 100644 --- a/common/client-core/src/config/old_config_v1_1_13.rs +++ b/common/client-core/src/config/old_config_v1_1_13.rs @@ -1,14 +1,14 @@ // Copyright 2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use crate::config::{ - Acknowledgements, Client, Config, CoverTraffic, DebugConfig, GatewayConnection, ReplySurbs, - Topology, Traffic, DEFAULT_ACK_WAIT_ADDITION, DEFAULT_ACK_WAIT_MULTIPLIER, - DEFAULT_AVERAGE_PACKET_DELAY, DEFAULT_GATEWAY_RESPONSE_TIMEOUT, - DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY, DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE, - DEFAULT_MAXIMUM_REPLY_KEY_AGE, DEFAULT_MAXIMUM_REPLY_SURB_AGE, - DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD, DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE, - DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD, +use crate::config::old_config_v1_1_19::{ + AcknowledgementsV1_1_19, ClientV1_1_19, ConfigV1_1_19, CoverTrafficV1_1_19, DebugConfigV1_1_19, + GatewayConnectionV1_1_19, LoggingV1_1_19, ReplySurbsV1_1_19, TopologyV1_1_19, TrafficV1_1_19, + DEFAULT_ACK_WAIT_ADDITION, DEFAULT_ACK_WAIT_MULTIPLIER, DEFAULT_AVERAGE_PACKET_DELAY, + DEFAULT_GATEWAY_RESPONSE_TIMEOUT, DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY, + DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE, DEFAULT_MAXIMUM_REPLY_KEY_AGE, + DEFAULT_MAXIMUM_REPLY_SURB_AGE, DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD, + DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE, DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD, DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD, DEFAULT_MESSAGE_STREAM_AVERAGE_DELAY, DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE, DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD, DEFAULT_TOPOLOGY_REFRESH_RATE, DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT, @@ -18,8 +18,6 @@ use serde::{Deserialize, Serialize}; use std::marker::PhantomData; use std::time::Duration; -// use nym_config::NymConfig; - #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum ExtendedPacketSize { @@ -41,22 +39,21 @@ impl From for PacketSize { #[derive(Debug, Clone, Deserialize, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct OldConfigV1_1_13 { - pub client: PhantomData, - // pub client: Client, - // #[serde(default)] - // logging: Logging, + pub client: ClientV1_1_19, + #[serde(default)] - debug: OldDebugConfigV1_1_13, + pub logging: OldLoggingV1_1_13, + #[serde(default)] + pub debug: OldDebugConfigV1_1_13, } -impl Default for OldConfigV1_1_13 { - fn default() -> Self { - todo!() - // OldConfigV1_1_13 { - // client: Client::::default(), - // logging: Default::default(), - // debug: Default::default(), - // } +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct OldLoggingV1_1_13 {} + +impl From for LoggingV1_1_19 { + fn from(_value: OldLoggingV1_1_13) -> Self { + LoggingV1_1_19 {} } } @@ -117,10 +114,10 @@ pub struct OldDebugConfigV1_1_13 { pub maximum_reply_key_age: Duration, } -impl From for DebugConfig { +impl From for DebugConfigV1_1_19 { fn from(value: OldDebugConfigV1_1_13) -> Self { - DebugConfig { - traffic: Traffic { + DebugConfigV1_1_19 { + traffic: TrafficV1_1_19 { average_packet_delay: value.average_packet_delay, message_sending_average_delay: value.message_sending_average_delay, disable_main_poisson_packet_distribution: value @@ -128,25 +125,25 @@ impl From for DebugConfig { primary_packet_size: PacketSize::RegularPacket, secondary_packet_size: value.use_extended_packet_size.map(Into::into), }, - cover_traffic: CoverTraffic { + cover_traffic: CoverTrafficV1_1_19 { loop_cover_traffic_average_delay: value.loop_cover_traffic_average_delay, disable_loop_cover_traffic_stream: value.disable_loop_cover_traffic_stream, - ..CoverTraffic::default() + ..CoverTrafficV1_1_19::default() }, - gateway_connection: GatewayConnection { + gateway_connection: GatewayConnectionV1_1_19 { gateway_response_timeout: value.gateway_response_timeout, }, - acknowledgements: Acknowledgements { + acknowledgements: AcknowledgementsV1_1_19 { average_ack_delay: value.average_ack_delay, ack_wait_multiplier: value.ack_wait_multiplier, ack_wait_addition: value.ack_wait_addition, }, - topology: Topology { + topology: TopologyV1_1_19 { topology_refresh_rate: value.topology_refresh_rate, topology_resolution_timeout: value.topology_resolution_timeout, disable_refreshing: false, }, - reply_surbs: ReplySurbs { + reply_surbs: ReplySurbsV1_1_19 { minimum_reply_surb_storage_threshold: value.minimum_reply_surb_storage_threshold, maximum_reply_surb_storage_threshold: value.maximum_reply_surb_storage_threshold, minimum_reply_surb_request_size: value.minimum_reply_surb_request_size, @@ -193,31 +190,30 @@ impl Default for OldDebugConfigV1_1_13 { } } -impl From> for Config { +impl From> for ConfigV1_1_19 { fn from(value: OldConfigV1_1_13) -> Self { - todo!() - // Config { - // client: Client { - // version: value.client.version, - // id: value.client.id, - // disabled_credentials_mode: value.client.disabled_credentials_mode, - // nyxd_urls: value.client.nyxd_urls, - // nym_api_urls: value.client.nym_api_urls, - // private_identity_key_file: value.client.private_identity_key_file, - // public_identity_key_file: value.client.public_identity_key_file, - // private_encryption_key_file: value.client.private_encryption_key_file, - // public_encryption_key_file: value.client.public_encryption_key_file, - // gateway_shared_key_file: value.client.gateway_shared_key_file, - // ack_key_file: value.client.ack_key_file, - // gateway_endpoint: value.client.gateway_endpoint, - // database_path: value.client.database_path, - // reply_surb_database_path: value.client.reply_surb_database_path, - // nym_root_directory: value.client.nym_root_directory, - // - // super_struct: PhantomData, - // }, - // logging: value.logging, - // debug: value.debug.into(), - // } + ConfigV1_1_19 { + client: ClientV1_1_19 { + version: value.client.version, + id: value.client.id, + disabled_credentials_mode: value.client.disabled_credentials_mode, + nyxd_urls: value.client.nyxd_urls, + nym_api_urls: value.client.nym_api_urls, + private_identity_key_file: value.client.private_identity_key_file, + public_identity_key_file: value.client.public_identity_key_file, + private_encryption_key_file: value.client.private_encryption_key_file, + public_encryption_key_file: value.client.public_encryption_key_file, + gateway_shared_key_file: value.client.gateway_shared_key_file, + ack_key_file: value.client.ack_key_file, + gateway_endpoint: value.client.gateway_endpoint, + database_path: value.client.database_path, + reply_surb_database_path: value.client.reply_surb_database_path, + nym_root_directory: value.client.nym_root_directory, + + super_struct: PhantomData, + }, + logging: value.logging.into(), + debug: value.debug.into(), + } } } diff --git a/common/client-core/src/config/old_config_v1_1_19.rs b/common/client-core/src/config/old_config_v1_1_19.rs new file mode 100644 index 0000000000..214c96aab2 --- /dev/null +++ b/common/client-core/src/config/old_config_v1_1_19.rs @@ -0,0 +1,353 @@ +// Copyright 2023 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 + +use crate::config::{ + Acknowledgements, CoverTraffic, DebugConfig, GatewayConnection, GatewayEndpointConfig, + ReplySurbs, Topology, Traffic, +}; +use nym_sphinx::params::PacketSize; +use serde::{Deserialize, Serialize}; +use std::marker::PhantomData; +use std::path::PathBuf; +use std::time::Duration; +use url::Url; + +// 'DEBUG' +pub(crate) const DEFAULT_ACK_WAIT_MULTIPLIER: f64 = 1.5; + +pub(crate) const DEFAULT_ACK_WAIT_ADDITION: Duration = Duration::from_millis(1_500); +pub(crate) const DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY: Duration = Duration::from_millis(200); +pub(crate) const DEFAULT_MESSAGE_STREAM_AVERAGE_DELAY: Duration = Duration::from_millis(20); +pub(crate) const DEFAULT_AVERAGE_PACKET_DELAY: Duration = Duration::from_millis(50); +pub(crate) const DEFAULT_TOPOLOGY_REFRESH_RATE: Duration = Duration::from_secs(5 * 60); // every 5min +pub(crate) const DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT: Duration = Duration::from_millis(5_000); +// Set this to a high value for now, so that we don't risk sporadic timeouts that might cause +// bought bandwidth tokens to not have time to be spent; Once we remove the gateway from the +// bandwidth bridging protocol, we can come back to a smaller timeout value +pub(crate) const DEFAULT_GATEWAY_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5 * 60); + +pub(crate) const DEFAULT_COVER_TRAFFIC_PRIMARY_SIZE_RATIO: f64 = 0.70; + +// reply-surbs related: + +// define when to request +// clients/client-core/src/client/replies/reply_storage/surb_storage.rs +pub(crate) const DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 10; +pub(crate) const DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD: usize = 200; + +// define how much to request at once +// clients/client-core/src/client/replies/reply_controller.rs +pub(crate) const DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 10; +pub(crate) const DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE: u32 = 100; + +pub(crate) const DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE: u32 = 500; + +pub(crate) const DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD: Duration = + Duration::from_secs(10); +pub(crate) const DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD: Duration = + Duration::from_secs(5 * 60); + +// 12 hours +pub(crate) const DEFAULT_MAXIMUM_REPLY_SURB_AGE: Duration = Duration::from_secs(12 * 60 * 60); + +// 24 hours +pub(crate) const DEFAULT_MAXIMUM_REPLY_KEY_AGE: Duration = Duration::from_secs(24 * 60 * 60); + +#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct ConfigV1_1_19 { + pub client: ClientV1_1_19, + + #[serde(default)] + pub logging: LoggingV1_1_19, + #[serde(default)] + pub debug: DebugConfigV1_1_19, +} + +#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)] +pub struct GatewayEndpointConfigV1_1_19 { + pub gateway_id: String, + pub gateway_owner: String, + pub gateway_listener: String, +} + +impl From for GatewayEndpointConfig { + fn from(value: GatewayEndpointConfigV1_1_19) -> Self { + GatewayEndpointConfig { + gateway_id: value.gateway_id, + gateway_owner: value.gateway_owner, + gateway_listener: value.gateway_listener, + } + } +} + +#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] +pub struct ClientV1_1_19 { + pub version: String, + pub id: String, + #[serde(default)] + pub disabled_credentials_mode: bool, + #[serde(alias = "validator_urls")] + pub nyxd_urls: Vec, + #[serde(alias = "validator_api_urls")] + pub nym_api_urls: Vec, + pub private_identity_key_file: PathBuf, + pub public_identity_key_file: PathBuf, + pub private_encryption_key_file: PathBuf, + pub public_encryption_key_file: PathBuf, + pub gateway_shared_key_file: PathBuf, + pub ack_key_file: PathBuf, + pub gateway_endpoint: GatewayEndpointConfigV1_1_19, + pub database_path: PathBuf, + #[serde(default)] + pub reply_surb_database_path: PathBuf, + pub nym_root_directory: PathBuf, + + #[serde(skip)] + pub super_struct: PhantomData, +} + +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct LoggingV1_1_19 {} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default)] +pub struct TrafficV1_1_19 { + #[serde(with = "humantime_serde")] + pub average_packet_delay: Duration, + #[serde(with = "humantime_serde")] + pub message_sending_average_delay: Duration, + pub disable_main_poisson_packet_distribution: bool, + pub primary_packet_size: PacketSize, + pub secondary_packet_size: Option, +} + +impl From for Traffic { + fn from(value: TrafficV1_1_19) -> Self { + Traffic { + average_packet_delay: value.average_packet_delay, + message_sending_average_delay: value.message_sending_average_delay, + disable_main_poisson_packet_distribution: value + .disable_main_poisson_packet_distribution, + primary_packet_size: value.primary_packet_size, + secondary_packet_size: value.secondary_packet_size, + } + } +} + +impl Default for TrafficV1_1_19 { + fn default() -> Self { + TrafficV1_1_19 { + average_packet_delay: DEFAULT_AVERAGE_PACKET_DELAY, + message_sending_average_delay: DEFAULT_MESSAGE_STREAM_AVERAGE_DELAY, + disable_main_poisson_packet_distribution: false, + primary_packet_size: PacketSize::RegularPacket, + secondary_packet_size: None, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct CoverTrafficV1_1_19 { + #[serde(with = "humantime_serde")] + pub loop_cover_traffic_average_delay: Duration, + pub cover_traffic_primary_size_ratio: f64, + pub disable_loop_cover_traffic_stream: bool, +} + +impl From for CoverTraffic { + fn from(value: CoverTrafficV1_1_19) -> Self { + CoverTraffic { + loop_cover_traffic_average_delay: value.loop_cover_traffic_average_delay, + cover_traffic_primary_size_ratio: value.cover_traffic_primary_size_ratio, + disable_loop_cover_traffic_stream: value.disable_loop_cover_traffic_stream, + } + } +} + +impl Default for CoverTrafficV1_1_19 { + fn default() -> Self { + CoverTrafficV1_1_19 { + loop_cover_traffic_average_delay: DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY, + cover_traffic_primary_size_ratio: DEFAULT_COVER_TRAFFIC_PRIMARY_SIZE_RATIO, + disable_loop_cover_traffic_stream: false, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct GatewayConnectionV1_1_19 { + #[serde(with = "humantime_serde")] + pub gateway_response_timeout: Duration, +} + +impl From for GatewayConnection { + fn from(value: GatewayConnectionV1_1_19) -> Self { + GatewayConnection { + gateway_response_timeout: value.gateway_response_timeout, + } + } +} + +impl Default for GatewayConnectionV1_1_19 { + fn default() -> Self { + GatewayConnectionV1_1_19 { + gateway_response_timeout: DEFAULT_GATEWAY_RESPONSE_TIMEOUT, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct AcknowledgementsV1_1_19 { + #[serde(with = "humantime_serde")] + pub average_ack_delay: Duration, + pub ack_wait_multiplier: f64, + #[serde(with = "humantime_serde")] + pub ack_wait_addition: Duration, +} + +impl From for Acknowledgements { + fn from(value: AcknowledgementsV1_1_19) -> Self { + Acknowledgements { + average_ack_delay: value.average_ack_delay, + ack_wait_multiplier: value.ack_wait_multiplier, + ack_wait_addition: value.ack_wait_addition, + } + } +} + +impl Default for AcknowledgementsV1_1_19 { + fn default() -> Self { + AcknowledgementsV1_1_19 { + average_ack_delay: DEFAULT_AVERAGE_PACKET_DELAY, + ack_wait_multiplier: DEFAULT_ACK_WAIT_MULTIPLIER, + ack_wait_addition: DEFAULT_ACK_WAIT_ADDITION, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct TopologyV1_1_19 { + #[serde(with = "humantime_serde")] + pub topology_refresh_rate: Duration, + #[serde(with = "humantime_serde")] + pub topology_resolution_timeout: Duration, + pub disable_refreshing: bool, +} + +impl From for Topology { + fn from(value: TopologyV1_1_19) -> Self { + Topology { + topology_refresh_rate: value.topology_refresh_rate, + topology_resolution_timeout: value.topology_resolution_timeout, + disable_refreshing: value.disable_refreshing, + } + } +} + +impl Default for TopologyV1_1_19 { + fn default() -> Self { + TopologyV1_1_19 { + topology_refresh_rate: DEFAULT_TOPOLOGY_REFRESH_RATE, + topology_resolution_timeout: DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT, + disable_refreshing: false, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct ReplySurbsV1_1_19 { + pub minimum_reply_surb_storage_threshold: usize, + pub maximum_reply_surb_storage_threshold: usize, + pub minimum_reply_surb_request_size: u32, + pub maximum_reply_surb_request_size: u32, + pub maximum_allowed_reply_surb_request_size: u32, + #[serde(with = "humantime_serde")] + pub maximum_reply_surb_rerequest_waiting_period: Duration, + #[serde(with = "humantime_serde")] + pub maximum_reply_surb_drop_waiting_period: Duration, + #[serde(with = "humantime_serde")] + pub maximum_reply_surb_age: Duration, + #[serde(with = "humantime_serde")] + pub maximum_reply_key_age: Duration, +} + +impl From for ReplySurbs { + fn from(value: ReplySurbsV1_1_19) -> Self { + ReplySurbs { + minimum_reply_surb_storage_threshold: value.minimum_reply_surb_storage_threshold, + maximum_reply_surb_storage_threshold: value.maximum_reply_surb_storage_threshold, + minimum_reply_surb_request_size: value.minimum_reply_surb_request_size, + maximum_reply_surb_request_size: value.maximum_reply_surb_request_size, + maximum_allowed_reply_surb_request_size: value.maximum_allowed_reply_surb_request_size, + maximum_reply_surb_rerequest_waiting_period: value + .maximum_reply_surb_rerequest_waiting_period, + maximum_reply_surb_drop_waiting_period: value.maximum_reply_surb_drop_waiting_period, + maximum_reply_surb_age: value.maximum_reply_surb_age, + maximum_reply_key_age: value.maximum_reply_key_age, + } + } +} + +impl Default for ReplySurbsV1_1_19 { + fn default() -> Self { + ReplySurbsV1_1_19 { + minimum_reply_surb_storage_threshold: DEFAULT_MINIMUM_REPLY_SURB_STORAGE_THRESHOLD, + maximum_reply_surb_storage_threshold: DEFAULT_MAXIMUM_REPLY_SURB_STORAGE_THRESHOLD, + minimum_reply_surb_request_size: DEFAULT_MINIMUM_REPLY_SURB_REQUEST_SIZE, + maximum_reply_surb_request_size: DEFAULT_MAXIMUM_REPLY_SURB_REQUEST_SIZE, + maximum_allowed_reply_surb_request_size: DEFAULT_MAXIMUM_ALLOWED_SURB_REQUEST_SIZE, + maximum_reply_surb_rerequest_waiting_period: + DEFAULT_MAXIMUM_REPLY_SURB_REREQUEST_WAITING_PERIOD, + maximum_reply_surb_drop_waiting_period: DEFAULT_MAXIMUM_REPLY_SURB_DROP_WAITING_PERIOD, + maximum_reply_surb_age: DEFAULT_MAXIMUM_REPLY_SURB_AGE, + maximum_reply_key_age: DEFAULT_MAXIMUM_REPLY_KEY_AGE, + } + } +} + +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)] +#[serde(default, deny_unknown_fields)] +pub struct DebugConfigV1_1_19 { + pub traffic: TrafficV1_1_19, + pub cover_traffic: CoverTrafficV1_1_19, + pub gateway_connection: GatewayConnectionV1_1_19, + pub acknowledgements: AcknowledgementsV1_1_19, + pub topology: TopologyV1_1_19, + pub reply_surbs: ReplySurbsV1_1_19, +} + +impl From for DebugConfig { + fn from(value: DebugConfigV1_1_19) -> Self { + DebugConfig { + traffic: value.traffic.into(), + cover_traffic: value.cover_traffic.into(), + gateway_connection: value.gateway_connection.into(), + acknowledgements: value.acknowledgements.into(), + topology: value.topology.into(), + reply_surbs: value.reply_surbs.into(), + } + } +} + +// it could be derived, sure, but I'd rather have an explicit implementation in case we had to change +// something manually at some point +#[allow(clippy::derivable_impls)] +impl Default for DebugConfigV1_1_19 { + fn default() -> Self { + DebugConfigV1_1_19 { + traffic: Default::default(), + cover_traffic: Default::default(), + gateway_connection: Default::default(), + acknowledgements: Default::default(), + topology: Default::default(), + reply_surbs: Default::default(), + } + } +} diff --git a/common/client-core/src/init/mod.rs b/common/client-core/src/init/mod.rs index 3983be2b32..cf07e042a3 100644 --- a/common/client-core/src/init/mod.rs +++ b/common/client-core/src/init/mod.rs @@ -17,7 +17,6 @@ use nym_validator_client::client::IdentityKey; use rand::rngs::OsRng; use serde::Serialize; use std::fmt::{Debug, Display}; -use tap::TapFallible; use url::Url; mod helpers; diff --git a/common/config/src/legacy_helpers.rs b/common/config/src/legacy_helpers.rs index 191586ee89..315b6c2b49 100644 --- a/common/config/src/legacy_helpers.rs +++ b/common/config/src/legacy_helpers.rs @@ -12,7 +12,7 @@ pub mod nym_config { pub const DATA_DIR: &str = "data"; // no need for anything to do with saving. - pub trait MigrationNymConfig: Default + Serialize + DeserializeOwned { + pub trait MigrationNymConfig: Serialize + DeserializeOwned { fn config_file_name() -> String { "config.toml".to_string() } diff --git a/nym-connect/desktop/src-tauri/src/config/mod.rs b/nym-connect/desktop/src-tauri/src/config/mod.rs index 2d002a4333..afb960cb56 100644 --- a/nym-connect/desktop/src-tauri/src/config/mod.rs +++ b/nym-connect/desktop/src-tauri/src/config/mod.rs @@ -154,7 +154,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str .map_err(|_| BackendError::UnableToParseGateway)?; // Setup gateway by either registering a new one, or reusing exiting keys - let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone()); + let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone()); let gateway = nym_client_core::init::setup_gateway_from_config::<_>( &key_store, register_gateway, @@ -175,7 +175,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str print_saved_config(&config); let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys( - &config.storage_paths.common_paths.keys_paths, + &config.storage_paths.common_paths.keys, &config.socks5.base.client.gateway_endpoint, )?; log::info!("The address of this client is: {}", address); diff --git a/nym-connect/desktop/src-tauri/src/operations/export.rs b/nym-connect/desktop/src-tauri/src/operations/export.rs index 33853ded87..9cd63fa579 100644 --- a/nym-connect/desktop/src-tauri/src/operations/export.rs +++ b/nym-connect/desktop/src-tauri/src/operations/export.rs @@ -20,7 +20,7 @@ pub async fn get_identity_key( state.load_config()? }; - let paths = config.storage_paths.common_paths.keys_paths; + let paths = config.storage_paths.common_paths.keys; // wtf, why are we loading EVERYTHING to just get identity key?? let key_store = OnDiskKeys::from(paths); @@ -52,7 +52,7 @@ pub async fn export_keys(state: tauri::State<'_, Arc>>) -> Result< state.load_config()? }; - let key_paths = config.storage_paths.common_paths.keys_paths; + let key_paths = config.storage_paths.common_paths.keys; // Get key paths let ack_key_file = key_paths.ack_key(); diff --git a/sdk/rust/nym-sdk/src/mixnet/paths.rs b/sdk/rust/nym-sdk/src/mixnet/paths.rs index 98121773d4..f005b6bd63 100644 --- a/sdk/rust/nym-sdk/src/mixnet/paths.rs +++ b/sdk/rust/nym-sdk/src/mixnet/paths.rs @@ -136,7 +136,7 @@ impl StoragePaths { impl From for CommonClientPaths { fn from(value: StoragePaths) -> Self { CommonClientPaths { - keys_paths: ClientKeysPaths { + keys: ClientKeysPaths { private_identity_key_file: value.private_identity, public_identity_key_file: value.public_identity, private_encryption_key_file: value.private_encryption, @@ -145,7 +145,7 @@ impl From for CommonClientPaths { ack_key_file: value.ack_key, }, credentials_database: value.credential_database_path, - reply_surb_database_path: value.reply_surb_database_path, + reply_surb_database: value.reply_surb_database_path, } } } @@ -153,14 +153,14 @@ impl From for CommonClientPaths { impl From for StoragePaths { fn from(value: CommonClientPaths) -> Self { StoragePaths { - private_identity: value.keys_paths.private_identity_key_file, - public_identity: value.keys_paths.public_identity_key_file, - private_encryption: value.keys_paths.private_encryption_key_file, - public_encryption: value.keys_paths.public_encryption_key_file, - ack_key: value.keys_paths.ack_key_file, - gateway_shared_key: value.keys_paths.gateway_shared_key_file, + private_identity: value.keys.private_identity_key_file, + public_identity: value.keys.public_identity_key_file, + private_encryption: value.keys.private_encryption_key_file, + public_encryption: value.keys.public_encryption_key_file, + ack_key: value.keys.ack_key_file, + gateway_shared_key: value.keys.gateway_shared_key_file, credential_database_path: value.credentials_database, - reply_surb_database_path: value.reply_surb_database_path, + reply_surb_database_path: value.reply_surb_database, } } } diff --git a/service-providers/network-requester/src/cli/init.rs b/service-providers/network-requester/src/cli/init.rs index 1ed2bbb7d1..c5992ea2ee 100644 --- a/service-providers/network-requester/src/cli/init.rs +++ b/service-providers/network-requester/src/cli/init.rs @@ -137,7 +137,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), NetworkRequesterError> { // Setup gateway by either registering a new one, or creating a new config from the selected // one but with keys kept, or reusing the gateway configuration. - let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys_paths.clone()); + let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone()); let gateway = nym_client_core::init::setup_gateway_from_config::<_>( &key_store, register_gateway, @@ -163,7 +163,7 @@ pub(crate) async fn execute(args: &Init) -> Result<(), NetworkRequesterError> { ); let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys( - &config.storage_paths.common_paths.keys_paths, + &config.storage_paths.common_paths.keys, &config.base.client.gateway_endpoint, )?;