Browse Source

[Qt] allow users to set -onion via GUI

- also allow users to see, if the default proxy (-proxy) is used for
  reaching peers via IPv6 or Tor
0.13
Philip Kaufmann 10 years ago
parent
commit
ed166dfa82
  1. 189
      src/qt/forms/optionsdialog.ui
  2. 51
      src/qt/optionsdialog.cpp
  3. 4
      src/qt/optionsdialog.h
  4. 57
      src/qt/optionsmodel.cpp
  5. 3
      src/qt/optionsmodel.h

189
src/qt/forms/optionsdialog.ui

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>560</width> <width>560</width>
<height>400</height> <height>440</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -297,6 +297,193 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2_Network">
<item>
<widget class="QLabel" name="proxyActiveNets">
<property name="text">
<string>Used for reaching peers via:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachIPv4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachIPv4Label">
<property name="text">
<string>IPv4</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachIPv6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachIPv6Label">
<property name="text">
<string>IPv6</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachTor">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachTorLabel">
<property name="text">
<string>Tor</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2_Network">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="connectSocksTor">
<property name="toolTip">
<string>Connect to the Bitcoin network through a separate SOCKS5 proxy for Tor hidden services.</string>
</property>
<property name="text">
<string>Use separate SOCKS5 proxy to reach peers via Tor hidden services:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3_Network">
<item>
<widget class="QLabel" name="proxyIpTorLabel">
<property name="text">
<string>Proxy &amp;IP:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="buddy">
<cstring>proxyIpTor</cstring>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="proxyIpTor">
<property name="minimumSize">
<size>
<width>140</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>IP address of the proxy (e.g. IPv4: 127.0.0.1 / IPv6: ::1)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyPortTorLabel">
<property name="text">
<string>&amp;Port:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="buddy">
<cstring>proxyPortTor</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyPortTor">
<property name="minimumSize">
<size>
<width>55</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Port of the proxy (e.g. 9050)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4_Network">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer_Network"> <spacer name="verticalSpacer_Network">
<property name="orientation"> <property name="orientation">

51
src/qt/optionsdialog.cpp

@ -35,7 +35,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
ui(new Ui::OptionsDialog), ui(new Ui::OptionsDialog),
model(0), model(0),
mapper(0), mapper(0),
fProxyIpValid(true) fProxyIpsValid(true)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -54,10 +54,18 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
ui->proxyPort->setEnabled(false); ui->proxyPort->setEnabled(false);
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this)); ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
ui->proxyIpTor->setEnabled(false);
ui->proxyPortTor->setEnabled(false);
ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyIpTor, SLOT(setEnabled(bool)));
connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyPortTor, SLOT(setEnabled(bool)));
ui->proxyIp->installEventFilter(this); ui->proxyIp->installEventFilter(this);
ui->proxyIpTor->installEventFilter(this);
/* Window elements init */ /* Window elements init */
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -110,7 +118,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setOrientation(Qt::Vertical); mapper->setOrientation(Qt::Vertical);
/* setup/change UI elements when proxy IP is invalid/valid */ /* setup/change UI elements when proxy IPs are invalid/valid */
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int))); connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int)));
} }
@ -137,6 +145,8 @@ void OptionsDialog::setModel(OptionsModel *model)
mapper->setModel(model); mapper->setModel(model);
setMapper(); setMapper();
mapper->toFirst(); mapper->toFirst();
updateDefaultProxyNets();
} }
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */ /* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
@ -149,6 +159,7 @@ void OptionsDialog::setModel(OptionsModel *model)
/* Network */ /* Network */
connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning())); connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning())); connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->connectSocksTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
/* Display */ /* Display */
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning())); connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
@ -173,6 +184,10 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP); mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort); mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
mapper->addMapping(ui->connectSocksTor, OptionsModel::ProxyUseTor);
mapper->addMapping(ui->proxyIpTor, OptionsModel::ProxyIPTor);
mapper->addMapping(ui->proxyPortTor, OptionsModel::ProxyPortTor);
/* Window */ /* Window */
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray); mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
@ -188,7 +203,7 @@ void OptionsDialog::setMapper()
void OptionsDialog::enableOkButton() void OptionsDialog::enableOkButton()
{ {
/* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */ /* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
if(fProxyIpValid) if(fProxyIpsValid)
setOkButtonState(true); setOkButtonState(true);
} }
@ -224,6 +239,7 @@ void OptionsDialog::on_okButton_clicked()
{ {
mapper->submit(); mapper->submit();
accept(); accept();
updateDefaultProxyNets();
} }
void OptionsDialog::on_cancelButton_clicked() void OptionsDialog::on_cancelButton_clicked()
@ -257,11 +273,10 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
{ {
Q_UNUSED(nProxyPort); Q_UNUSED(nProxyPort);
const std::string strAddrProxy = pUiProxyIp->text().toStdString();
CService addrProxy; CService addrProxy;
/* Check for a valid IPv4 / IPv6 address */ /* Check for a valid IPv4 / IPv6 address */
if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy))) if (!(fProxyIpsValid = LookupNumeric(pUiProxyIp->text().toStdString().c_str(), addrProxy)))
{ {
disableOkButton(); disableOkButton();
pUiProxyIp->setValid(false); pUiProxyIp->setValid(false);
@ -275,6 +290,28 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
} }
} }
void OptionsDialog::updateDefaultProxyNets()
{
proxyType proxy;
std::string strProxy;
QString strDefaultProxyGUI;
GetProxy(NET_IPV4, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv4->setChecked(true) : ui->proxyReachIPv4->setChecked(false);
GetProxy(NET_IPV6, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv6->setChecked(true) : ui->proxyReachIPv6->setChecked(false);
GetProxy(NET_TOR, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachTor->setChecked(true) : ui->proxyReachTor->setChecked(false);
}
bool OptionsDialog::eventFilter(QObject *object, QEvent *event) bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{ {
if(event->type() == QEvent::FocusOut) if(event->type() == QEvent::FocusOut)
@ -283,6 +320,10 @@ bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{ {
Q_EMIT proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt()); Q_EMIT proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
} }
else if(object == ui->proxyIpTor)
{
Q_EMIT proxyIpChecks(ui->proxyIpTor, ui->proxyPortTor->text().toInt());
}
} }
return QDialog::eventFilter(object, event); return QDialog::eventFilter(object, event);
} }

4
src/qt/optionsdialog.h

@ -47,6 +47,8 @@ private Q_SLOTS:
void showRestartWarning(bool fPersistent = false); void showRestartWarning(bool fPersistent = false);
void clearStatusLabel(); void clearStatusLabel();
void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
/* query the networks, for which the default proxy is used */
void updateDefaultProxyNets();
Q_SIGNALS: Q_SIGNALS:
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort); void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
@ -55,7 +57,7 @@ private:
Ui::OptionsDialog *ui; Ui::OptionsDialog *ui;
OptionsModel *model; OptionsModel *model;
QDataWidgetMapper *mapper; QDataWidgetMapper *mapper;
bool fProxyIpValid; bool fProxyIpsValid;
}; };
#endif // BITCOIN_QT_OPTIONSDIALOG_H #endif // BITCOIN_QT_OPTIONSDIALOG_H

57
src/qt/optionsmodel.cpp

@ -117,6 +117,16 @@ void OptionsModel::Init()
else if(!settings.value("fUseProxy").toBool() && !GetArg("-proxy", "").empty()) else if(!settings.value("fUseProxy").toBool() && !GetArg("-proxy", "").empty())
addOverriddenOption("-proxy"); addOverriddenOption("-proxy");
if (!settings.contains("fUseSeparateProxyTor"))
settings.setValue("fUseSeparateProxyTor", false);
if (!settings.contains("addrSeparateProxyTor"))
settings.setValue("addrSeparateProxyTor", "127.0.0.1:9050");
// Only try to set -onion, if user has enabled fUseSeparateProxyTor
if (settings.value("fUseSeparateProxyTor").toBool() && !SoftSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
addOverriddenOption("-onion");
else if(!settings.value("fUseSeparateProxyTor").toBool() && !GetArg("-onion", "").empty())
addOverriddenOption("-onion");
// Display // Display
if (!settings.contains("language")) if (!settings.contains("language"))
settings.setValue("language", ""); settings.setValue("language", "");
@ -178,6 +188,20 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return strlIpPort.at(1); return strlIpPort.at(1);
} }
// separate Tor proxy
case ProxyUseTor:
return settings.value("fUseSeparateProxyTor", false);
case ProxyIPTor: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
return strlIpPort.at(0);
}
case ProxyPortTor: {
// contains IP at index 0 and port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
return strlIpPort.at(1);
}
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
case SpendZeroConfChange: case SpendZeroConfChange:
return settings.value("bSpendZeroConfChange"); return settings.value("bSpendZeroConfChange");
@ -259,6 +283,39 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
} }
} }
break; break;
// separate Tor proxy
case ProxyUseTor:
if (settings.value("fUseSeparateProxyTor") != value) {
settings.setValue("fUseSeparateProxyTor", value.toBool());
setRestartRequired(true);
}
break;
case ProxyIPTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed IP
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(0) != value.toString()) {
// construct new value from new IP and current port
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
settings.setValue("addrSeparateProxyTor", strNewValue);
setRestartRequired(true);
}
}
break;
case ProxyPortTor: {
// contains current IP at index 0 and current port at index 1
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
// if that key doesn't exist or has a changed port
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(1) != value.toString()) {
// construct new value from current IP and new port
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
settings.setValue("addrSeparateProxyTor", strNewValue);
setRestartRequired(true);
}
}
break;
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
case SpendZeroConfChange: case SpendZeroConfChange:
if (settings.value("bSpendZeroConfChange") != value) { if (settings.value("bSpendZeroConfChange") != value) {

3
src/qt/optionsmodel.h

@ -34,6 +34,9 @@ public:
ProxyUse, // bool ProxyUse, // bool
ProxyIP, // QString ProxyIP, // QString
ProxyPort, // int ProxyPort, // int
ProxyUseTor, // bool
ProxyIPTor, // QString
ProxyPortTor, // int
DisplayUnit, // BitcoinUnits::Unit DisplayUnit, // BitcoinUnits::Unit
ThirdPartyTxUrls, // QString ThirdPartyTxUrls, // QString
Language, // QString Language, // QString

Loading…
Cancel
Save