From a6b2158733ca7ac57b22f493e07f173d02b34464 Mon Sep 17 00:00:00 2001 From: max143672 Date: Sun, 1 Oct 2023 22:37:18 +0400 Subject: [PATCH] Switched the 'upnp' variable to 'disable_upnp'. It is now apparent that UPnP is enabled by default and can be deactivated using this flag. --- components/addressmanager/src/lib.rs | 7 ++++++- consensus/core/src/config/mod.rs | 4 ++-- kaspad/src/args.rs | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/components/addressmanager/src/lib.rs b/components/addressmanager/src/lib.rs index 5062b0db1a..59e9ecaed1 100644 --- a/components/addressmanager/src/lib.rs +++ b/components/addressmanager/src/lib.rs @@ -61,10 +61,15 @@ impl AddressManager { info!("Non-publicly routable external ip {} not added to store", local_net_address); None } - None if self.config.upnp => { + None if !self.config.disable_upnp => { let gateway = igd::search_gateway(Default::default()).ok()?; let ip = IpAddress::new(gateway.get_external_ip().ok()?); + if !ip.is_publicly_routable() { + info!("Non-publicly routable external ip from gateway using upnp {} not added to store", ip); + return None; + } info!("Get external ip from gateway using upnp: {ip}"); + let default_port = self.config.default_p2p_port(); let normalized_p2p_listen_address = self.config.p2p_listen_address.normalize(default_port); diff --git a/consensus/core/src/config/mod.rs b/consensus/core/src/config/mod.rs index d70ed971b1..f60b1a9950 100644 --- a/consensus/core/src/config/mod.rs +++ b/consensus/core/src/config/mod.rs @@ -61,7 +61,7 @@ pub struct Config { #[cfg(feature = "devnet-prealloc")] pub initial_utxo_set: Arc, - pub upnp: bool, + pub disable_upnp: bool, } impl Config { @@ -86,7 +86,7 @@ impl Config { #[cfg(feature = "devnet-prealloc")] initial_utxo_set: Default::default(), - upnp: false, + disable_upnp: false, } } diff --git a/kaspad/src/args.rs b/kaspad/src/args.rs index 8b44795d5f..53af8b92d1 100644 --- a/kaspad/src/args.rs +++ b/kaspad/src/args.rs @@ -63,7 +63,7 @@ pub struct Args { #[cfg(feature = "devnet-prealloc")] pub prealloc_amount: u64, - pub upnp: bool, + pub disable_upnp: bool, } impl Default for Args { @@ -108,7 +108,7 @@ impl Default for Args { #[cfg(feature = "devnet-prealloc")] prealloc_amount: 1_000_000, - upnp: false, + disable_upnp: false, } } } @@ -116,7 +116,7 @@ impl Default for Args { impl Args { pub fn apply_to_config(&self, config: &mut Config) { config.utxoindex = self.utxoindex; - config.upnp = self.upnp; + config.disable_upnp = self.disable_upnp; config.unsafe_rpc = self.unsafe_rpc; config.enable_unsynced_mining = self.enable_unsynced_mining; config.is_archival = self.archival; @@ -311,7 +311,7 @@ pub fn cli() -> Command { .require_equals(true) .value_parser(clap::value_parser!(u64)) .help("Interval in seconds for performance metrics collection."), - ).arg(arg!(--upnp "Enable upnp")); + ).arg(arg!(--disable-upnp "Disable upnp")); #[cfg(feature = "devnet-prealloc")] let cmd = cmd @@ -368,7 +368,7 @@ pub fn parse_args() -> Args { prealloc_address: m.get_one::("prealloc-address").cloned(), #[cfg(feature = "devnet-prealloc")] prealloc_amount: m.get_one::("prealloc-amount").cloned().unwrap_or(defaults.prealloc_amount), - upnp: m.get_one::("upnp").cloned().unwrap_or(defaults.upnp), + disable_upnp: m.get_one::("upnp").cloned().unwrap_or(defaults.disable_upnp), } }