nym-connect config updates

This commit is contained in:
Jędrzej Stuczyński
2023-06-02 15:52:30 +01:00
parent 728542181e
commit eb06285653
3 changed files with 57 additions and 56 deletions
+13 -12
View File
@@ -52,7 +52,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Config {
pub socks5: Socks5CoreConfig,
pub core: Socks5CoreConfig,
pub storage_paths: NymConnectPaths,
}
@@ -70,7 +70,7 @@ pub fn socks5_config_id_appended_with(gateway_id: &str) -> String {
impl Config {
pub fn new<S: AsRef<str>>(id: S, provider_mix_address: S) -> Self {
Config {
socks5: Socks5CoreConfig::new(id.as_ref(), provider_mix_address.as_ref()),
core: Socks5CoreConfig::new(id.as_ref(), provider_mix_address.as_ref()),
storage_paths: NymConnectPaths::new_default(default_data_directory(id.as_ref())),
}
}
@@ -84,7 +84,7 @@ impl Config {
}
pub fn default_location(&self) -> PathBuf {
default_config_filepath(&self.socks5.base.client.id)
default_config_filepath(&self.core.base.client.id)
}
pub fn save_to_default_location(&self) -> io::Result<()> {
@@ -101,6 +101,7 @@ impl Config {
// The client initialization was originally not written for this use case, so there are
// lots of ways it can panic. Until we have proper error handling in the init code for the
// clients we'll catch any panics here by spawning a new runtime in a separate thread.
// JS: why are we spawning a new thread here?
std::thread::spawn(move || {
tokio::runtime::Runtime::new()
.expect("Failed to create tokio runtime")
@@ -147,7 +148,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
let mut config = Config::new(&id, &provider_address);
if let Ok(raw_validators) = std::env::var(nym_config_common::defaults::var_names::NYM_API) {
config.socks5.base.client.nym_api_urls = nym_config_common::parse_urls(&raw_validators);
config.core.base.client.nym_api_urls = nym_config_common::parse_urls(&raw_validators);
}
let chosen_gateway_id = identity::PublicKey::from_base58_string(chosen_gateway_id)
@@ -159,13 +160,13 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
&key_store,
register_gateway,
Some(chosen_gateway_id),
&config.socks5.base,
&config.core.base,
// TODO: another instance where this setting should probably get used
false,
)
.await?;
config.socks5.base.set_gateway_endpoint(gateway);
config.core.base.set_gateway_endpoint(gateway);
config.save_to_default_location().tap_err(|_| {
log::error!("Failed to save the config file");
@@ -175,7 +176,7 @@ pub async fn init_socks5_config(provider_address: String, chosen_gateway_id: Str
let address = nym_client_core::init::get_client_address_from_stored_ondisk_keys(
&config.storage_paths.common_paths.keys,
&config.socks5.base.client.gateway_endpoint,
&config.core.base.client.gateway_endpoint,
)?;
log::info!("The address of this client is: {}", address);
Ok(())
@@ -186,19 +187,19 @@ fn print_saved_config(config: &Config) {
"Saved configuration file to {}",
config.default_location().display()
);
log::info!("Gateway id: {}", config.socks5.base.get_gateway_id());
log::info!("Gateway owner: {}", config.socks5.base.get_gateway_owner());
log::info!("Gateway id: {}", config.core.base.get_gateway_id());
log::info!("Gateway owner: {}", config.core.base.get_gateway_owner());
log::info!(
"Gateway listener: {}",
config.socks5.base.get_gateway_listener()
config.core.base.get_gateway_listener()
);
log::info!(
"Service provider address: {}",
config.socks5.socks5.provider_mix_address
config.core.socks5.provider_mix_address
);
log::info!(
"Service provider port: {}",
config.socks5.socks5.listening_port
config.core.socks5.listening_port
);
log::info!("Client configuration completed.");
}
@@ -1,97 +1,97 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
// While using normal toml marshalling would have been way simpler with less overhead,
// I think it's useful to have comments attached to the saved config file to explain behaviour of
// particular fields.
// Note: any changes to the template must be reflected in the appropriate structs.
pub(crate) const CONFIG_TEMPLATE: &str = r#"
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
##### main base client config options #####
[client]
[core.client]
# Version of the client for which this configuration was created.
version = '{{ client.version }}'
version = '{{ core.client.version }}'
# Human readable ID of this particular client.
id = '{{ client.id }}'
id = '{{ core.client.id }}'
# Indicates whether this client is running in a disabled credentials mode, thus attempting
# to claim bandwidth without presenting bandwidth credentials.
disabled_credentials_mode = {{ client.disabled_credentials_mode }}
disabled_credentials_mode = {{ core.client.disabled_credentials_mode }}
# Addresses to nyxd validators via which the client can communicate with the chain.
nyxd_urls = [
{{#each client.nyxd_urls }}
{{#each core.client.nyxd_urls }}
'{{this}}',
{{/each}}
]
# Addresses to APIs running on validator from which the client gets the view of the network.
nym_api_urls = [
{{#each client.nym_api_urls }}
{{#each core.client.nym_api_urls }}
'{{this}}',
{{/each}}
]
[storage_paths]
# Path to file containing private identity key.
private_identity_key_file = '{{ client.private_identity_key_file }}'
keys.private_identity_key_file = '{{ storage_paths.keys.private_identity_key_file }}'
# Path to file containing public identity key.
public_identity_key_file = '{{ client.public_identity_key_file }}'
keys.public_identity_key_file = '{{ storage_paths.keys.public_identity_key_file }}'
# Path to file containing private encryption key.
private_encryption_key_file = '{{ client.private_encryption_key_file }}'
keys.private_encryption_key_file = '{{ storage_paths.keys.private_encryption_key_file }}'
# Path to file containing public encryption key.
public_encryption_key_file = '{{ client.public_encryption_key_file }}'
# Path to the database containing bandwidth credentials
database_path = '{{ client.database_path }}'
# Path to the persistent store for received reply surbs, unused encryption keys and used sender tags.
reply_surb_database_path = '{{ client.reply_surb_database_path }}'
##### additional client config options #####
keys.public_encryption_key_file = '{{ storage_paths.keys.public_encryption_key_file }}'
# A gateway specific, optional, base58 stringified shared key used for
# communication with particular gateway.
gateway_shared_key_file = '{{ client.gateway_shared_key_file }}'
keys.gateway_shared_key_file = '{{ storage_paths.keys.gateway_shared_key_file }}'
# Path to file containing key used for encrypting and decrypting the content of an
# acknowledgement so that nobody besides the client knows which packet it refers to.
ack_key_file = '{{ client.ack_key_file }}'
keys.ack_key_file = '{{ storage_paths.keys.ack_key_file }}'
##### advanced configuration options #####
# Path to the database containing bandwidth credentials
credentials_database = '{{ storage_paths.credentials_database }}'
# Absolute path to the home Nym Clients directory.
nym_root_directory = '{{ client.nym_root_directory }}'
# Path to the persistent store for received reply surbs, unused encryption keys and used sender tags.
reply_surb_database = '{{ storage_paths.reply_surb_database }}'
[client.gateway_endpoint]
# DEPRECATED
[core.client.gateway_endpoint]
# ID of the gateway from which the client should be fetching messages.
gateway_id = '{{ client.gateway_endpoint.gateway_id }}'
gateway_id = '{{ core.client.gateway_endpoint.gateway_id }}'
# Address of the gateway owner to which the client should send messages.
gateway_owner = '{{ client.gateway_endpoint.gateway_owner }}'
gateway_owner = '{{ core.client.gateway_endpoint.gateway_owner }}'
# Address of the gateway listener to which all client requests should be sent.
gateway_listener = '{{ client.gateway_endpoint.gateway_listener }}'
gateway_listener = '{{ core.client.gateway_endpoint.gateway_listener }}'
##### socket config options #####
[socks5]
[core.socks5]
# The mix address of the provider to which all requests are going to be sent.
provider_mix_address = '{{ socks5.provider_mix_address }}'
provider_mix_address = '{{ core.socks5.provider_mix_address }}'
# The port on which the client will be listening for incoming requests
listening_port = {{ socks5.listening_port }}
listening_port = {{ core.socks5.listening_port }}
# Specifies whether this client is going to use an anonymous sender tag for communication with the service provider.
# While this is going to hide its actual address information, it will make the actual communication
# slower and consume nearly double the bandwidth as it will require sending reply SURBs.
#
# Note that some service providers might not support this.
send_anonymously = {{ socks5.send_anonymously }}
send_anonymously = {{ core.socks5.send_anonymously }}
##### logging configuration options #####
@@ -104,19 +104,19 @@ send_anonymously = {{ socks5.send_anonymously }}
# The following options should not be modified unless you know EXACTLY what you are doing
# as if set incorrectly, they may impact your anonymity.
# [socks5.socks5_debug]
# [core.socks5.socks5_debug]
[debug]
[core.debug]
[debug.traffic]
average_packet_delay = '{{ debug.traffic.average_packet_delay }}'
message_sending_average_delay = '{{ debug.traffic.message_sending_average_delay }}'
[core.debug.traffic]
average_packet_delay = '{{ core.debug.traffic.average_packet_delay }}'
message_sending_average_delay = '{{ core.debug.traffic.message_sending_average_delay }}'
[debug.acknowledgements]
average_ack_delay = '{{ debug.acknowledgements.average_ack_delay }}'
[core.debug.acknowledgements]
average_ack_delay = '{{ core.debug.acknowledgements.average_ack_delay }}'
[debug.cover_traffic]
loop_cover_traffic_average_delay = '{{ debug.cover_traffic.loop_cover_traffic_average_delay }}'
[core.debug.cover_traffic]
loop_cover_traffic_average_delay = '{{ core.debug.cover_traffic.loop_cover_traffic_average_delay }}'
"#;
+3 -3
View File
@@ -40,7 +40,7 @@ pub fn start_nym_socks5_client(
log::info!("Loading config from file: {id}");
let config = Config::read_from_default_path(id)
.tap_err(|_| log::warn!("Failed to load configuration file"))?;
let used_gateway = config.socks5.base.client.gateway_endpoint.clone();
let used_gateway = config.core.base.client.gateway_endpoint.clone();
log::info!("Starting socks5 client");
@@ -63,10 +63,10 @@ pub fn start_nym_socks5_client(
.block_on(async move {
let storage = OnDiskPersistent::from_paths(
config.storage_paths.common_paths,
&config.socks5.base.debug,
&config.core.base.debug,
)
.await?;
let socks5_client = Socks5NymClient::new(config.socks5, storage);
let socks5_client = Socks5NymClient::new(config.core, storage);
socks5_client
.run_and_listen(socks5_ctrl_rx, socks5_status_tx)