-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
// Copyright 2023 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::default_config_filepath; | ||
use crate::config::old_config_v1_1_30::ConfigV1_1_30; | ||
use crate::config::persistence::NymConnectPaths; | ||
use crate::config::{default_config_filepath, Config}; | ||
use crate::error::Result; | ||
use nym_bin_common::logging::LoggingSettings; | ||
use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2; | ||
use nym_client_core::config::GatewayEndpointConfig; | ||
use nym_config::read_config_from_toml_file; | ||
pub use nym_socks5_client_core::config::old_config_v1_1_20_2::ConfigV1_1_20_2 as CoreConfigV1_1_20_2; | ||
pub use nym_socks5_client_core::config::old_config_v1_1_30::ConfigV1_1_30 as CoreConfigV1_1_30; | ||
use serde::{Deserialize, Serialize}; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
pub use nym_socks5_client_core::config::old_config_v1_1_20_2::ConfigV1_1_20_2 as CoreConfigV1_1_20_2; | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone)] | ||
pub struct SocksClientPathsV1_1_20_2 { | ||
#[serde(flatten)] | ||
|
@@ -41,10 +42,10 @@ impl ConfigV1_1_20_2 { | |
|
||
// in this upgrade, gateway endpoint configuration was moved out of the config file, | ||
// so its returned to be stored elsewhere. | ||
pub fn upgrade(self) -> Result<(Config, GatewayEndpointConfig)> { | ||
pub fn upgrade(self) -> Result<(ConfigV1_1_30, GatewayEndpointConfig)> { | ||
let gateway_details = self.core.base.client.gateway_endpoint.clone().into(); | ||
let config = Config { | ||
core: CoreConfigV1_1_30::from(self.core).into(), | ||
let config = ConfigV1_1_30 { | ||
core: self.core.into(), | ||
storage_paths: NymConnectPaths { | ||
common_paths: self.storage_paths.common_paths.upgrade_default()?, | ||
}, | ||
|
40 changes: 40 additions & 0 deletions
40
nym-connect/desktop/src-tauri/src/config/old_config_v1_1_30.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::persistence::NymConnectPaths; | ||
use crate::config::{default_config_filepath, Config}; | ||
use nym_config::read_config_from_toml_file; | ||
use nym_socks5_client_core::config::old_config_v1_1_30::ConfigV1_1_30 as CoreConfigV1_1_30; | ||
use serde::{Deserialize, Serialize}; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct ConfigV1_1_30 { | ||
pub core: CoreConfigV1_1_30, | ||
|
||
// I'm leaving a landmine here for when the paths actually do change the next time, | ||
// but propagating the change right now (in ALL clients) would be such a hassle..., | ||
// so sorry for the next person looking at it : ) | ||
pub storage_paths: NymConnectPaths, | ||
} | ||
|
||
impl From<ConfigV1_1_30> for Config { | ||
fn from(value: ConfigV1_1_30) -> Self { | ||
Config { | ||
core: value.core.into(), | ||
storage_paths: value.storage_paths, | ||
} | ||
} | ||
} | ||
|
||
impl ConfigV1_1_30 { | ||
pub fn read_from_toml_file<P: AsRef<Path>>(path: P) -> io::Result<Self> { | ||
read_config_from_toml_file(path) | ||
} | ||
|
||
pub fn read_from_default_path<P: AsRef<Path>>(id: P) -> io::Result<Self> { | ||
Self::read_from_toml_file(default_config_filepath(id)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright 2022-2023 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::config::old_config_v1_1_30::ConfigV1_1_30; | ||
use crate::config::persistence::NymConnectPaths; | ||
use crate::{ | ||
config::{ | ||
old_config_v1_1_13::OldConfigV1_1_13, old_config_v1_1_20::ConfigV1_1_20, | ||
|
@@ -18,10 +20,12 @@ use nym_client_core::{ | |
error::ClientCoreError, | ||
}; | ||
|
||
fn persist_gateway_details(config: &Config, details: GatewayEndpointConfig) -> Result<()> { | ||
let details_store = | ||
OnDiskGatewayDetails::new(&config.storage_paths.common_paths.gateway_details); | ||
let keys_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone()); | ||
fn persist_gateway_details( | ||
storage_paths: &NymConnectPaths, | ||
details: GatewayEndpointConfig, | ||
) -> Result<()> { | ||
let details_store = OnDiskGatewayDetails::new(&storage_paths.common_paths.gateway_details); | ||
let keys_store = OnDiskKeys::new(storage_paths.common_paths.keys.clone()); | ||
let shared_keys = keys_store.ephemeral_load_gateway_keys().map_err(|source| { | ||
BackendError::ClientCoreError { | ||
source: ClientCoreError::KeyStoreError { | ||
|
@@ -52,9 +56,10 @@ fn try_upgrade_v1_1_13_config(id: &str) -> Result<bool> { | |
|
||
let updated_step1: ConfigV1_1_20 = old_config.into(); | ||
let updated_step2: ConfigV1_1_20_2 = updated_step1.into(); | ||
let (updated, gateway_config) = updated_step2.upgrade()?; | ||
persist_gateway_details(&updated, gateway_config)?; | ||
let (updated_step3, gateway_config) = updated_step2.upgrade()?; | ||
persist_gateway_details(&updated_step3.storage_paths, gateway_config)?; | ||
|
||
let updated: Config = updated_step3.into(); | ||
updated.save_to_default_location()?; | ||
Ok(true) | ||
} | ||
|
@@ -72,9 +77,10 @@ fn try_upgrade_v1_1_20_config(id: &str) -> Result<bool> { | |
info!("It is going to get updated to the current specification."); | ||
|
||
let updated_step1: ConfigV1_1_20_2 = old_config.into(); | ||
let (updated, gateway_config) = updated_step1.upgrade()?; | ||
persist_gateway_details(&updated, gateway_config)?; | ||
let (updated_step2, gateway_config) = updated_step1.upgrade()?; | ||
persist_gateway_details(&updated_step2.storage_paths, gateway_config)?; | ||
|
||
let updated: Config = updated_step2.into(); | ||
updated.save_to_default_location()?; | ||
Ok(true) | ||
} | ||
|
@@ -89,9 +95,25 @@ fn try_upgrade_v1_1_20_2_config(id: &str) -> Result<bool> { | |
info!("It seems the client is using <= v1.1.20_2 config template."); | ||
info!("It is going to get updated to the current specification."); | ||
|
||
let (updated, gateway_config) = old_config.upgrade()?; | ||
persist_gateway_details(&updated, gateway_config)?; | ||
let (updated_step1, gateway_config) = old_config.upgrade()?; | ||
persist_gateway_details(&updated_step1.storage_paths, gateway_config)?; | ||
|
||
let updated: Config = updated_step1.into(); | ||
updated.save_to_default_location()?; | ||
Ok(true) | ||
} | ||
|
||
fn try_upgrade_v1_1_30_config(id: &str) -> Result<bool> { | ||
// explicitly load it as v1.1.20_2 (which is incompatible with the current one, i.e. +1.1.21) | ||
let Ok(old_config) = ConfigV1_1_30::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 client is using <= v1.1.30 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) | ||
} | ||
|
@@ -107,6 +129,9 @@ pub fn try_upgrade_config(id: &str) -> Result<()> { | |
if try_upgrade_v1_1_20_2_config(id)? { | ||
return Ok(()); | ||
} | ||
if try_upgrade_v1_1_30_config(id)? { | ||
return Ok(()); | ||
} | ||
|
||
Ok(()) | ||
} |