From d9f88ca51547f786280205bd16e96ad40671d917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 27 Oct 2023 12:17:17 +0100 Subject: [PATCH] ibid. for the gateway --- gateway/src/commands/helpers.rs | 5 +++ gateway/src/commands/init.rs | 52 +++++++++++++----------- gateway/src/commands/run.rs | 6 +++ gateway/src/config/mod.rs | 25 ++++++++++++ gateway/src/config/old_config_v1_1_29.rs | 4 ++ gateway/src/config/old_config_v1_1_31.rs | 1 + gateway/src/config/template.rs | 6 +++ gateway/src/node/mod.rs | 9 +++- mixnode/src/config/old_config_v1_1_32.rs | 1 + 9 files changed, 84 insertions(+), 25 deletions(-) diff --git a/gateway/src/commands/helpers.rs b/gateway/src/commands/helpers.rs index 3b97212ae6..13d7b97765 100644 --- a/gateway/src/commands/helpers.rs +++ b/gateway/src/commands/helpers.rs @@ -38,6 +38,7 @@ pub(crate) struct OverrideConfig { pub(crate) statistics_service_url: Option, pub(crate) nym_apis: Option>, pub(crate) mnemonic: Option, + pub(crate) enforce_forward_travel: Option, pub(crate) nyxd_urls: Option>, pub(crate) only_coconut_credentials: Option, pub(crate) with_network_requester: Option, @@ -52,6 +53,10 @@ impl OverrideConfig { .with_optional(Config::with_listening_address, self.listening_address) .with_optional(Config::with_mix_port, self.mix_port) .with_optional(Config::with_clients_port, self.clients_port) + .with_optional( + Config::with_enforce_forward_travel, + self.enforce_forward_travel, + ) .with_optional_custom_env( Config::with_custom_nym_apis, self.nym_apis, diff --git a/gateway/src/commands/init.rs b/gateway/src/commands/init.rs index bfa12bd66d..e13c5452ec 100644 --- a/gateway/src/commands/init.rs +++ b/gateway/src/commands/init.rs @@ -20,41 +20,41 @@ use super::helpers::OverrideIpPacketRouterConfig; #[derive(Args, Clone)] pub struct Init { /// Id of the gateway we want to create config for - #[clap(long)] + #[arg(long)] id: String, /// The listening address on which the gateway will be receiving sphinx packets and listening for client data - #[clap(long, alias = "host")] + #[arg(long, alias = "host")] listening_address: IpAddr, /// Comma separated list of public ip addresses that will announced to the nym-api and subsequently to the clients. /// In nearly all circumstances, it's going to be identical to the address you're going to use for bonding. - #[clap(long, value_delimiter = ',')] + #[arg(long, value_delimiter = ',')] public_ips: Option>, /// Optional hostname associated with this gateway that will announced to the nym-api and subsequently to the clients - #[clap(long)] + #[arg(long)] hostname: Option, /// The port on which the gateway will be listening for sphinx packets - #[clap(long)] + #[arg(long)] mix_port: Option, /// The port on which the gateway will be listening for clients gateway-requests - #[clap(long)] + #[arg(long)] clients_port: Option, /// Path to sqlite database containing all gateway persistent data - #[clap(long)] + #[arg(long)] datastore: Option, /// Comma separated list of endpoints of nym APIs - #[clap(long, alias = "validator_apis", value_delimiter = ',')] + #[arg(long, alias = "validator_apis", value_delimiter = ',')] // the alias here is included for backwards compatibility (1.1.4 and before) nym_apis: Option>, /// Comma separated list of endpoints of the validator - #[clap( + #[arg( long, alias = "validators", alias = "nyxd_validators", @@ -65,47 +65,52 @@ pub struct Init { nyxd_urls: Option>, /// Cosmos wallet mnemonic needed for double spending protection - #[clap(long)] + #[arg(long)] mnemonic: Option, /// Set this gateway to work only with coconut credentials; that would disallow clients to /// bypass bandwidth credential requirement - #[clap(long, hide = true)] + #[arg(long, hide = true)] only_coconut_credentials: Option, /// Enable/disable gateway anonymized statistics that get sent to a statistics aggregator server - #[clap(long)] + #[arg(long)] enabled_statistics: Option, /// URL where a statistics aggregator is running. The default value is a Nym aggregator server - #[clap(long)] + #[arg(long)] statistics_service_url: Option, + /// Specifies whether this node should accepts and send out packets that would only go to nodes + /// on the next mix layer + #[arg(long)] + enforce_forward_travel: bool, + /// Allows this gateway to run an embedded network requester for minimal network overhead - #[clap(long, conflicts_with = "with_ip_packet_router")] + #[arg(long, conflicts_with = "with_ip_packet_router")] with_network_requester: bool, /// Allows this gateway to run an embedded network requester for minimal network overhead - #[clap(long, hide = true, conflicts_with = "with_network_requester")] + #[arg(long, hide = true, conflicts_with = "with_network_requester")] with_ip_packet_router: bool, // ##### NETWORK REQUESTER FLAGS ##### /// Specifies whether this network requester should run in 'open-proxy' mode - #[clap(long, requires = "with_network_requester")] + #[arg(long, requires = "with_network_requester")] open_proxy: Option, /// Enable service anonymized statistics that get sent to a statistics aggregator server - #[clap(long, requires = "with_network_requester")] + #[arg(long, requires = "with_network_requester")] enable_statistics: Option, /// Mixnet client address where a statistics aggregator is running. The default value is a Nym /// aggregator client - #[clap(long, requires = "with_network_requester")] + #[arg(long, requires = "with_network_requester")] statistics_recipient: Option, /// Mostly debug-related option to increase default traffic rate so that you would not need to /// modify config post init - #[clap( + #[arg( long, hide = true, conflicts_with = "medium_toggle", @@ -114,7 +119,7 @@ pub struct Init { fastmode: bool, /// Disable loop cover traffic and the Poisson rate limiter (for debugging only) - #[clap( + #[arg( long, hide = true, conflicts_with = "medium_toggle", @@ -124,7 +129,7 @@ pub struct Init { /// Enable medium mixnet traffic, for experiments only. /// This includes things like disabling cover traffic, no per hop delays, etc. - #[clap( + #[arg( long, hide = true, conflicts_with = "no_cover", @@ -136,10 +141,10 @@ pub struct Init { /// Specifies whether this network requester will run using the default ExitPolicy /// as opposed to the allow list. /// Note: this setting will become the default in the future releases. - #[clap(long)] + #[arg(long)] with_exit_policy: Option, - #[clap(short, long, default_value_t = OutputFormat::default())] + #[arg(short, long, default_value_t = OutputFormat::default())] output: OutputFormat, } @@ -154,6 +159,7 @@ impl From for OverrideConfig { datastore: init_config.datastore, nym_apis: init_config.nym_apis, mnemonic: init_config.mnemonic, + enforce_forward_travel: Some(init_config.enforce_forward_travel), enabled_statistics: init_config.enabled_statistics, statistics_service_url: init_config.statistics_service_url, diff --git a/gateway/src/commands/run.rs b/gateway/src/commands/run.rs index 76f7629de5..2621ea549f 100644 --- a/gateway/src/commands/run.rs +++ b/gateway/src/commands/run.rs @@ -108,6 +108,11 @@ pub struct Run { #[arg(long)] statistics_recipient: Option, + /// Specifies whether this node should accepts and send out packets that would only go to nodes + /// on the next mix layer + #[arg(long)] + enforce_forward_travel: Option, + /// Mostly debug-related option to increase default traffic rate so that you would not need to /// modify config post init #[arg(long, hide = true, conflicts_with = "medium_toggle")] @@ -157,6 +162,7 @@ impl From for OverrideConfig { datastore: run_config.datastore, nym_apis: run_config.nym_apis, mnemonic: run_config.mnemonic, + enforce_forward_travel: run_config.enforce_forward_travel, enabled_statistics: run_config.enabled_statistics, statistics_service_url: run_config.statistics_service_url, diff --git a/gateway/src/config/mod.rs b/gateway/src/config/mod.rs index ff021048d5..18900d5378 100644 --- a/gateway/src/config/mod.rs +++ b/gateway/src/config/mod.rs @@ -188,11 +188,13 @@ impl Config { self } + #[must_use] pub fn with_enabled_network_requester(mut self, enabled_network_requester: bool) -> Self { self.network_requester.enabled = enabled_network_requester; self } + #[must_use] pub fn with_default_network_requester_config_path(mut self) -> Self { self.storage_paths = self .storage_paths @@ -212,36 +214,43 @@ impl Config { self } + #[must_use] pub fn with_only_coconut_credentials(mut self, only_coconut_credentials: bool) -> Self { self.gateway.only_coconut_credentials = only_coconut_credentials; self } + #[must_use] pub fn with_enabled_statistics(mut self, enabled_statistics: bool) -> Self { self.gateway.enabled_statistics = enabled_statistics; self } + #[must_use] pub fn with_custom_statistics_service_url(mut self, statistics_service_url: Url) -> Self { self.gateway.statistics_service_url = statistics_service_url; self } + #[must_use] pub fn with_custom_nym_apis(mut self, nym_api_urls: Vec) -> Self { self.gateway.nym_api_urls = nym_api_urls; self } + #[must_use] pub fn with_custom_validator_nyxd(mut self, validator_nyxd_urls: Vec) -> Self { self.gateway.nyxd_urls = validator_nyxd_urls; self } + #[must_use] pub fn with_cosmos_mnemonic(mut self, cosmos_mnemonic: bip39::Mnemonic) -> Self { self.gateway.cosmos_mnemonic = cosmos_mnemonic; self } + #[must_use] pub fn with_listening_address(mut self, listening_address: IpAddr) -> Self { self.gateway.listening_address = listening_address; @@ -253,16 +262,25 @@ impl Config { self } + #[must_use] pub fn with_mix_port(mut self, port: u16) -> Self { self.gateway.mix_port = port; self } + #[must_use] pub fn with_clients_port(mut self, port: u16) -> Self { self.gateway.clients_port = port; self } + #[must_use] + pub fn with_enforce_forward_travel(mut self, forward_travel: bool) -> Self { + self.debug.enforce_forward_travel = forward_travel; + self + } + + #[must_use] pub fn with_custom_persistent_store(mut self, store_dir: PathBuf) -> Self { self.storage_paths.clients_storage = store_dir; self @@ -422,6 +440,10 @@ pub struct Debug { /// Number of messages from offline client that can be pulled at once from the storage. pub message_retrieval_limit: i64, + /// Specifies whether this node should accepts and send out packets that would only go to nodes + /// on the next mix layer. + pub enforce_forward_travel: bool, + /// Specifies whether the mixnode should be using the legacy framing for the sphinx packets. // it's set to true by default. The reason for that decision is to preserve compatibility with the // existing nodes whilst everyone else is upgrading and getting the code for handling the new field. @@ -439,6 +461,9 @@ impl Default for Debug { maximum_connection_buffer_size: DEFAULT_MAXIMUM_CONNECTION_BUFFER_SIZE, stored_messages_filename_length: DEFAULT_STORED_MESSAGE_FILENAME_LENGTH, message_retrieval_limit: DEFAULT_MESSAGE_RETRIEVAL_LIMIT, + + // let's keep it disabled for now to not surprise operators/users + enforce_forward_travel: false, use_legacy_framed_packet_version: false, } } diff --git a/gateway/src/config/old_config_v1_1_29.rs b/gateway/src/config/old_config_v1_1_29.rs index 48ca3d14fb..0e753b0518 100644 --- a/gateway/src/config/old_config_v1_1_29.rs +++ b/gateway/src/config/old_config_v1_1_29.rs @@ -166,6 +166,10 @@ impl From for ConfigV1_1_31 { stored_messages_filename_length: value.debug.stored_messages_filename_length, message_retrieval_limit: value.debug.message_retrieval_limit, use_legacy_framed_packet_version: value.debug.use_legacy_framed_packet_version, + + // \/ ADDED + // enforce forward travel, et al. + ..Default::default() // /\ ADDED }, } } diff --git a/gateway/src/config/old_config_v1_1_31.rs b/gateway/src/config/old_config_v1_1_31.rs index 18841a4993..a1891744c2 100644 --- a/gateway/src/config/old_config_v1_1_31.rs +++ b/gateway/src/config/old_config_v1_1_31.rs @@ -163,6 +163,7 @@ impl From for Config { presence_sending_delay: value.debug.presence_sending_delay, stored_messages_filename_length: value.debug.stored_messages_filename_length, message_retrieval_limit: value.debug.message_retrieval_limit, + enforce_forward_travel: false, use_legacy_framed_packet_version: value.debug.use_legacy_framed_packet_version, }, } diff --git a/gateway/src/config/template.rs b/gateway/src/config/template.rs index 1b6ac71262..58ffd6265e 100644 --- a/gateway/src/config/template.rs +++ b/gateway/src/config/template.rs @@ -116,4 +116,10 @@ ip_packet_router_config = '{{ storage_paths.ip_packet_router_config }}' # TODO +[debug] + +# Specifies whether this node should accepts and send out packets that would only go to nodes +# on the next mix layer. +enforce_forward_travel = {{ debug.enforce_forward_travel }} + "#; diff --git a/gateway/src/node/mod.rs b/gateway/src/node/mod.rs index 469c8eacb8..f059b055df 100644 --- a/gateway/src/node/mod.rs +++ b/gateway/src/node/mod.rs @@ -253,8 +253,13 @@ impl Gateway { let nyxd_endpoints = self.config.gateway.nyxd_urls.clone(); let network = NymNetworkDetails::new_from_env(); - let mut provider = - AllowedAddressesProvider::new(identity, nyxd_endpoints, Some(network)).await?; + let mut provider = AllowedAddressesProvider::new( + identity, + nyxd_endpoints, + !self.config.debug.enforce_forward_travel, + Some(network), + ) + .await?; let filters = (provider.ingress(), provider.egress()); diff --git a/mixnode/src/config/old_config_v1_1_32.rs b/mixnode/src/config/old_config_v1_1_32.rs index b92ce57897..9043269033 100644 --- a/mixnode/src/config/old_config_v1_1_32.rs +++ b/mixnode/src/config/old_config_v1_1_32.rs @@ -257,6 +257,7 @@ impl From for Debug { packet_forwarding_maximum_backoff: value.packet_forwarding_maximum_backoff, initial_connection_timeout: value.initial_connection_timeout, maximum_connection_buffer_size: value.maximum_connection_buffer_size, + enforce_forward_travel: false, use_legacy_framed_packet_version: value.use_legacy_framed_packet_version, } }