From c0ffbb0cb2a5ce5be38a5f0eec9c7c9dcb0fc1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Thu, 15 Dec 2022 11:21:40 +0000 Subject: [PATCH] Fix multi-surb backwards compatibility in pre 1.1.4 client config files (#2703) * Defaulting to 'false' value for 'send_anonymously' in socks5 config if not present * Created method to change all empty core client config fields to their default values * Using default values for surb reply storage in 'run' command if left unset --- clients/client-core/src/config/mod.rs | 44 ++++++++++++++++++------- clients/native/src/commands/run.rs | 4 +++ clients/socks5/src/client/config/mod.rs | 1 + clients/socks5/src/commands/run.rs | 4 +++ 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/clients/client-core/src/config/mod.rs b/clients/client-core/src/config/mod.rs index 0ce94ba646..0ec88a8095 100644 --- a/clients/client-core/src/config/mod.rs +++ b/clients/client-core/src/config/mod.rs @@ -88,16 +88,28 @@ impl Config { where T: NymConfig, { - let id = id.into(); + self.client.id = id.into(); + self.set_empty_fields_to_defaults(); + self + } + + pub fn set_empty_fields_to_defaults(&mut self) -> bool + where + T: NymConfig, + { + let id = &self.client.id; + let mut changes_made = false; // identity key setting if self.client.private_identity_key_file.as_os_str().is_empty() { + changes_made = true; self.client.private_identity_key_file = - self::Client::::default_private_identity_key_file(&id); + self::Client::::default_private_identity_key_file(id); } if self.client.public_identity_key_file.as_os_str().is_empty() { + changes_made = true; self.client.public_identity_key_file = - self::Client::::default_public_identity_key_file(&id); + self::Client::::default_public_identity_key_file(id); } // encryption key setting @@ -107,8 +119,9 @@ impl Config { .as_os_str() .is_empty() { + changes_made = true; self.client.private_encryption_key_file = - self::Client::::default_private_encryption_key_file(&id); + self::Client::::default_private_encryption_key_file(id); } if self .client @@ -116,32 +129,35 @@ impl Config { .as_os_str() .is_empty() { + changes_made = true; self.client.public_encryption_key_file = - self::Client::::default_public_encryption_key_file(&id); + self::Client::::default_public_encryption_key_file(id); } // shared gateway key setting if self.client.gateway_shared_key_file.as_os_str().is_empty() { + changes_made = true; self.client.gateway_shared_key_file = - self::Client::::default_gateway_shared_key_file(&id); + self::Client::::default_gateway_shared_key_file(id); } // ack key setting if self.client.ack_key_file.as_os_str().is_empty() { - self.client.ack_key_file = self::Client::::default_ack_key_file(&id); + changes_made = true; + self.client.ack_key_file = self::Client::::default_ack_key_file(id); } if self.client.reply_surb_database_path.as_os_str().is_empty() { + changes_made = true; self.client.reply_surb_database_path = - self::Client::::default_reply_surb_database_path(&id); + self::Client::::default_reply_surb_database_path(id); } if self.client.database_path.as_os_str().is_empty() { - self.client.database_path = self::Client::::default_database_path(&id); + changes_made = true; + self.client.database_path = self::Client::::default_database_path(id); } - - self.client.id = id; - self + changes_made } pub fn with_disabled_credentials(&mut self, disabled_credentials_mode: bool) { @@ -438,6 +454,10 @@ pub struct Client { database_path: PathBuf, /// Path to the persistent store for received reply surbs, unused encryption keys and used sender tags. + // this was set to use #[serde(default)] for the purposes of compatibility for multi-surbs introduced in 1.1.4. + // if you're reading this message and we have already introduced some breaking changes, feel free + // to remove that attribute since at this point the client configs should have gotten regenerated + #[serde(default)] reply_surb_database_path: PathBuf, /// nym_home_directory specifies absolute path to the home nym Clients directory. diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index 4267fcbac5..5eb6939944 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -103,6 +103,10 @@ pub(crate) async fn execute(args: &Run) -> Result<(), ClientError> { let override_config_fields = OverrideConfig::from(args.clone()); config = override_config(config, override_config_fields); + if config.get_base_mut().set_empty_fields_to_defaults() { + warn!("some of the core config options were left unset. the default values are going to get used instead."); + } + if !version_check(&config) { error!("failed the local version check"); return Err(ClientError::FailedLocalVersionCheck); diff --git a/clients/socks5/src/client/config/mod.rs b/clients/socks5/src/client/config/mod.rs index 97372e4c86..cda73334d3 100644 --- a/clients/socks5/src/client/config/mod.rs +++ b/clients/socks5/src/client/config/mod.rs @@ -143,6 +143,7 @@ pub struct Socks5 { /// slower and consume nearly double the bandwidth as it will require sending reply SURBs. /// /// Note that some service providers might not support this. + #[serde(default)] send_anonymously: bool, } diff --git a/clients/socks5/src/commands/run.rs b/clients/socks5/src/commands/run.rs index 612ecc02c2..48d4651d15 100644 --- a/clients/socks5/src/commands/run.rs +++ b/clients/socks5/src/commands/run.rs @@ -120,6 +120,10 @@ pub(crate) async fn execute(args: &Run) -> Result<(), Box