fixing builds of x86-based binaries
This commit is contained in:
@@ -27,8 +27,9 @@ use crate::{
|
||||
use nym_credential_storage::persistent_storage::PersistentStorage as PersistentCredentialStorage;
|
||||
|
||||
pub use nym_client_core_gateways_storage::{
|
||||
CustomGatewayDetails, GatewayDetails, GatewayRegistration, GatewayType, GatewaysDetailsStore,
|
||||
InMemGatewaysDetails, RegisteredGateway, RemoteGatewayDetails,
|
||||
ActiveGateway, BadGateway, CustomGatewayDetails, GatewayDetails, GatewayRegistration,
|
||||
GatewayType, GatewaysDetailsStore, InMemGatewaysDetails, RegisteredGateway,
|
||||
RemoteGatewayDetails,
|
||||
};
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "fs-gateways-storage"))]
|
||||
|
||||
@@ -320,6 +320,7 @@ pub struct InitResults {
|
||||
pub encryption_key: String,
|
||||
pub gateway_id: String,
|
||||
pub gateway_listener: String,
|
||||
pub gateway_registration: OffsetDateTime,
|
||||
pub address: Recipient,
|
||||
}
|
||||
|
||||
@@ -337,6 +338,7 @@ impl InitResults {
|
||||
encryption_key: address.encryption_key().to_base58_string(),
|
||||
gateway_id: gateway.gateway_id.to_base58_string(),
|
||||
gateway_listener: gateway.gateway_listener.to_string(),
|
||||
gateway_registration: registration,
|
||||
address,
|
||||
}
|
||||
}
|
||||
@@ -349,6 +351,7 @@ impl Display for InitResults {
|
||||
writeln!(f, "Identity key: {}", self.identity_key)?;
|
||||
writeln!(f, "Encryption: {}", self.encryption_key)?;
|
||||
writeln!(f, "Gateway ID: {}", self.gateway_id)?;
|
||||
write!(f, "Gateway: {}", self.gateway_listener)
|
||||
writeln!(f, "Gateway: {}", self.gateway_listener)?;
|
||||
write!(f, "Registered at: {}", self.gateway_registration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub mod topology;
|
||||
pub use nym_bandwidth_controller::BandwidthController;
|
||||
pub use nym_client_core::*;
|
||||
pub use nym_client_core::{
|
||||
client::key_manager::ManagedKeys, error::ClientCoreError, init::types::InitialisationResult,
|
||||
client::key_manager::ClientKeys, error::ClientCoreError, init::types::InitialisationResult,
|
||||
};
|
||||
pub use nym_gateway_client::{error::GatewayClientError, GatewayClient, GatewayConfig};
|
||||
pub use nym_sphinx::{
|
||||
|
||||
@@ -5,10 +5,11 @@ use crate::config::persistence::NymConnectPaths;
|
||||
use crate::config::template::CONFIG_TEMPLATE;
|
||||
use crate::config::upgrade::try_upgrade_config;
|
||||
use crate::error::{BackendError, Result};
|
||||
use nym_client_core::client::base_client::storage::gateway_details::OnDiskGatewayDetails;
|
||||
use nym_client_core::client::base_client::non_wasm_helpers::setup_fs_gateways_storage;
|
||||
use nym_client_core::client::base_client::storage::{GatewayDetails, RemoteGatewayDetails};
|
||||
use nym_client_core::client::key_manager::persistence::OnDiskKeys;
|
||||
use nym_client_core::config::GatewayEndpointConfig;
|
||||
use nym_client_core::error::ClientCoreError;
|
||||
use nym_client_core::init::generate_new_client_keys;
|
||||
use nym_client_core::init::helpers::current_gateways;
|
||||
use nym_client_core::init::types::{GatewaySelectionSpecification, GatewaySetup};
|
||||
use nym_config::{
|
||||
@@ -17,6 +18,7 @@ use nym_config::{
|
||||
};
|
||||
use nym_crypto::asymmetric::identity;
|
||||
use nym_socks5_client_core::config::Config as Socks5CoreConfig;
|
||||
use rand_07::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{fs, io};
|
||||
@@ -26,6 +28,7 @@ mod old_config_v1_1_13;
|
||||
mod old_config_v1_1_20;
|
||||
mod old_config_v1_1_20_2;
|
||||
mod old_config_v1_1_30;
|
||||
mod old_config_v1_1_33;
|
||||
mod persistence;
|
||||
mod template;
|
||||
mod upgrade;
|
||||
@@ -163,24 +166,21 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
|
||||
let already_init = if config_path.exists() {
|
||||
// in case we're using old config, try to upgrade it
|
||||
// (if we're using the current version, it's a no-op)
|
||||
if let Err(err) = try_upgrade_config(&id) {
|
||||
if let Err(err) = try_upgrade_config(&id).await {
|
||||
log::error!(
|
||||
"Failed to upgrade config file {}: {:?}",
|
||||
"Failed to upgrade config file {}: {err}",
|
||||
config_path.display(),
|
||||
err
|
||||
);
|
||||
if let Some(failed_at_version) = try_extract_version_for_upgrade_failure(err) {
|
||||
return Err(
|
||||
return if let Some(failed_at_version) = try_extract_version_for_upgrade_failure(err) {
|
||||
Err(
|
||||
BackendError::CouldNotUpgradeExistingConfigurationFileAtVersion {
|
||||
file: config_path,
|
||||
failed_at_version,
|
||||
},
|
||||
);
|
||||
)
|
||||
} else {
|
||||
return Err(BackendError::CouldNotUpgradeExistingConfigurationFile {
|
||||
file: config_path,
|
||||
});
|
||||
}
|
||||
Err(BackendError::CouldNotUpgradeExistingConfigurationFile { file: config_path })
|
||||
};
|
||||
};
|
||||
eprintln!("SOCKS5 client \"{id}\" was already initialised before");
|
||||
true
|
||||
@@ -189,13 +189,8 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
|
||||
false
|
||||
};
|
||||
|
||||
// Future proofing. This flag exists for the other clients
|
||||
let user_wants_force_register = false;
|
||||
|
||||
// If the client was already initialized, don't generate new keys and don't re-register with
|
||||
// the gateway (because this would create a new shared key).
|
||||
// Unless the user really wants to.
|
||||
let register_gateway = !already_init || user_wants_force_register;
|
||||
// // Future proofing. This flag exists for the other clients
|
||||
// let user_wants_force_register = false;
|
||||
|
||||
log::trace!("Creating config for id: {id}");
|
||||
let mut config = Config::new(&id, &provider_address);
|
||||
@@ -204,7 +199,17 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
|
||||
config.core.base.client.nym_api_urls = nym_config::parse_urls(&raw_validators);
|
||||
}
|
||||
|
||||
let gateway_setup = if register_gateway {
|
||||
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone());
|
||||
let details_store =
|
||||
setup_fs_gateways_storage(&config.storage_paths.common_paths.gateway_registrations).await?;
|
||||
|
||||
// if this is a first time client with this particular id is initialised, generated long-term keys
|
||||
if !already_init {
|
||||
let mut rng = OsRng;
|
||||
generate_new_client_keys(&mut rng, &key_store).await?;
|
||||
}
|
||||
|
||||
let gateway_setup = if !already_init {
|
||||
let selection_spec =
|
||||
GatewaySelectionSpecification::new(Some(chosen_gateway_id), None, false);
|
||||
let mut rng = rand_07::thread_rng();
|
||||
@@ -213,41 +218,40 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
|
||||
GatewaySetup::New {
|
||||
specification: selection_spec,
|
||||
available_gateways,
|
||||
overwrite_data: register_gateway,
|
||||
overwrite_data: true,
|
||||
wg_tun_address: None,
|
||||
}
|
||||
} else {
|
||||
GatewaySetup::MustLoad
|
||||
GatewaySetup::MustLoad {
|
||||
gateway_id: Some(chosen_gateway_id),
|
||||
}
|
||||
};
|
||||
|
||||
// Setup gateway by either registering a new one, or reusing exiting keys
|
||||
let key_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone());
|
||||
let details_store =
|
||||
OnDiskGatewayDetails::new(&config.storage_paths.common_paths.gateway_details);
|
||||
let init_details =
|
||||
nym_client_core::init::setup_gateway(gateway_setup, &key_store, &details_store).await?;
|
||||
let gateway_endpoint = init_details
|
||||
.gateway_details
|
||||
.try_get_configured_endpoint()
|
||||
.unwrap();
|
||||
|
||||
let GatewayDetails::Remote(gateway_details) = &init_details.gateway_registration.details else {
|
||||
return Err(ClientCoreError::UnexpectedPersistedCustomGatewayDetails)?;
|
||||
};
|
||||
|
||||
config.save_to_default_location().tap_err(|_| {
|
||||
log::error!("Failed to save the config file");
|
||||
})?;
|
||||
|
||||
print_saved_config(&config, gateway_endpoint);
|
||||
print_saved_config(&config, gateway_details);
|
||||
|
||||
let address = init_details.client_address()?;
|
||||
let address = init_details.client_address();
|
||||
log::info!("The address of this client is: {address}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_saved_config(config: &Config, gateway_details: &GatewayEndpointConfig) {
|
||||
fn print_saved_config(config: &Config, gateway_details: &RemoteGatewayDetails) {
|
||||
log::info!(
|
||||
"Saved configuration file to {}",
|
||||
config.default_location().display()
|
||||
);
|
||||
log::info!("Gateway id: {}", gateway_details.gateway_id);
|
||||
log::info!("Gateway owner: {}", gateway_details.gateway_owner);
|
||||
log::info!("Gateway owner: {}", gateway_details.gateway_owner_address);
|
||||
log::info!("Gateway listener: {}", gateway_details.gateway_listener);
|
||||
log::info!(
|
||||
"Service provider address: {}",
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::config::old_config_v1_1_20_2::{
|
||||
ConfigV1_1_20_2, CoreConfigV1_1_20_2, SocksClientPathsV1_1_20_2,
|
||||
};
|
||||
use nym_bin_common::logging::LoggingSettings;
|
||||
use nym_client_core::config::disk_persistence::keys_paths::ClientKeysPaths;
|
||||
use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2;
|
||||
use nym_client_core::config::disk_persistence::old_v1_1_33::ClientKeysPathsV1_1_33;
|
||||
use nym_client_core::config::old_config_v1_1_20::ConfigV1_1_20 as BaseConfigV1_1_20;
|
||||
use nym_client_core::config::old_config_v1_1_20_2::ClientV1_1_20_2;
|
||||
use nym_config::legacy_helpers::nym_config::MigrationNymConfig;
|
||||
@@ -50,7 +50,7 @@ impl From<ConfigV1_1_20> for ConfigV1_1_20_2 {
|
||||
},
|
||||
storage_paths: SocksClientPathsV1_1_20_2 {
|
||||
common_paths: CommonClientPathsV1_1_20_2 {
|
||||
keys: ClientKeysPaths {
|
||||
keys: ClientKeysPathsV1_1_33 {
|
||||
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,
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
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::old_config_v1_1_33::NymConnectPathsV1_1_33;
|
||||
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_client_core::config::old_config_v1_1_33::OldGatewayEndpointConfigV1_1_33;
|
||||
use nym_config::read_config_from_toml_file;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io;
|
||||
@@ -42,11 +42,11 @@ 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<(ConfigV1_1_30, GatewayEndpointConfig)> {
|
||||
pub fn upgrade(self) -> Result<(ConfigV1_1_30, OldGatewayEndpointConfigV1_1_33)> {
|
||||
let gateway_details = self.core.base.client.gateway_endpoint.clone().into();
|
||||
let config = ConfigV1_1_30 {
|
||||
core: self.core.into(),
|
||||
storage_paths: NymConnectPaths {
|
||||
storage_paths: NymConnectPathsV1_1_33 {
|
||||
common_paths: self.storage_paths.common_paths.upgrade_default()?,
|
||||
},
|
||||
// logging: self.logging,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::persistence::NymConnectPaths;
|
||||
use crate::config::{default_config_filepath, Config};
|
||||
use crate::config::default_config_filepath;
|
||||
use crate::config::old_config_v1_1_33::{ConfigV1_1_33, NymConnectPathsV1_1_33};
|
||||
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};
|
||||
@@ -14,15 +14,12 @@ use std::path::Path;
|
||||
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,
|
||||
pub storage_paths: NymConnectPathsV1_1_33,
|
||||
}
|
||||
|
||||
impl From<ConfigV1_1_30> for Config {
|
||||
impl From<ConfigV1_1_30> for ConfigV1_1_33 {
|
||||
fn from(value: ConfigV1_1_30) -> Self {
|
||||
Config {
|
||||
ConfigV1_1_33 {
|
||||
core: value.core.into(),
|
||||
storage_paths: value.storage_paths,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::persistence::NymConnectPaths;
|
||||
use crate::config::{default_config_filepath, Config};
|
||||
use crate::error::BackendError;
|
||||
use nym_client_core::config::disk_persistence::old_v1_1_33::CommonClientPathsV1_1_33;
|
||||
use nym_config::read_config_from_toml_file;
|
||||
use nym_socks5_client_core::config::old_config_v1_1_33::ConfigV1_1_33 as CoreConfigV1_1_33;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub struct NymConnectPathsV1_1_33 {
|
||||
#[serde(flatten)]
|
||||
pub common_paths: CommonClientPathsV1_1_33,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ConfigV1_1_33 {
|
||||
pub core: CoreConfigV1_1_33,
|
||||
|
||||
// \/ CHANGED
|
||||
pub storage_paths: NymConnectPathsV1_1_33,
|
||||
// /\ CHANGED
|
||||
}
|
||||
|
||||
impl ConfigV1_1_33 {
|
||||
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))
|
||||
}
|
||||
|
||||
pub fn try_upgrade(self) -> Result<Config, BackendError> {
|
||||
Ok(Config {
|
||||
core: self.core.into(),
|
||||
storage_paths: NymConnectPaths {
|
||||
common_paths: self.storage_paths.common_paths.upgrade_default()?,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,47 +2,18 @@
|
||||
// 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_33::ConfigV1_1_33;
|
||||
use crate::{
|
||||
config::{
|
||||
old_config_v1_1_13::OldConfigV1_1_13, old_config_v1_1_20::ConfigV1_1_20,
|
||||
old_config_v1_1_20_2::ConfigV1_1_20_2, Config,
|
||||
old_config_v1_1_20_2::ConfigV1_1_20_2,
|
||||
},
|
||||
error::{BackendError, Result},
|
||||
error::Result,
|
||||
};
|
||||
use log::{debug, info};
|
||||
use nym_client_core::{
|
||||
client::{
|
||||
base_client::storage::gateway_details::{OnDiskGatewayDetails, PersistedGatewayDetails},
|
||||
key_manager::persistence::OnDiskKeys,
|
||||
},
|
||||
config::GatewayEndpointConfig,
|
||||
error::ClientCoreError,
|
||||
};
|
||||
use nym_client_core::client::base_client::storage::migration_helpers::v1_1_33;
|
||||
|
||||
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 {
|
||||
source: Box::new(source),
|
||||
},
|
||||
}
|
||||
})?;
|
||||
let persisted_details = PersistedGatewayDetails::new(details.into(), Some(&shared_keys))?;
|
||||
details_store
|
||||
.store_to_disk(&persisted_details)
|
||||
.map_err(|source| BackendError::ClientCoreError {
|
||||
source: ClientCoreError::GatewaysDetailsStoreError {
|
||||
source: Box::new(source),
|
||||
},
|
||||
})
|
||||
}
|
||||
fn try_upgrade_v1_1_13_config(id: &str) -> Result<bool> {
|
||||
async fn try_upgrade_v1_1_13_config(id: &str) -> Result<bool> {
|
||||
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)
|
||||
@@ -57,14 +28,23 @@ 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_step3, gateway_config) = updated_step2.upgrade()?;
|
||||
persist_gateway_details(&updated_step3.storage_paths, gateway_config)?;
|
||||
let old_paths = updated_step3.storage_paths.clone();
|
||||
|
||||
let updated_step4: ConfigV1_1_33 = updated_step3.into();
|
||||
let updated = updated_step4.try_upgrade()?;
|
||||
|
||||
v1_1_33::migrate_gateway_details(
|
||||
&old_paths.common_paths,
|
||||
&updated.storage_paths.common_paths,
|
||||
Some(gateway_config),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let updated: Config = updated_step3.into();
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn try_upgrade_v1_1_20_config(id: &str) -> Result<bool> {
|
||||
async fn try_upgrade_v1_1_20_config(id: &str) -> Result<bool> {
|
||||
use nym_config::legacy_helpers::nym_config::MigrationNymConfig;
|
||||
|
||||
// explicitly load it as v1.1.20 (which is incompatible with the current one, i.e. +1.1.21)
|
||||
@@ -78,14 +58,23 @@ fn try_upgrade_v1_1_20_config(id: &str) -> Result<bool> {
|
||||
|
||||
let updated_step1: ConfigV1_1_20_2 = old_config.into();
|
||||
let (updated_step2, gateway_config) = updated_step1.upgrade()?;
|
||||
persist_gateway_details(&updated_step2.storage_paths, gateway_config)?;
|
||||
let old_paths = updated_step2.storage_paths.clone();
|
||||
|
||||
let updated_step3: ConfigV1_1_33 = updated_step2.into();
|
||||
let updated = updated_step3.try_upgrade()?;
|
||||
|
||||
v1_1_33::migrate_gateway_details(
|
||||
&old_paths.common_paths,
|
||||
&updated.storage_paths.common_paths,
|
||||
Some(gateway_config),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let updated: Config = updated_step2.into();
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn try_upgrade_v1_1_20_2_config(id: &str) -> Result<bool> {
|
||||
async fn try_upgrade_v1_1_20_2_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_20_2::read_from_default_path(id) else {
|
||||
// if we failed to load it, there might have been nothing to upgrade
|
||||
@@ -96,14 +85,23 @@ fn try_upgrade_v1_1_20_2_config(id: &str) -> Result<bool> {
|
||||
info!("It is going to get updated to the current specification.");
|
||||
|
||||
let (updated_step1, gateway_config) = old_config.upgrade()?;
|
||||
persist_gateway_details(&updated_step1.storage_paths, gateway_config)?;
|
||||
let old_paths = updated_step1.storage_paths.clone();
|
||||
|
||||
let updated_step2: ConfigV1_1_33 = updated_step1.into();
|
||||
let updated = updated_step2.try_upgrade()?;
|
||||
|
||||
v1_1_33::migrate_gateway_details(
|
||||
&old_paths.common_paths,
|
||||
&updated.storage_paths.common_paths,
|
||||
Some(gateway_config),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let updated: Config = updated_step1.into();
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn try_upgrade_v1_1_30_config(id: &str) -> Result<bool> {
|
||||
async 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
|
||||
@@ -113,23 +111,62 @@ fn try_upgrade_v1_1_30_config(id: &str) -> Result<bool> {
|
||||
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();
|
||||
let old_paths = old_config.storage_paths.clone();
|
||||
|
||||
let updated_step1: ConfigV1_1_33 = old_config.into();
|
||||
let updated = updated_step1.try_upgrade()?;
|
||||
|
||||
v1_1_33::migrate_gateway_details(
|
||||
&old_paths.common_paths,
|
||||
&updated.storage_paths.common_paths,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn try_upgrade_config(id: &str) -> Result<()> {
|
||||
async fn try_upgrade_v1_1_33_config(id: &str) -> Result<bool> {
|
||||
// explicitly load it as v1.1.33 (which is incompatible with the current one, i.e. +1.1.34)
|
||||
let Ok(old_config) = ConfigV1_1_33::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.33 config template.");
|
||||
info!("It is going to get updated to the current specification.");
|
||||
|
||||
let old_paths = old_config.storage_paths.clone();
|
||||
|
||||
let updated = old_config.try_upgrade()?;
|
||||
|
||||
v1_1_33::migrate_gateway_details(
|
||||
&old_paths.common_paths,
|
||||
&updated.storage_paths.common_paths,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub async fn try_upgrade_config(id: &str) -> Result<()> {
|
||||
debug!("Attempting to upgrade config file for \"{id}\"");
|
||||
if try_upgrade_v1_1_13_config(id)? {
|
||||
if try_upgrade_v1_1_13_config(id).await? {
|
||||
return Ok(());
|
||||
}
|
||||
if try_upgrade_v1_1_20_config(id)? {
|
||||
if try_upgrade_v1_1_20_config(id).await? {
|
||||
return Ok(());
|
||||
}
|
||||
if try_upgrade_v1_1_20_2_config(id)? {
|
||||
if try_upgrade_v1_1_20_2_config(id).await? {
|
||||
return Ok(());
|
||||
}
|
||||
if try_upgrade_v1_1_30_config(id)? {
|
||||
if try_upgrade_v1_1_30_config(id).await? {
|
||||
return Ok(());
|
||||
}
|
||||
if try_upgrade_v1_1_33_config(id).await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ pub async fn export_keys(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<
|
||||
|
||||
// Get key paths
|
||||
let ack_key_file = key_paths.ack_key();
|
||||
let gateway_shared_key_file = key_paths.gateway_shared_key();
|
||||
|
||||
let pub_id_key_file = key_paths.public_identity_key();
|
||||
let priv_id_key_file = key_paths.private_identity_key();
|
||||
@@ -64,7 +63,6 @@ pub async fn export_keys(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<
|
||||
|
||||
// Read file contents
|
||||
let ack_key = fs::read_to_string(ack_key_file)?;
|
||||
let gateway_shared_key = fs::read_to_string(gateway_shared_key_file)?;
|
||||
|
||||
let pub_id_key = fs::read_to_string(pub_id_key_file)?;
|
||||
let priv_id_key = fs::read_to_string(priv_id_key_file)?;
|
||||
@@ -73,7 +71,6 @@ pub async fn export_keys(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<
|
||||
let priv_enc_key = fs::read_to_string(priv_enc_key_file)?;
|
||||
|
||||
let ack_key_file = key_filename(&key_paths.ack_key_file)?;
|
||||
let gateway_shared_key_file = key_filename(&key_paths.gateway_shared_key_file)?;
|
||||
let pub_id_key_file = key_filename(&key_paths.public_identity_key_file)?;
|
||||
let priv_id_key_file = key_filename(&key_paths.private_identity_key_file)?;
|
||||
let pub_enc_key_file = key_filename(&key_paths.public_encryption_key_file)?;
|
||||
@@ -82,7 +79,6 @@ pub async fn export_keys(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<
|
||||
// Format and return as json
|
||||
let json = serde_json::json!({
|
||||
ack_key_file: ack_key,
|
||||
gateway_shared_key_file: gateway_shared_key,
|
||||
pub_id_key_file: pub_id_key,
|
||||
priv_id_key_file: priv_id_key,
|
||||
pub_enc_key_file: pub_enc_key,
|
||||
|
||||
@@ -257,13 +257,7 @@ impl State {
|
||||
let (control_tx, msg_rx, exit_status_rx, used_gateway) =
|
||||
tasks::start_nym_socks5_client(&id, &privacy_level).await?;
|
||||
self.socks5_client_sender = Some(control_tx);
|
||||
self.gateway = Some(
|
||||
used_gateway
|
||||
.try_get_configured_endpoint()
|
||||
.unwrap()
|
||||
.gateway_id
|
||||
.clone(),
|
||||
);
|
||||
self.gateway = Some(used_gateway.gateway_id().to_base58_string());
|
||||
Ok((msg_rx, exit_status_rx))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use futures::{channel::mpsc, StreamExt};
|
||||
use nym_client_core::init::types::GatewayDetails;
|
||||
use nym_client_core::client::base_client::storage::{GatewayDetails, GatewaysDetailsStore};
|
||||
use nym_client_core::{
|
||||
client::base_client::storage::{
|
||||
gateway_details::GatewayDetailsStore, MixnetClientStorage, OnDiskPersistent,
|
||||
},
|
||||
client::base_client::storage::{MixnetClientStorage, OnDiskPersistent},
|
||||
config::{GroupBy, TopologyStructure},
|
||||
error::ClientCoreStatusMessage,
|
||||
};
|
||||
@@ -90,10 +88,12 @@ pub async fn start_nym_socks5_client(
|
||||
|
||||
let used_gateway = storage
|
||||
.gateway_details_store()
|
||||
.load_gateway_details()
|
||||
.active_gateway()
|
||||
.await
|
||||
.expect("failed to load gateway details")
|
||||
.into();
|
||||
.expect("failed to load active gateway details")
|
||||
.registration
|
||||
.expect("no active gateway set")
|
||||
.details;
|
||||
|
||||
log::info!("Starting socks5 client");
|
||||
|
||||
|
||||
@@ -277,6 +277,7 @@ where
|
||||
},
|
||||
available_gateways: current_gateways(&mut rng, &nym_apis).await?,
|
||||
overwrite_data: false,
|
||||
wg_tun_address: None,
|
||||
});
|
||||
|
||||
eprintln!("starting the socks5 client");
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
use nym_client_core::client::base_client::storage::{
|
||||
ActiveGateway, BadGateway, GatewayRegistration, GatewaysDetailsStore,
|
||||
};
|
||||
use nym_sdk::mixnet::{
|
||||
self, ClientKeys, EmptyReplyStorage, EphemeralCredentialStorage, KeyStore, MixnetClientStorage,
|
||||
MixnetMessageSender,
|
||||
@@ -106,23 +109,56 @@ impl KeyStore for MockKeyStore {
|
||||
struct MockGatewayDetailsStore;
|
||||
|
||||
#[async_trait]
|
||||
impl GatewayDetailsStore for MockGatewayDetailsStore {
|
||||
impl GatewaysDetailsStore for MockGatewayDetailsStore {
|
||||
type StorageError = MyError;
|
||||
|
||||
async fn load_gateway_details(&self) -> Result<PersistedGatewayDetails, Self::StorageError> {
|
||||
println!("loading stored gateway details");
|
||||
async fn active_gateway(&self) -> Result<ActiveGateway, Self::StorageError> {
|
||||
println!("getting active gateway");
|
||||
|
||||
Err(MyError)
|
||||
}
|
||||
|
||||
async fn set_active_gateway(&self, _gateway_id: &str) -> Result<(), Self::StorageError> {
|
||||
println!("setting active gateway");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn all_gateways(&self) -> Result<Vec<GatewayRegistration>, Self::StorageError> {
|
||||
println!("getting all registered gateways");
|
||||
|
||||
Err(MyError)
|
||||
}
|
||||
|
||||
async fn has_gateway_details(&self, _gateway_id: &str) -> Result<bool, Self::StorageError> {
|
||||
println!("checking for gateway details");
|
||||
|
||||
Err(MyError)
|
||||
}
|
||||
|
||||
async fn load_gateway_details(
|
||||
&self,
|
||||
_gateway_id: &str,
|
||||
) -> Result<GatewayRegistration, Self::StorageError> {
|
||||
println!("loading gateway details");
|
||||
|
||||
Err(MyError)
|
||||
}
|
||||
|
||||
async fn store_gateway_details(
|
||||
&self,
|
||||
_details: &PersistedGatewayDetails,
|
||||
_details: &GatewayRegistration,
|
||||
) -> Result<(), Self::StorageError> {
|
||||
println!("storing gateway details");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_gateway_details(&self, _gateway_id: &str) -> Result<(), Self::StorageError> {
|
||||
println!("removing gateway details");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -178,3 +214,9 @@ impl GatewayDetailsStore for MockGatewayDetailsStore {
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
#[error("foobar")]
|
||||
struct MyError;
|
||||
|
||||
impl From<BadGateway> for MyError {
|
||||
fn from(_: BadGateway) -> Self {
|
||||
MyError
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user