diff --git a/gateway/src/commands/upgrade_helpers.rs b/gateway/src/commands/upgrade_helpers.rs index acba5ec1f2..07c424a9c8 100644 --- a/gateway/src/commands/upgrade_helpers.rs +++ b/gateway/src/commands/upgrade_helpers.rs @@ -6,7 +6,6 @@ use nym_gateway::config::old_config_v1_1_20::ConfigV1_1_20; use nym_gateway::config::old_config_v1_1_28::ConfigV1_1_28; use nym_gateway::config::old_config_v1_1_29::ConfigV1_1_29; use nym_gateway::config::old_config_v1_1_31::ConfigV1_1_31; -use nym_gateway::config::old_config_v1_1_36::ConfigV1_1_36; use nym_gateway::config::{default_config_filepath, Config}; use nym_gateway::error::GatewayError; @@ -25,8 +24,7 @@ fn try_upgrade_v1_1_20_config(id: &str) -> Result { let updated_step1: ConfigV1_1_28 = old_config.into(); let updated_step2: ConfigV1_1_29 = updated_step1.into(); let updated_step3: ConfigV1_1_31 = updated_step2.into(); - let updated_step4: ConfigV1_1_36 = updated_step3.into(); - let updated: Config = updated_step4.into(); + let updated: Config = updated_step3.into(); updated .save_to_default_location() .map_err(|err| GatewayError::ConfigSaveFailure { @@ -50,8 +48,7 @@ fn try_upgrade_v1_1_28_config(id: &str) -> Result { let updated_step1: ConfigV1_1_29 = old_config.into(); let updated_step2: ConfigV1_1_31 = updated_step1.into(); - let updated_step3: ConfigV1_1_36 = updated_step2.into(); - let updated: Config = updated_step3.into(); + let updated: Config = updated_step2.into(); updated .save_to_default_location() .map_err(|err| GatewayError::ConfigSaveFailure { @@ -74,30 +71,6 @@ fn try_upgrade_v1_1_29_config(id: &str) -> Result { info!("It is going to get updated to the current specification."); let updated_step1: ConfigV1_1_31 = old_config.into(); - let updated_step2: ConfigV1_1_36 = updated_step1.into(); - let updated: Config = updated_step2.into(); - updated - .save_to_default_location() - .map_err(|err| GatewayError::ConfigSaveFailure { - path: default_config_filepath(id), - id: id.to_string(), - source: err, - })?; - - Ok(true) -} - -fn try_upgrade_v1_1_31_config(id: &str) -> Result { - // explicitly load it as v1.1.30 (which is incompatible with the current, i.e. 1.1.31+) - let Ok(old_config) = ConfigV1_1_36::read_from_default_path(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 gateway is using <= v1.1.30 config template."); - info!("It is going to get updated to the current specification."); - - let updated_step1: ConfigV1_1_36 = old_config.into(); let updated: Config = updated_step1.into(); updated .save_to_default_location() @@ -110,9 +83,9 @@ fn try_upgrade_v1_1_31_config(id: &str) -> Result { Ok(true) } -fn try_upgrade_v1_1_36_config(id: &str) -> Result { +fn try_upgrade_v1_1_31_config(id: &str) -> Result { // explicitly load it as v1.1.35 (which is incompatible with the current, i.e. 1.1.36+) - let Ok(old_config) = ConfigV1_1_36::read_from_default_path(id) else { + let Ok(old_config) = ConfigV1_1_31::read_from_default_path(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); @@ -145,9 +118,6 @@ pub(crate) fn try_upgrade_config(id: &str) -> Result<(), GatewayError> { if try_upgrade_v1_1_31_config(id)? { return Ok(()); } - if try_upgrade_v1_1_36_config(id)? { - return Ok(()); - } Ok(()) } diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index 5e5073b466..e5c2ab7ff6 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -26,7 +26,6 @@ pub mod old_config_v1_1_20; pub mod old_config_v1_1_28; pub mod old_config_v1_1_29; pub mod old_config_v1_1_31; -pub mod old_config_v1_1_36; pub mod persistence; mod template; diff --git a/gateway/src/config/old_config_v1_1_31.rs b/gateway/src/config/old_config_v1_1_31.rs index e027b7310d..2c4760003f 100644 --- a/gateway/src/config/old_config_v1_1_31.rs +++ b/gateway/src/config/old_config_v1_1_31.rs @@ -12,11 +12,9 @@ use std::path::{Path, PathBuf}; use std::time::Duration; use url::Url; -use super::old_config_v1_1_36::{ - ConfigV1_1_36, DebugV1_1_36, GatewayPathsV1_1_36, GatewayV1_1_36, KeysPathsV1_1_36, - LoggingSettingsV1_1_36, NetworkRequesterV1_1_36, WireguardPathsV1_1_36, WireguardV1_1_36, -}; use super::{Host, Http}; +use crate::config::persistence::paths::KeysPaths; +use crate::config::{Config, Debug, Gateway, GatewayPaths, LoggingSettings, NetworkRequester}; const DEFAULT_GATEWAYS_DIR: &str = "gateways"; @@ -106,13 +104,13 @@ impl ConfigV1_1_31 { } } -impl From for ConfigV1_1_36 { +impl From for Config { fn from(value: ConfigV1_1_31) -> Self { Self { save_path: value.save_path, host: value.host, http: value.http, - gateway: GatewayV1_1_36 { + gateway: Gateway { version: value.gateway.version, id: value.gateway.id, only_coconut_credentials: value.gateway.only_coconut_credentials, @@ -126,17 +124,8 @@ impl From for ConfigV1_1_36 { nyxd_urls: value.gateway.nyxd_urls, cosmos_mnemonic: value.gateway.cosmos_mnemonic, }, - wireguard: WireguardV1_1_36 { - enabled: value.wireguard.enabled, - bind_address: value.wireguard.bind_address, - announced_port: value.wireguard.announced_port, - private_network_prefix: Default::default(), - storage_paths: WireguardPathsV1_1_36 { - // no fields (yet) - }, - }, - storage_paths: GatewayPathsV1_1_36 { - keys: KeysPathsV1_1_36 { + storage_paths: GatewayPaths { + keys: KeysPaths { private_identity_key_file: value.storage_paths.keys.private_identity_key_file, public_identity_key_file: value.storage_paths.keys.public_identity_key_file, private_sphinx_key_file: value.storage_paths.keys.private_sphinx_key_file, @@ -148,16 +137,16 @@ impl From for ConfigV1_1_36 { ip_packet_router_config: Default::default(), // /\ ADDED }, - network_requester: NetworkRequesterV1_1_36 { + network_requester: NetworkRequester { enabled: value.network_requester.enabled, }, // \/ ADDED ip_packet_router: Default::default(), // /\ ADDED - logging: LoggingSettingsV1_1_36 { + logging: LoggingSettings { // no fields (yet) }, - debug: DebugV1_1_36 { + debug: Debug { packet_forwarding_initial_backoff: value.debug.packet_forwarding_initial_backoff, packet_forwarding_maximum_backoff: value.debug.packet_forwarding_maximum_backoff, initial_connection_timeout: value.debug.initial_connection_timeout, diff --git a/gateway/src/config/old_config_v1_1_36.rs b/gateway/src/config/old_config_v1_1_36.rs deleted file mode 100644 index 64e44b4578..0000000000 --- a/gateway/src/config/old_config_v1_1_36.rs +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright 2020-2023 - Nym Technologies SA -// SPDX-License-Identifier: GPL-3.0-only - -use crate::config::persistence::paths::GatewayPaths; -use nym_bin_common::logging::LoggingSettings; -use nym_config::{ - must_get_home, read_config_from_toml_file, DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_FILENAME, NYM_DIR, -}; -use nym_network_defaults::WG_PORT; -use serde::{Deserialize, Deserializer, Serialize}; -use std::io; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use std::path::{Path, PathBuf}; -use std::time::Duration; -use url::Url; - -use super::persistence::paths::KeysPaths; -use super::{Config, Debug, Gateway, Host, Http, IpPacketRouter, NetworkRequester}; - -const DEFAULT_GATEWAYS_DIR: &str = "gateways"; - -// 'DEBUG' -// where applicable, the below are defined in milliseconds -const DEFAULT_PRESENCE_SENDING_DELAY: Duration = Duration::from_millis(10_000); -const DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF: Duration = Duration::from_millis(10_000); -const DEFAULT_PACKET_FORWARDING_MAXIMUM_BACKOFF: Duration = Duration::from_millis(300_000); -const DEFAULT_INITIAL_CONNECTION_TIMEOUT: Duration = Duration::from_millis(1_500); -const DEFAULT_MAXIMUM_CONNECTION_BUFFER_SIZE: usize = 2000; - -const DEFAULT_STORED_MESSAGE_FILENAME_LENGTH: u16 = 16; -const DEFAULT_MESSAGE_RETRIEVAL_LIMIT: i64 = 100; - -fn de_maybe_port<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - let port = u16::deserialize(deserializer)?; - if port == 0 { - Ok(None) - } else { - Ok(Some(port)) - } -} - -fn de_maybe_path<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - let path = PathBuf::deserialize(deserializer)?; - if path.as_os_str().is_empty() { - Ok(None) - } else { - Ok(Some(path)) - } -} - -/// Derive default path to gateway's config directory. -/// It should get resolved to `$HOME/.nym/gateways//config` -pub fn default_config_directory>(id: P) -> PathBuf { - must_get_home() - .join(NYM_DIR) - .join(DEFAULT_GATEWAYS_DIR) - .join(id) - .join(DEFAULT_CONFIG_DIR) -} - -/// Derive default path to gateways's config file. -/// It should get resolved to `$HOME/.nym/gateways//config/config.toml` -pub fn default_config_filepath>(id: P) -> PathBuf { - default_config_directory(id).join(DEFAULT_CONFIG_FILENAME) -} - -#[derive(Debug, Deserialize, PartialEq, Serialize)] -#[serde(deny_unknown_fields)] -pub struct ConfigV1_1_36 { - // additional metadata holding on-disk location of this config file - #[serde(skip)] - pub(crate) save_path: Option, - - pub host: Host, - - #[serde(default)] - pub http: Http, - - pub gateway: GatewayV1_1_36, - - #[serde(default)] - // currently not really used for anything useful - pub wireguard: WireguardV1_1_36, - - pub storage_paths: GatewayPathsV1_1_36, - - pub network_requester: NetworkRequesterV1_1_36, - - #[serde(default)] - pub ip_packet_router: IpPacketRouterV1_1_36, - - #[serde(default)] - pub logging: LoggingSettingsV1_1_36, - - #[serde(default)] - pub debug: DebugV1_1_36, -} - -impl ConfigV1_1_36 { - pub fn read_from_default_path>(id: P) -> io::Result { - read_config_from_toml_file(default_config_filepath(id)) - } -} - -impl From for Config { - fn from(value: ConfigV1_1_36) -> Self { - Self { - save_path: value.save_path, - host: value.host, - http: value.http, - gateway: Gateway { - version: value.gateway.version, - id: value.gateway.id, - only_coconut_credentials: value.gateway.only_coconut_credentials, - listening_address: value.gateway.listening_address, - mix_port: value.gateway.mix_port, - clients_port: value.gateway.clients_port, - clients_wss_port: value.gateway.clients_wss_port, - enabled_statistics: value.gateway.enabled_statistics, - statistics_service_url: value.gateway.statistics_service_url, - nym_api_urls: value.gateway.nym_api_urls, - nyxd_urls: value.gateway.nyxd_urls, - cosmos_mnemonic: value.gateway.cosmos_mnemonic, - }, - storage_paths: GatewayPaths { - keys: KeysPaths { - private_identity_key_file: value.storage_paths.keys.private_identity_key_file, - public_identity_key_file: value.storage_paths.keys.public_identity_key_file, - private_sphinx_key_file: value.storage_paths.keys.private_sphinx_key_file, - public_sphinx_key_file: value.storage_paths.keys.public_sphinx_key_file, - }, - clients_storage: value.storage_paths.clients_storage, - network_requester_config: value.storage_paths.network_requester_config, - ip_packet_router_config: value.storage_paths.ip_packet_router_config, - // \/ ADDED - wireguard_config: Default::default(), - // /\ ADDED - }, - network_requester: NetworkRequester { - enabled: value.network_requester.enabled, - }, - ip_packet_router: IpPacketRouter { - enabled: value.ip_packet_router.enabled, - }, - logging: LoggingSettings { - // no fields (yet) - }, - debug: Debug { - packet_forwarding_initial_backoff: value.debug.packet_forwarding_initial_backoff, - packet_forwarding_maximum_backoff: value.debug.packet_forwarding_maximum_backoff, - initial_connection_timeout: value.debug.initial_connection_timeout, - maximum_connection_buffer_size: value.debug.maximum_connection_buffer_size, - presence_sending_delay: value.debug.presence_sending_delay, - stored_messages_filename_length: value.debug.stored_messages_filename_length, - message_retrieval_limit: value.debug.message_retrieval_limit, - use_legacy_framed_packet_version: value.debug.use_legacy_framed_packet_version, - ..Default::default() - }, - } - } -} - -#[derive(Debug, Deserialize, PartialEq, Eq, Serialize)] -pub struct GatewayV1_1_36 { - /// Version of the gateway for which this configuration was created. - pub version: String, - - /// ID specifies the human readable ID of this particular gateway. - pub id: String, - - /// Indicates whether this gateway is accepting only coconut credentials for accessing the - /// the mixnet, or if it also accepts non-paying clients - #[serde(default)] - pub only_coconut_credentials: bool, - - /// Address to which this mixnode will bind to and will be listening for packets. - pub listening_address: IpAddr, - - /// Port used for listening for all mixnet traffic. - /// (default: 1789) - pub mix_port: u16, - - /// Port used for listening for all client-related traffic. - /// (default: 9000) - pub clients_port: u16, - - /// If applicable, announced port for listening for secure websocket client traffic. - /// (default: None) - #[serde(deserialize_with = "de_maybe_port")] - pub clients_wss_port: Option, - - /// Whether gateway collects and sends anonymized statistics - pub enabled_statistics: bool, - - /// Domain address of the statistics service - pub statistics_service_url: Url, - - /// Addresses to APIs from which the node gets the view of the network. - #[serde(alias = "validator_api_urls")] - pub nym_api_urls: Vec, - - /// Addresses to validators which the node uses to check for double spending of ERC20 tokens. - #[serde(alias = "validator_nymd_urls")] - pub nyxd_urls: Vec, - - /// Mnemonic of a cosmos wallet used in checking for double spending. - // #[deprecated(note = "move to storage")] - // TODO: I don't think this should be stored directly in the config... - pub cosmos_mnemonic: bip39::Mnemonic, -} - -#[derive(Debug, Deserialize, PartialEq, Serialize)] -#[serde(default)] -#[serde(deny_unknown_fields)] -pub struct WireguardV1_1_36 { - /// Specifies whether the wireguard service is enabled on this node. - pub enabled: bool, - - /// Socket address this node will use for binding its wireguard interface. - /// default: `0.0.0.0:51820` - pub bind_address: SocketAddr, - - /// Port announced to external clients wishing to connect to the wireguard interface. - /// Useful in the instances where the node is behind a proxy. - pub announced_port: u16, - - /// Paths for wireguard keys, client registries, etc. - pub storage_paths: WireguardPathsV1_1_36, - - /// The prefix denoting the maximum number of the clients that can be connected via Wireguard. - /// The maximum value for IPv4 is 32 and for IPv6 is 128 - pub private_network_prefix: u8, -} - -impl Default for WireguardV1_1_36 { - fn default() -> Self { - Self { - enabled: false, - bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), WG_PORT), - announced_port: WG_PORT, - storage_paths: WireguardPathsV1_1_36 {}, - private_network_prefix: 16, - } - } -} - -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] -#[serde(deny_unknown_fields)] -pub struct WireguardPathsV1_1_36 { - // pub keys: -} - -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] -#[serde(deny_unknown_fields)] -pub struct GatewayPathsV1_1_36 { - pub keys: KeysPathsV1_1_36, - - /// Path to sqlite database containing all persistent data: messages for offline clients, - /// derived shared keys and available client bandwidths. - #[serde(alias = "persistent_storage")] - pub clients_storage: PathBuf, - - /// Path to the configuration of the embedded network requester. - #[serde(deserialize_with = "de_maybe_path")] - pub network_requester_config: Option, - // pub node_description: PathBuf, - - // pub cosmos_bip39_mnemonic: PathBuf, - /// Path to the configuration of the embedded ip packet router. - #[serde(deserialize_with = "de_maybe_path")] - pub ip_packet_router_config: Option, -} - -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Serialize)] -pub struct KeysPathsV1_1_36 { - /// Path to file containing private identity key. - pub private_identity_key_file: PathBuf, - - /// Path to file containing public identity key. - pub public_identity_key_file: PathBuf, - - /// Path to file containing private sphinx key. - pub private_sphinx_key_file: PathBuf, - - /// Path to file containing public sphinx key. - pub public_sphinx_key_file: PathBuf, -} - -#[derive(Debug, Deserialize, PartialEq, Serialize)] -#[serde(default)] -pub struct NetworkRequesterV1_1_36 { - /// Specifies whether network requester service is enabled in this process. - pub enabled: bool, -} - -#[allow(clippy::derivable_impls)] -impl Default for NetworkRequesterV1_1_36 { - fn default() -> Self { - Self { enabled: false } - } -} - -#[derive(Debug, Deserialize, PartialEq, Serialize)] -#[serde(default)] -pub struct IpPacketRouterV1_1_36 { - /// Specifies whether ip packet router service is enabled in this process. - pub enabled: bool, -} - -#[allow(clippy::derivable_impls)] -impl Default for IpPacketRouterV1_1_36 { - fn default() -> Self { - Self { enabled: false } - } -} - -#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq, Serialize)] -#[serde(deny_unknown_fields)] -pub struct LoggingSettingsV1_1_36 { - // well, we need to implement something here at some point... -} - -#[derive(Debug, Deserialize, PartialEq, Serialize)] -#[serde(default)] -pub struct DebugV1_1_36 { - /// Initial value of an exponential backoff to reconnect to dropped TCP connection when - /// forwarding sphinx packets. - #[serde(with = "humantime_serde")] - pub packet_forwarding_initial_backoff: Duration, - - /// Maximum value of an exponential backoff to reconnect to dropped TCP connection when - /// forwarding sphinx packets. - #[serde(with = "humantime_serde")] - pub packet_forwarding_maximum_backoff: Duration, - - /// Timeout for establishing initial connection when trying to forward a sphinx packet. - #[serde(with = "humantime_serde")] - pub initial_connection_timeout: Duration, - - /// Maximum number of packets that can be stored waiting to get sent to a particular connection. - pub maximum_connection_buffer_size: usize, - - /// Delay between each subsequent presence data being sent. - #[serde(with = "humantime_serde")] - pub presence_sending_delay: Duration, - - /// Length of filenames for new client messages. - pub stored_messages_filename_length: u16, - - /// Number of messages from offline client that can be pulled at once from the storage. - pub message_retrieval_limit: i64, - - /// Specifies whether the mixnode should be using the legacy framing for the sphinx packets. - // it's set to true by default. The reason for that decision is to preserve compatibility with the - // existing nodes whilst everyone else is upgrading and getting the code for handling the new field. - // It shall be disabled in the subsequent releases. - pub use_legacy_framed_packet_version: bool, -} - -impl Default for DebugV1_1_36 { - fn default() -> Self { - Self { - packet_forwarding_initial_backoff: DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF, - packet_forwarding_maximum_backoff: DEFAULT_PACKET_FORWARDING_MAXIMUM_BACKOFF, - initial_connection_timeout: DEFAULT_INITIAL_CONNECTION_TIMEOUT, - presence_sending_delay: DEFAULT_PRESENCE_SENDING_DELAY, - maximum_connection_buffer_size: DEFAULT_MAXIMUM_CONNECTION_BUFFER_SIZE, - stored_messages_filename_length: DEFAULT_STORED_MESSAGE_FILENAME_LENGTH, - message_retrieval_limit: DEFAULT_MESSAGE_RETRIEVAL_LIMIT, - use_legacy_framed_packet_version: false, - } - } -} diff --git a/gateway/src/config/persistence/paths.rs b/gateway/src/config/persistence/paths.rs index 019c065f14..c416bce4b2 100644 --- a/gateway/src/config/persistence/paths.rs +++ b/gateway/src/config/persistence/paths.rs @@ -48,10 +48,6 @@ pub struct GatewayPaths { /// Path to the configuration of the embedded ip packet router. #[serde(deserialize_with = "de_maybe_stringified")] pub ip_packet_router_config: Option, - - /// Path to the configuration of the wireguard server. - #[serde(deserialize_with = "de_maybe_stringified")] - pub wireguard_config: Option, } impl GatewayPaths { @@ -62,7 +58,6 @@ impl GatewayPaths { // node_description: default_config_filepath(id).join(DEFAULT_DESCRIPTION_FILENAME), network_requester_config: None, ip_packet_router_config: None, - wireguard_config: None, } } @@ -77,7 +72,6 @@ impl GatewayPaths { clients_storage: Default::default(), network_requester_config: None, ip_packet_router_config: None, - wireguard_config: None, } } @@ -100,12 +94,6 @@ impl GatewayPaths { self } - #[must_use] - pub fn with_wireguard_config>(mut self, path: P) -> Self { - self.wireguard_config = Some(path.as_ref().into()); - self - } - #[must_use] pub fn with_default_ip_packet_router_config>(self, id: P) -> Self { self.with_ip_packet_router_config( @@ -121,10 +109,6 @@ impl GatewayPaths { &self.ip_packet_router_config } - pub fn wireguard_config(&self) -> &Option { - &self.wireguard_config - } - pub fn private_identity_key(&self) -> &Path { self.keys.private_identity_key() }