mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-02 03:02:35 +02:00
Migrate -listen and -server settings from QSettings to settings.json
This commit is contained in:
parent
d2ada6e635
commit
a09e3b7cf2
@ -43,6 +43,8 @@ static const char* SettingName(OptionsModel::OptionID option)
|
|||||||
case OptionsModel::ExternalSignerPath: return "signer";
|
case OptionsModel::ExternalSignerPath: return "signer";
|
||||||
case OptionsModel::MapPortUPnP: return "upnp";
|
case OptionsModel::MapPortUPnP: return "upnp";
|
||||||
case OptionsModel::MapPortNatpmp: return "natpmp";
|
case OptionsModel::MapPortNatpmp: return "natpmp";
|
||||||
|
case OptionsModel::Listen: return "listen";
|
||||||
|
case OptionsModel::Server: return "server";
|
||||||
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
|
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +133,7 @@ bool OptionsModel::Init(bilingual_str& error)
|
|||||||
// These are shared with the core or have a command-line parameter
|
// These are shared with the core or have a command-line parameter
|
||||||
// and we want command-line parameters to overwrite the GUI settings.
|
// and we want command-line parameters to overwrite the GUI settings.
|
||||||
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
|
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
|
||||||
MapPortNatpmp}) {
|
MapPortNatpmp, Listen, Server}) {
|
||||||
std::string setting = SettingName(option);
|
std::string setting = SettingName(option);
|
||||||
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
|
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
|
||||||
try {
|
try {
|
||||||
@ -168,37 +170,6 @@ bool OptionsModel::Init(bilingual_str& error)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
if (!settings.contains("fListen"))
|
|
||||||
settings.setValue("fListen", DEFAULT_LISTEN);
|
|
||||||
const bool listen{settings.value("fListen").toBool()};
|
|
||||||
if (!gArgs.SoftSetBoolArg("-listen", listen)) {
|
|
||||||
addOverriddenOption("-listen");
|
|
||||||
} else if (!listen) {
|
|
||||||
// We successfully set -listen=0, thus mimic the logic from InitParameterInteraction():
|
|
||||||
// "parameter interaction: -listen=0 -> setting -listenonion=0".
|
|
||||||
//
|
|
||||||
// Both -listen and -listenonion default to true.
|
|
||||||
//
|
|
||||||
// The call order is:
|
|
||||||
//
|
|
||||||
// InitParameterInteraction()
|
|
||||||
// would set -listenonion=0 if it sees -listen=0, but for bitcoin-qt with
|
|
||||||
// fListen=false -listen is 1 at this point
|
|
||||||
//
|
|
||||||
// OptionsModel::Init()
|
|
||||||
// (this method) can flip -listen from 1 to 0 if fListen=false
|
|
||||||
//
|
|
||||||
// AppInitParameterInteraction()
|
|
||||||
// raises an error if -listen=0 and -listenonion=1
|
|
||||||
gArgs.SoftSetBoolArg("-listenonion", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!settings.contains("server")) {
|
|
||||||
settings.setValue("server", false);
|
|
||||||
}
|
|
||||||
if (!gArgs.SoftSetBoolArg("-server", settings.value("server").toBool())) {
|
|
||||||
addOverriddenOption("-server");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!settings.contains("fUseProxy"))
|
if (!settings.contains("fUseProxy"))
|
||||||
settings.setValue("fUseProxy", false);
|
settings.setValue("fUseProxy", false);
|
||||||
@ -439,9 +410,9 @@ QVariant OptionsModel::getOption(OptionID option) const
|
|||||||
case ThreadsScriptVerif:
|
case ThreadsScriptVerif:
|
||||||
return qlonglong(SettingToInt(setting(), DEFAULT_SCRIPTCHECK_THREADS));
|
return qlonglong(SettingToInt(setting(), DEFAULT_SCRIPTCHECK_THREADS));
|
||||||
case Listen:
|
case Listen:
|
||||||
return settings.value("fListen");
|
return SettingToBool(setting(), DEFAULT_LISTEN);
|
||||||
case Server:
|
case Server:
|
||||||
return settings.value("server");
|
return SettingToBool(setting(), false);
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -610,14 +581,9 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Listen:
|
case Listen:
|
||||||
if (settings.value("fListen") != value) {
|
|
||||||
settings.setValue("fListen", value);
|
|
||||||
setRestartRequired(true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Server:
|
case Server:
|
||||||
if (settings.value("server") != value) {
|
if (changed()) {
|
||||||
settings.setValue("server", value);
|
update(value.toBool());
|
||||||
setRestartRequired(true);
|
setRestartRequired(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -697,4 +663,13 @@ void OptionsModel::checkAndMigrate()
|
|||||||
#endif
|
#endif
|
||||||
migrate_setting(MapPortUPnP, "fUseUPnP");
|
migrate_setting(MapPortUPnP, "fUseUPnP");
|
||||||
migrate_setting(MapPortNatpmp, "fUseNatpmp");
|
migrate_setting(MapPortNatpmp, "fUseNatpmp");
|
||||||
|
migrate_setting(Listen, "fListen");
|
||||||
|
migrate_setting(Server, "server");
|
||||||
|
|
||||||
|
// In case migrating QSettings caused any settings value to change, rerun
|
||||||
|
// parameter interaction code to update other settings. This is particularly
|
||||||
|
// important for the -listen setting, which should cause -listenonion, -upnp,
|
||||||
|
// and other settings to default to false if it was set to false.
|
||||||
|
// (https://github.com/bitcoin-core/gui/issues/567).
|
||||||
|
node().initParameterInteraction();
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ void OptionTests::migrateSettings()
|
|||||||
settings.setValue("nDatabaseCache", 600);
|
settings.setValue("nDatabaseCache", 600);
|
||||||
settings.setValue("nThreadsScriptVerif", 12);
|
settings.setValue("nThreadsScriptVerif", 12);
|
||||||
settings.setValue("fUseUPnP", false);
|
settings.setValue("fUseUPnP", false);
|
||||||
|
settings.setValue("fListen", false);
|
||||||
|
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
@ -44,10 +45,12 @@ void OptionTests::migrateSettings()
|
|||||||
QVERIFY(!settings.contains("nDatabaseCache"));
|
QVERIFY(!settings.contains("nDatabaseCache"));
|
||||||
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
QVERIFY(!settings.contains("nThreadsScriptVerif"));
|
||||||
QVERIFY(!settings.contains("fUseUPnP"));
|
QVERIFY(!settings.contains("fUseUPnP"));
|
||||||
|
QVERIFY(!settings.contains("fListen"));
|
||||||
|
|
||||||
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
|
||||||
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
|
||||||
" \"dbcache\": \"600\",\n"
|
" \"dbcache\": \"600\",\n"
|
||||||
|
" \"listen\": false,\n"
|
||||||
" \"par\": \"12\"\n"
|
" \"par\": \"12\"\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user