Skip to content

Commit f15b72f

Browse files
committed
Merge #12650: gui: Fix issue: "default port not shown correctly in settings dialog"
40c5886 Fix illegal default `addProxy` and `addrSeparateProxyTor` settings. (251) Pull request description: In f05d349 the value of the `addrProxy` and `addrSeparateProxyTor` settings is set to an illegal default value, because the value of `DEFAULT_GUI_PROXY_PORT ` is passed to the `fieldWidth` parameter of the `QString QString::arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const` method: https://github.com/bitcoin/bitcoin/blob/29fad97c320c892ab6a480c81e2078ec22ab354b/src/qt/optionsmodel.cpp#L129 https://github.com/bitcoin/bitcoin/blob/29fad97c320c892ab6a480c81e2078ec22ab354b/src/qt/optionsmodel.cpp#L139 This will create a default proxy setting that consists of 9053 characters and ends with the string `127.0.0.1:%2`. This PR attempts to resolve #12623 by setting the correct value for the `addrProxy` and `addrSeparateProxyTor` settings (i) if the proxy setting does not exist; or (ii) if the proxy setting has an illegal value caused by to the aforementioned bug. The second condition is *only* relevant if we don't want Bitcoin Core 0.16.0 users to explicitly reset their settings to see the correct default proxy port value. Tree-SHA512: 3dc3de2eb7da831f6e318797df67341ced2076b48f9b561c73677bf6beb67b259d8e413095f290356fb92e32e4e8162d48accbc575c4e612060fd5d6dde7ac8d
2 parents 7b6041d + 40c5886 commit f15b72f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/qt/optionsmodel.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
2626

27+
static const QString GetDefaultProxyAddress();
28+
2729
OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent, bool resetSettings) :
2830
QAbstractListModel(parent), m_node(node)
2931
{
@@ -121,7 +123,7 @@ void OptionsModel::Init(bool resetSettings)
121123
if (!settings.contains("fUseProxy"))
122124
settings.setValue("fUseProxy", false);
123125
if (!settings.contains("addrProxy"))
124-
settings.setValue("addrProxy", QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, DEFAULT_GUI_PROXY_PORT));
126+
settings.setValue("addrProxy", GetDefaultProxyAddress());
125127
// Only try to set -proxy, if user has enabled fUseProxy
126128
if (settings.value("fUseProxy").toBool() && !m_node.softSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
127129
addOverriddenOption("-proxy");
@@ -131,7 +133,7 @@ void OptionsModel::Init(bool resetSettings)
131133
if (!settings.contains("fUseSeparateProxyTor"))
132134
settings.setValue("fUseSeparateProxyTor", false);
133135
if (!settings.contains("addrSeparateProxyTor"))
134-
settings.setValue("addrSeparateProxyTor", QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, DEFAULT_GUI_PROXY_PORT));
136+
settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
135137
// Only try to set -onion, if user has enabled fUseSeparateProxyTor
136138
if (settings.value("fUseSeparateProxyTor").toBool() && !m_node.softSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
137139
addOverriddenOption("-onion");
@@ -223,6 +225,11 @@ static void SetProxySetting(QSettings &settings, const QString &name, const Prox
223225
settings.setValue(name, ip_port.ip + ":" + ip_port.port);
224226
}
225227

228+
static const QString GetDefaultProxyAddress()
229+
{
230+
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
231+
}
232+
226233
// read QSettings values and return them
227234
QVariant OptionsModel::data(const QModelIndex & index, int role) const
228235
{
@@ -485,4 +492,16 @@ void OptionsModel::checkAndMigrate()
485492

486493
settings.setValue(strSettingsVersionKey, CLIENT_VERSION);
487494
}
495+
496+
// Overwrite the 'addrProxy' setting in case it has been set to an illegal
497+
// default value (see issue #12623; PR #12650).
498+
if (settings.contains("addrProxy") && settings.value("addrProxy").toString().endsWith("%2")) {
499+
settings.setValue("addrProxy", GetDefaultProxyAddress());
500+
}
501+
502+
// Overwrite the 'addrSeparateProxyTor' setting in case it has been set to an illegal
503+
// default value (see issue #12623; PR #12650).
504+
if (settings.contains("addrSeparateProxyTor") && settings.value("addrSeparateProxyTor").toString().endsWith("%2")) {
505+
settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
506+
}
488507
}

0 commit comments

Comments
 (0)