diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index 8f8380349f..bb8295a34e 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -41,7 +41,7 @@ pub(crate) struct Init { /// Whether to not start the websocket #[clap(long)] - disable_socket: bool, + disable_socket: Option, /// Port for the socket (if applicable) to listen on in all subsequent runs #[clap(short, long)] @@ -60,7 +60,7 @@ pub(crate) struct Init { /// with bandwidth credential requirement. #[cfg(feature = "coconut")] #[clap(long)] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, /// Save a summary of the initialization to a json file #[clap(long)] diff --git a/clients/native/src/commands/mod.rs b/clients/native/src/commands/mod.rs index 14ac39056f..f3048c8a22 100644 --- a/clients/native/src/commands/mod.rs +++ b/clients/native/src/commands/mod.rs @@ -54,7 +54,7 @@ pub(crate) enum Commands { // Configuration that can be overridden. pub(crate) struct OverrideConfig { nym_apis: Option>, - disable_socket: bool, + disable_socket: Option, port: Option, fastmode: bool, no_cover: bool, @@ -62,7 +62,7 @@ pub(crate) struct OverrideConfig { #[cfg(feature = "coconut")] nyxd_urls: Option>, #[cfg(feature = "coconut")] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, } pub(crate) async fn execute(args: &Cli) -> Result<(), Box> { @@ -80,7 +80,7 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box Config { config = config - .with_disabled_socket(args.disable_socket) + .with_optional(Config::with_disabled_socket, args.disable_socket) .with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode) .with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover) .with_optional(Config::with_port, args.port) @@ -100,9 +100,9 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi network_defaults::var_names::NYXD, config::parse_urls, ) - .with_base( + .with_optional_ext( BaseConfig::with_disabled_credentials, - !args.enabled_credentials_mode, + args.enabled_credentials_mode.map(|b| !b), ); } diff --git a/clients/native/src/commands/run.rs b/clients/native/src/commands/run.rs index 123bb827e4..47fd3d97e8 100644 --- a/clients/native/src/commands/run.rs +++ b/clients/native/src/commands/run.rs @@ -38,7 +38,7 @@ pub(crate) struct Run { /// Whether to not start the websocket #[clap(long)] - disable_socket: bool, + disable_socket: Option, /// Port for the socket to listen on #[clap(short, long)] @@ -57,7 +57,7 @@ pub(crate) struct Run { /// with bandwidth credential requirement. #[cfg(feature = "coconut")] #[clap(long)] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, } impl From for OverrideConfig { diff --git a/clients/socks5/src/commands/init.rs b/clients/socks5/src/commands/init.rs index 80087a59e6..f9bcf219a8 100644 --- a/clients/socks5/src/commands/init.rs +++ b/clients/socks5/src/commands/init.rs @@ -31,7 +31,7 @@ pub(crate) struct Init { /// Note that some service providers might not support this. // the alias here is included for backwards compatibility (1.1.4 and before) #[clap(long, alias = "use_anonymous_sender_tag")] - use_reply_surbs: bool, + use_reply_surbs: Option, /// Id of the gateway we are going to connect to. #[clap(long)] @@ -69,7 +69,7 @@ pub(crate) struct Init { /// with bandwidth credential requirement. #[cfg(feature = "coconut")] #[clap(long)] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, /// Save a summary of the initialization to a json file #[clap(long)] diff --git a/clients/socks5/src/commands/mod.rs b/clients/socks5/src/commands/mod.rs index a825fb882e..5674a94196 100644 --- a/clients/socks5/src/commands/mod.rs +++ b/clients/socks5/src/commands/mod.rs @@ -57,14 +57,14 @@ pub(crate) enum Commands { pub(crate) struct OverrideConfig { nym_apis: Option>, port: Option, - use_anonymous_replies: bool, + use_anonymous_replies: Option, fastmode: bool, no_cover: bool, #[cfg(feature = "coconut")] nyxd_urls: Option>, #[cfg(feature = "coconut")] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, } pub(crate) async fn execute(args: &Cli) -> Result<(), Box> { @@ -84,7 +84,7 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi config = config .with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode) .with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover) - .with_anonymous_replies(args.use_anonymous_replies) + .with_optional(Config::with_anonymous_replies, args.use_anonymous_replies) .with_optional(Config::with_port, args.port) .with_optional_custom_env_ext( BaseConfig::with_custom_nym_apis, @@ -102,9 +102,9 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi network_defaults::var_names::NYXD, config::parse_urls, ) - .with_base( + .with_optional_ext( BaseConfig::with_disabled_credentials, - !args.enabled_credentials_mode, + args.enabled_credentials_mode.map(|b| !b), ); } diff --git a/clients/socks5/src/commands/run.rs b/clients/socks5/src/commands/run.rs index 9d60479e71..2498ac5148 100644 --- a/clients/socks5/src/commands/run.rs +++ b/clients/socks5/src/commands/run.rs @@ -31,7 +31,7 @@ pub(crate) struct Run { /// Note that some service providers might not support this. // the alias here is included for backwards compatibility (1.1.4 and before) #[clap(long, alias = "use_anonymous_sender_tag")] - use_anonymous_replies: bool, + use_anonymous_replies: Option, /// Address of the socks5 provider to send messages to. #[clap(long)] @@ -68,7 +68,7 @@ pub(crate) struct Run { /// with bandwidth credential requirement. #[cfg(feature = "coconut")] #[clap(long)] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, } impl From for OverrideConfig { diff --git a/gateway/src/commands/init.rs b/gateway/src/commands/init.rs index 040698e582..426962dc30 100644 --- a/gateway/src/commands/init.rs +++ b/gateway/src/commands/init.rs @@ -68,11 +68,11 @@ pub struct Init { /// bypass bandwidth credential requirement #[cfg(feature = "coconut")] #[clap(long)] - only_coconut_credentials: bool, + only_coconut_credentials: Option, /// Enable/disable gateway anonymized statistics that get sent to a statistics aggregator server #[clap(long)] - enabled_statistics: bool, + enabled_statistics: Option, /// URL where a statistics aggregator is running. The default value is a Nym aggregator server #[clap(long)] @@ -182,11 +182,11 @@ mod tests { nym_apis: None, mnemonic: None, statistics_service_url: None, - enabled_statistics: false, + enabled_statistics: None, #[cfg(feature = "coconut")] nyxd_urls: None, #[cfg(feature = "coconut")] - only_coconut_credentials: false, + only_coconut_credentials: None, }; std::env::set_var(BECH32_PREFIX, "n"); diff --git a/gateway/src/commands/mod.rs b/gateway/src/commands/mod.rs index aaf587c8ae..122749624c 100644 --- a/gateway/src/commands/mod.rs +++ b/gateway/src/commands/mod.rs @@ -52,7 +52,7 @@ pub(crate) struct OverrideConfig { clients_port: Option, datastore: Option, announce_host: Option, - enabled_statistics: bool, + enabled_statistics: Option, statistics_service_url: Option, nym_apis: Option>, mnemonic: Option, @@ -60,7 +60,7 @@ pub(crate) struct OverrideConfig { #[cfg(feature = "coconut")] nyxd_urls: Option>, #[cfg(feature = "coconut")] - only_coconut_credentials: bool, + only_coconut_credentials: Option, } pub(crate) async fn execute(args: Cli) { @@ -103,7 +103,7 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi NYM_API, config::parse_urls, ) - .with_enabled_statistics(args.enabled_statistics) + .with_optional(Config::with_enabled_statistics, args.enabled_statistics) .with_optional_env( Config::with_custom_statistics_service_url, args.statistics_service_url, @@ -130,7 +130,10 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi NYXD, config::parse_urls, ) - .with_only_coconut_credentials(args.only_coconut_credentials); + .with_optional( + Config::with_only_coconut_credentials, + args.only_coconut_credentials, + ); } config diff --git a/gateway/src/commands/run.rs b/gateway/src/commands/run.rs index 45a496f511..3198d97029 100644 --- a/gateway/src/commands/run.rs +++ b/gateway/src/commands/run.rs @@ -68,11 +68,11 @@ pub struct Run { /// bypass bandwidth credential requirement #[cfg(feature = "coconut")] #[clap(long)] - only_coconut_credentials: bool, + only_coconut_credentials: Option, /// Enable/disable gateway anonymized statistics that get sent to a statistics aggregator server #[clap(long)] - enabled_statistics: bool, + enabled_statistics: Option, /// URL where a statistics aggregator is running. The default value is a Nym aggregator server #[clap(long)] diff --git a/nym-api/src/main.rs b/nym-api/src/main.rs index 6b6b2313f4..3d54fde175 100644 --- a/nym-api/src/main.rs +++ b/nym-api/src/main.rs @@ -94,11 +94,11 @@ struct ApiArgs { /// Specifies whether network monitoring is enabled on this API #[clap(short = 'm', long)] - enable_monitor: bool, + enable_monitor: Option, /// Specifies whether network rewarding is enabled on this API #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")] - enable_rewarding: bool, + enable_rewarding: Option, /// Endpoint to nyxd instance from which the monitor will grab nodes to test #[clap(long)] @@ -132,7 +132,7 @@ struct ApiArgs { /// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement #[clap(long)] - enabled_credentials_mode: bool, + enabled_credentials_mode: Option, /// Announced address where coconut clients will connect. #[cfg(feature = "coconut")] @@ -142,7 +142,7 @@ struct ApiArgs { /// Flag to indicate whether coconut signer authority is enabled on this API #[cfg(feature = "coconut")] #[clap(long, requires = "mnemonic", requires = "announce-address")] - enable_coconut: bool, + enable_coconut: Option, } async fn wait_for_interrupt(mut shutdown: TaskManager) { @@ -186,15 +186,18 @@ fn override_config(mut config: Config, args: ApiArgs) -> Config { Config::with_min_gateway_reliability, args.min_gateway_reliability, ) - .with_network_monitor_enabled(args.enable_monitor) - .with_rewarding_enabled(args.enable_rewarding) - .with_disabled_credentials_mode(!args.enabled_credentials_mode); + .with_optional(Config::with_network_monitor_enabled, args.enable_monitor) + .with_optional(Config::with_rewarding_enabled, args.enable_rewarding) + .with_optional( + Config::with_disabled_credentials_mode, + args.enabled_credentials_mode.map(|b| !b), + ); #[cfg(feature = "coconut")] { config = config .with_optional(Config::with_announce_address, args.announce_address) - .with_coconut_signer_enabled(args.enable_coconut); + .with_optional(Config::with_coconut_signer_enabled, args.enable_coconut); } if args.save_config {