Skip to content

Commit 44041ae

Browse files
committed
init: Handle dropped UPnP support more gracefully
Closes #843. In that issue it was brought up that users likely don't care what kind of port forwarding is used, and the setting is opportunistic anyway, so instead of showing an extensive warning, we can simply migrate from UPNP to NAT-PMP+PCP. This prevents nodes dropping from the public network. - Change the logic for removed runtime setting `-upnp` to set `-natpmp` instead, and only log a message. - Also replace any lingering `upnp` in `settings.json` with `natpmp`.
1 parent e606c57 commit 44041ae

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/init.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,32 @@ void InitParameterInteraction(ArgsManager& args)
793793
LogInfo("parameter interaction: -onlynet excludes IPv4 and IPv6 -> setting -dnsseed=0\n");
794794
}
795795
}
796+
797+
// If settings.json contains a "upnp" option, migrate it to use "natpmp" instead
798+
bool settings_changed{false}; // Whether settings.json file needs to be rewritten
799+
args.LockSettings([&](common::Settings& settings) {
800+
if (auto* upnp{common::FindKey(settings.rw_settings, "upnp")}) {
801+
if (common::FindKey(settings.rw_settings, "natpmp") == nullptr) {
802+
LogWarning(R"(Adding "natpmp": %s to settings.json to replace obsolete "upnp" setting)", upnp->write());
803+
settings.rw_settings["natpmp"] = *upnp;
804+
}
805+
LogWarning(R"(Removing obsolete "upnp" setting from settings.json)");
806+
settings.rw_settings.erase("upnp");
807+
settings_changed = true;
808+
}
809+
});
810+
if (settings_changed) args.WriteSettingsFile();
811+
812+
// We dropped UPnP support but kept the arg as hidden for now to display a friendlier error to user who has the
813+
// option in their config, and migrate the setting to -natpmp.
814+
if (const auto arg{args.GetBoolArg("-upnp")}) {
815+
std::string message;
816+
if (args.SoftSetBoolArg("-natpmp", *arg)) {
817+
message = strprintf(" Substituting '-natpmp=%s'.", *arg);
818+
}
819+
LogWarning("Option '-upnp=%s' is given but UPnP support was dropped in version 29.0.%s",
820+
*arg, message);
821+
}
796822
}
797823

798824
/**
@@ -874,12 +900,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
874900

875901
// also see: InitParameterInteraction()
876902

877-
// We drop UPnP support but kept the arg as hidden for now to display a friendlier error to user who have the
878-
// option in their config. TODO: remove (here and above) for version 30.0.
879-
if (args.IsArgSet("-upnp")) {
880-
InitWarning(_("Option '-upnp' is set but UPnP support was dropped in version 29.0. Consider using '-natpmp' instead."));
881-
}
882-
883903
// Error if network-specific options (-addnode, -connect, etc) are
884904
// specified in default section of config file, but not overridden
885905
// on the command line or in this chain's section of the config file.

0 commit comments

Comments
 (0)