ibid for network requester
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
use crate::config::old_config_v1_1_13::OldConfigV1_1_13;
|
||||
use crate::config::old_config_v1_1_20::ConfigV1_1_20;
|
||||
use crate::config::old_config_v1_1_20_2::ConfigV1_1_20_2;
|
||||
use crate::config::old_config_v1_1_33::ConfigV1_1_33;
|
||||
use crate::{
|
||||
config::{BaseClientConfig, Config},
|
||||
error::NetworkRequesterError,
|
||||
@@ -170,22 +171,34 @@ fn persist_gateway_details(
|
||||
config: &Config,
|
||||
details: GatewayEndpointConfig,
|
||||
) -> Result<(), NetworkRequesterError> {
|
||||
let details_store =
|
||||
OnDiskGatewayDetails::new(&config.storage_paths.common_paths.gateway_details);
|
||||
let keys_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone());
|
||||
let shared_keys = keys_store.ephemeral_load_gateway_keys().map_err(|source| {
|
||||
NetworkRequesterError::ClientCoreError(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| {
|
||||
NetworkRequesterError::ClientCoreError(ClientCoreError::GatewayDetailsStoreError {
|
||||
source: Box::new(source),
|
||||
})
|
||||
})
|
||||
todo!()
|
||||
// let details_store =
|
||||
// OnDiskGatewayDetails::new(&config.storage_paths.common_paths.gateway_details);
|
||||
// let keys_store = OnDiskKeys::new(config.storage_paths.common_paths.keys.clone());
|
||||
// let shared_keys = keys_store.ephemeral_load_gateway_keys().map_err(|source| {
|
||||
// NetworkRequesterError::ClientCoreError(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| {
|
||||
// NetworkRequesterError::ClientCoreError(ClientCoreError::GatewayDetailsStoreError {
|
||||
// source: Box::new(source),
|
||||
// })
|
||||
// })
|
||||
}
|
||||
|
||||
fn migrate_gateway_details(
|
||||
config: &Config,
|
||||
old_details: Option<GatewayEndpointConfig>,
|
||||
) -> Result<(), NetworkRequesterError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn extract_gateway_details(config: &ConfigV1_1_33) -> Result<(), NetworkRequesterError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn try_upgrade_v1_1_13_config(id: &str) -> Result<bool, NetworkRequesterError> {
|
||||
@@ -203,8 +216,10 @@ fn try_upgrade_v1_1_13_config(id: &str) -> Result<bool, NetworkRequesterError> {
|
||||
|
||||
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()?;
|
||||
let updated = updated_step3.try_upgrade()?;
|
||||
|
||||
migrate_gateway_details(&updated, Some(gateway_config))?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
@@ -225,8 +240,10 @@ fn try_upgrade_v1_1_20_config(id: &str) -> Result<bool, NetworkRequesterError> {
|
||||
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()?;
|
||||
let updated = updated_step2.try_upgrade()?;
|
||||
|
||||
migrate_gateway_details(&updated, Some(gateway_config))?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
@@ -244,8 +261,28 @@ fn try_upgrade_v1_1_20_2_config(id: &str) -> Result<bool, NetworkRequesterError>
|
||||
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()?;
|
||||
let updated = updated_step1.try_upgrade()?;
|
||||
|
||||
migrate_gateway_details(&updated, Some(gateway_config))?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn try_upgrade_v1_1_33_config(id: &str) -> Result<bool, NetworkRequesterError> {
|
||||
// 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 updated = old_config.try_upgrade()?;
|
||||
|
||||
migrate_gateway_details(&updated, None)?;
|
||||
|
||||
updated.save_to_default_location()?;
|
||||
Ok(true)
|
||||
@@ -262,6 +299,9 @@ fn try_upgrade_config(id: &str) -> Result<(), NetworkRequesterError> {
|
||||
if try_upgrade_v1_1_20_2_config(id)? {
|
||||
return Ok(());
|
||||
}
|
||||
if try_upgrade_v1_1_33_config(id)? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ pub mod old_config_v1_1_20;
|
||||
pub mod old_config_v1_1_20_2;
|
||||
mod persistence;
|
||||
mod template;
|
||||
pub mod old_config_v1_1_33;
|
||||
|
||||
const DEFAULT_NETWORK_REQUESTERS_DIR: &str = "network-requester";
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::config::old_config_v1_1_20_2::{
|
||||
};
|
||||
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, ConfigV1_1_20_2 as BaseClientConfigV1_1_20_2,
|
||||
@@ -47,7 +48,7 @@ impl From<ConfigV1_1_20> for ConfigV1_1_20_2 {
|
||||
network_requester: Default::default(),
|
||||
storage_paths: NetworkRequesterPathsV1_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,
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{
|
||||
config::{
|
||||
default_config_filepath, persistence::NetworkRequesterPaths, Config, Debug,
|
||||
NetworkRequester,
|
||||
},
|
||||
error::NetworkRequesterError,
|
||||
use super::old_config_v1_1_33::{
|
||||
ConfigV1_1_33, DebugV1_1_33, NetworkRequesterPathsV1_1_33, NetworkRequesterV1_1_33,
|
||||
};
|
||||
|
||||
use crate::{config::default_config_filepath, error::NetworkRequesterError};
|
||||
use log::trace;
|
||||
use nym_bin_common::logging::LoggingSettings;
|
||||
use nym_client_core::config::disk_persistence::old_v1_1_20_2::CommonClientPathsV1_1_20_2;
|
||||
@@ -65,7 +61,7 @@ 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), NetworkRequesterError> {
|
||||
pub fn upgrade(self) -> Result<(ConfigV1_1_33, GatewayEndpointConfig), NetworkRequesterError> {
|
||||
trace!("Upgrading from v1.1.20_2");
|
||||
let gateway_details = self.base.client.gateway_endpoint.clone().into();
|
||||
let nr_description = self
|
||||
@@ -76,9 +72,9 @@ impl ConfigV1_1_20_2 {
|
||||
.parent()
|
||||
.expect("config paths upgrade failure")
|
||||
.join(DEFAULT_DESCRIPTION_FILENAME);
|
||||
let config = Config {
|
||||
let config = ConfigV1_1_33 {
|
||||
base: BaseConfigV1_1_30::from(self.base).into(),
|
||||
storage_paths: NetworkRequesterPaths {
|
||||
storage_paths: NetworkRequesterPathsV1_1_33 {
|
||||
common_paths: self.storage_paths.common_paths.upgrade_default()?,
|
||||
allowed_list_location: self.storage_paths.allowed_list_location,
|
||||
unknown_list_location: self.storage_paths.unknown_list_location,
|
||||
@@ -97,9 +93,9 @@ impl ConfigV1_1_20_2 {
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct NetworkRequesterV1_1_20_2 {}
|
||||
|
||||
impl From<NetworkRequesterV1_1_20_2> for NetworkRequester {
|
||||
impl From<NetworkRequesterV1_1_20_2> for NetworkRequesterV1_1_33 {
|
||||
fn from(_value: NetworkRequesterV1_1_20_2) -> Self {
|
||||
NetworkRequester::default()
|
||||
NetworkRequesterV1_1_33::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +107,9 @@ pub struct DebugV1_1_20_2 {
|
||||
pub standard_list_update_interval: Duration,
|
||||
}
|
||||
|
||||
impl From<DebugV1_1_20_2> for Debug {
|
||||
impl From<DebugV1_1_20_2> for DebugV1_1_33 {
|
||||
fn from(value: DebugV1_1_20_2) -> Self {
|
||||
Debug {
|
||||
DebugV1_1_33 {
|
||||
standard_list_update_interval: value.standard_list_update_interval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::persistence::NetworkRequesterPaths;
|
||||
use crate::config::Config;
|
||||
use crate::config::{default_config_filepath, Debug, NetworkRequester};
|
||||
use crate::error::NetworkRequesterError;
|
||||
use nym_bin_common::logging::LoggingSettings;
|
||||
use nym_client_core::config::disk_persistence::old_v1_1_33::CommonClientPathsV1_1_33;
|
||||
use nym_client_core::config::old_config_v1_1_33::ConfigV1_1_33 as BaseConfigV1_1_33;
|
||||
use nym_config::read_config_from_toml_file;
|
||||
use nym_config::serde_helpers::de_maybe_stringified;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
use url::Url;
|
||||
|
||||
pub const DEFAULT_STANDARD_LIST_UPDATE_INTERVAL: Duration = Duration::from_secs(30 * 60);
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone)]
|
||||
pub struct NetworkRequesterPathsV1_1_33 {
|
||||
#[serde(flatten)]
|
||||
pub common_paths: CommonClientPathsV1_1_33,
|
||||
|
||||
/// Location of the file containing our allow.list
|
||||
pub allowed_list_location: PathBuf,
|
||||
|
||||
/// Location of the file containing our unknown.list
|
||||
pub unknown_list_location: PathBuf,
|
||||
|
||||
#[serde(default)]
|
||||
pub nr_description: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ConfigV1_1_33 {
|
||||
pub base: BaseConfigV1_1_33,
|
||||
|
||||
#[serde(default)]
|
||||
pub network_requester: NetworkRequesterV1_1_33,
|
||||
|
||||
pub storage_paths: NetworkRequesterPathsV1_1_33,
|
||||
|
||||
#[serde(default)]
|
||||
pub network_requester_debug: DebugV1_1_33,
|
||||
|
||||
pub logging: LoggingSettings,
|
||||
}
|
||||
|
||||
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, NetworkRequesterError> {
|
||||
Ok(Config {
|
||||
base: self.base.into(),
|
||||
network_requester: self.network_requester.into(),
|
||||
storage_paths: NetworkRequesterPaths {
|
||||
common_paths: self.storage_paths.common_paths.upgrade_default()?,
|
||||
allowed_list_location: self.storage_paths.allowed_list_location,
|
||||
unknown_list_location: self.storage_paths.unknown_list_location,
|
||||
nr_description: self.storage_paths.nr_description,
|
||||
},
|
||||
network_requester_debug: self.network_requester_debug.into(),
|
||||
logging: self.logging,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct NetworkRequesterV1_1_33 {
|
||||
/// specifies whether this network requester should run in 'open-proxy' mode
|
||||
/// and thus would attempt to resolve **ANY** request it receives.
|
||||
pub open_proxy: bool,
|
||||
|
||||
/// specifies whether this network requester would send anonymized statistics to a statistics aggregator server
|
||||
pub enabled_statistics: bool,
|
||||
|
||||
/// in case of enabled statistics, specifies mixnet client address where a statistics aggregator is running
|
||||
pub statistics_recipient: Option<String>,
|
||||
|
||||
/// Disable Poisson sending rate.
|
||||
/// This is equivalent to setting debug.traffic.disable_main_poisson_packet_distribution = true,
|
||||
pub disable_poisson_rate: bool,
|
||||
|
||||
/// Specifies whether this network requester should be using the deprecated allow-list,
|
||||
/// as opposed to the new ExitPolicy.
|
||||
/// Note: this field will be removed in a near future.
|
||||
pub use_deprecated_allow_list: bool,
|
||||
|
||||
/// Specifies the url for an upstream source of the exit policy used by this node.
|
||||
#[serde(deserialize_with = "de_maybe_stringified")]
|
||||
pub upstream_exit_policy_url: Option<Url>,
|
||||
}
|
||||
|
||||
impl From<NetworkRequesterV1_1_33> for NetworkRequester {
|
||||
fn from(value: NetworkRequesterV1_1_33) -> Self {
|
||||
NetworkRequester {
|
||||
open_proxy: value.open_proxy,
|
||||
enabled_statistics: value.enabled_statistics,
|
||||
statistics_recipient: value.statistics_recipient,
|
||||
disable_poisson_rate: value.disable_poisson_rate,
|
||||
use_deprecated_allow_list: value.use_deprecated_allow_list,
|
||||
upstream_exit_policy_url: value.upstream_exit_policy_url,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct DebugV1_1_33 {
|
||||
/// Defines how often the standard allow list should get updated
|
||||
#[serde(with = "humantime_serde")]
|
||||
pub standard_list_update_interval: Duration,
|
||||
}
|
||||
|
||||
impl From<DebugV1_1_33> for Debug {
|
||||
fn from(value: DebugV1_1_33) -> Self {
|
||||
Debug {
|
||||
standard_list_update_interval: value.standard_list_update_interval,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DebugV1_1_33 {
|
||||
fn default() -> Self {
|
||||
DebugV1_1_33 {
|
||||
standard_list_update_interval: DEFAULT_STANDARD_LIST_UPDATE_INTERVAL,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,6 @@ pub struct NetworkRequesterPaths {
|
||||
pub unknown_list_location: PathBuf,
|
||||
|
||||
/// Location of the file containing our description
|
||||
// For upgrade use default if missing. On next config upgrade iteration, remove the serde(default)
|
||||
#[serde(default)]
|
||||
pub nr_description: PathBuf,
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,7 @@ pub use nym_client_core::{
|
||||
},
|
||||
init::{
|
||||
setup_gateway,
|
||||
types::{
|
||||
CustomGatewayDetails, GatewayDetails, GatewaySelectionSpecification, GatewaySetup,
|
||||
InitResults, InitialisationResult,
|
||||
},
|
||||
types::{GatewaySelectionSpecification, GatewaySetup, InitResults, InitialisationResult},
|
||||
},
|
||||
};
|
||||
pub use request_filter::RequestFilter;
|
||||
|
||||
Reference in New Issue
Block a user