Skip to content

Commit 15717f0

Browse files
committed
Merge bitcoin/bitcoin#31916: init: Handle dropped UPnP support more gracefully
44041ae init: Handle dropped UPnP support more gracefully (laanwj) Pull request description: Closes #843. In that issue it was brought up that users likely don't care what kind of port forwarding is used, and that the setting is opportunistic anyway, so instead of showing an extensive warning, we can simply "upgrade" from UPNP to NAT-PMP+PCP. - Change the logic for removed runtime setting `-upnp` to set `-natpmp` instead, and log a message. - Also remove any lingering `upnp` from `settings.json` and replace it with `natpmp`, when it makes sense (this is important so that the UI shows the right values in the settings): ```json { "upnp": true } ``` becomes ```json { "natpmp": true } ``` and ```json { "upnp": false } ``` becomes ```json { "natpmp": false } ``` ACKs for top commit: darosior: tACK 44041ae davidgumberg: lightly reviewed code, tested ACK bitcoin/bitcoin@44041ae achow101: ACK 44041ae ryanofsky: Code review ACK 44041ae. Code changes look good. Could potentially add test coverage for this, though I don't think it is too important. hodlinator: cr-ACK 44041ae Tree-SHA512: ca822f7160529e59973bab6a7cc31753ffa3caaa806887b5073b42c4ae5c918a5ea2cf93c666e5125ea70d10c6954709a535a264b04c2fd4cf916b3c59ab9964
2 parents afde95b + 44041ae commit 15717f0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/init.cpp

+26-6
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)