Skip to content

Commit 0c465f5

Browse files
committed
Merge pull request #4587
ed166df [Qt] allow users to set -onion via GUI (Philip Kaufmann)
2 parents 100c9d3 + ed166df commit 0c465f5

File tree

5 files changed

+297
-7
lines changed

5 files changed

+297
-7
lines changed

src/qt/forms/optionsdialog.ui

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>560</width>
10-
<height>400</height>
10+
<height>440</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -297,6 +297,193 @@
297297
</item>
298298
</layout>
299299
</item>
300+
<item>
301+
<layout class="QHBoxLayout" name="horizontalLayout_2_Network">
302+
<item>
303+
<widget class="QLabel" name="proxyActiveNets">
304+
<property name="text">
305+
<string>Used for reaching peers via:</string>
306+
</property>
307+
<property name="textFormat">
308+
<enum>Qt::PlainText</enum>
309+
</property>
310+
</widget>
311+
</item>
312+
<item>
313+
<widget class="QCheckBox" name="proxyReachIPv4">
314+
<property name="enabled">
315+
<bool>false</bool>
316+
</property>
317+
<property name="toolTip">
318+
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
319+
</property>
320+
<property name="text">
321+
<string/>
322+
</property>
323+
</widget>
324+
</item>
325+
<item>
326+
<widget class="QLabel" name="proxyReachIPv4Label">
327+
<property name="text">
328+
<string>IPv4</string>
329+
</property>
330+
<property name="textFormat">
331+
<enum>Qt::PlainText</enum>
332+
</property>
333+
</widget>
334+
</item>
335+
<item>
336+
<widget class="QCheckBox" name="proxyReachIPv6">
337+
<property name="enabled">
338+
<bool>false</bool>
339+
</property>
340+
<property name="toolTip">
341+
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
342+
</property>
343+
<property name="text">
344+
<string/>
345+
</property>
346+
</widget>
347+
</item>
348+
<item>
349+
<widget class="QLabel" name="proxyReachIPv6Label">
350+
<property name="text">
351+
<string>IPv6</string>
352+
</property>
353+
<property name="textFormat">
354+
<enum>Qt::PlainText</enum>
355+
</property>
356+
</widget>
357+
</item>
358+
<item>
359+
<widget class="QCheckBox" name="proxyReachTor">
360+
<property name="enabled">
361+
<bool>false</bool>
362+
</property>
363+
<property name="toolTip">
364+
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
365+
</property>
366+
<property name="text">
367+
<string/>
368+
</property>
369+
</widget>
370+
</item>
371+
<item>
372+
<widget class="QLabel" name="proxyReachTorLabel">
373+
<property name="text">
374+
<string>Tor</string>
375+
</property>
376+
<property name="textFormat">
377+
<enum>Qt::PlainText</enum>
378+
</property>
379+
</widget>
380+
</item>
381+
<item>
382+
<spacer name="horizontalSpacer_2_Network">
383+
<property name="orientation">
384+
<enum>Qt::Horizontal</enum>
385+
</property>
386+
<property name="sizeHint" stdset="0">
387+
<size>
388+
<width>40</width>
389+
<height>20</height>
390+
</size>
391+
</property>
392+
</spacer>
393+
</item>
394+
</layout>
395+
</item>
396+
<item>
397+
<widget class="QCheckBox" name="connectSocksTor">
398+
<property name="toolTip">
399+
<string>Connect to the Bitcoin network through a separate SOCKS5 proxy for Tor hidden services.</string>
400+
</property>
401+
<property name="text">
402+
<string>Use separate SOCKS5 proxy to reach peers via Tor hidden services:</string>
403+
</property>
404+
</widget>
405+
</item>
406+
<item>
407+
<layout class="QHBoxLayout" name="horizontalLayout_3_Network">
408+
<item>
409+
<widget class="QLabel" name="proxyIpTorLabel">
410+
<property name="text">
411+
<string>Proxy &amp;IP:</string>
412+
</property>
413+
<property name="textFormat">
414+
<enum>Qt::PlainText</enum>
415+
</property>
416+
<property name="buddy">
417+
<cstring>proxyIpTor</cstring>
418+
</property>
419+
</widget>
420+
</item>
421+
<item>
422+
<widget class="QValidatedLineEdit" name="proxyIpTor">
423+
<property name="minimumSize">
424+
<size>
425+
<width>140</width>
426+
<height>0</height>
427+
</size>
428+
</property>
429+
<property name="maximumSize">
430+
<size>
431+
<width>140</width>
432+
<height>16777215</height>
433+
</size>
434+
</property>
435+
<property name="toolTip">
436+
<string>IP address of the proxy (e.g. IPv4: 127.0.0.1 / IPv6: ::1)</string>
437+
</property>
438+
</widget>
439+
</item>
440+
<item>
441+
<widget class="QLabel" name="proxyPortTorLabel">
442+
<property name="text">
443+
<string>&amp;Port:</string>
444+
</property>
445+
<property name="textFormat">
446+
<enum>Qt::PlainText</enum>
447+
</property>
448+
<property name="buddy">
449+
<cstring>proxyPortTor</cstring>
450+
</property>
451+
</widget>
452+
</item>
453+
<item>
454+
<widget class="QLineEdit" name="proxyPortTor">
455+
<property name="minimumSize">
456+
<size>
457+
<width>55</width>
458+
<height>0</height>
459+
</size>
460+
</property>
461+
<property name="maximumSize">
462+
<size>
463+
<width>55</width>
464+
<height>16777215</height>
465+
</size>
466+
</property>
467+
<property name="toolTip">
468+
<string>Port of the proxy (e.g. 9050)</string>
469+
</property>
470+
</widget>
471+
</item>
472+
<item>
473+
<spacer name="horizontalSpacer_4_Network">
474+
<property name="orientation">
475+
<enum>Qt::Horizontal</enum>
476+
</property>
477+
<property name="sizeHint" stdset="0">
478+
<size>
479+
<width>40</width>
480+
<height>20</height>
481+
</size>
482+
</property>
483+
</spacer>
484+
</item>
485+
</layout>
486+
</item>
300487
<item>
301488
<spacer name="verticalSpacer_Network">
302489
<property name="orientation">

src/qt/optionsdialog.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
3535
ui(new Ui::OptionsDialog),
3636
model(0),
3737
mapper(0),
38-
fProxyIpValid(true)
38+
fProxyIpsValid(true)
3939
{
4040
ui->setupUi(this);
4141

@@ -54,10 +54,18 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
5454
ui->proxyPort->setEnabled(false);
5555
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
5656

57+
ui->proxyIpTor->setEnabled(false);
58+
ui->proxyPortTor->setEnabled(false);
59+
ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));
60+
5761
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
5862
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
5963

64+
connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyIpTor, SLOT(setEnabled(bool)));
65+
connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyPortTor, SLOT(setEnabled(bool)));
66+
6067
ui->proxyIp->installEventFilter(this);
68+
ui->proxyIpTor->installEventFilter(this);
6169

6270
/* Window elements init */
6371
#ifdef Q_OS_MAC
@@ -110,7 +118,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
110118
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
111119
mapper->setOrientation(Qt::Vertical);
112120

113-
/* setup/change UI elements when proxy IP is invalid/valid */
121+
/* setup/change UI elements when proxy IPs are invalid/valid */
114122
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int)));
115123
}
116124

@@ -137,6 +145,8 @@ void OptionsDialog::setModel(OptionsModel *model)
137145
mapper->setModel(model);
138146
setMapper();
139147
mapper->toFirst();
148+
149+
updateDefaultProxyNets();
140150
}
141151

142152
/* 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)
149159
/* Network */
150160
connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
151161
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
162+
connect(ui->connectSocksTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
152163
/* Display */
153164
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
154165
connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
@@ -173,6 +184,10 @@ void OptionsDialog::setMapper()
173184
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
174185
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
175186

187+
mapper->addMapping(ui->connectSocksTor, OptionsModel::ProxyUseTor);
188+
mapper->addMapping(ui->proxyIpTor, OptionsModel::ProxyIPTor);
189+
mapper->addMapping(ui->proxyPortTor, OptionsModel::ProxyPortTor);
190+
176191
/* Window */
177192
#ifndef Q_OS_MAC
178193
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
@@ -188,7 +203,7 @@ void OptionsDialog::setMapper()
188203
void OptionsDialog::enableOkButton()
189204
{
190205
/* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
191-
if(fProxyIpValid)
206+
if(fProxyIpsValid)
192207
setOkButtonState(true);
193208
}
194209

@@ -224,6 +239,7 @@ void OptionsDialog::on_okButton_clicked()
224239
{
225240
mapper->submit();
226241
accept();
242+
updateDefaultProxyNets();
227243
}
228244

229245
void OptionsDialog::on_cancelButton_clicked()
@@ -257,11 +273,10 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
257273
{
258274
Q_UNUSED(nProxyPort);
259275

260-
const std::string strAddrProxy = pUiProxyIp->text().toStdString();
261276
CService addrProxy;
262277

263278
/* Check for a valid IPv4 / IPv6 address */
264-
if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy)))
279+
if (!(fProxyIpsValid = LookupNumeric(pUiProxyIp->text().toStdString().c_str(), addrProxy)))
265280
{
266281
disableOkButton();
267282
pUiProxyIp->setValid(false);
@@ -275,6 +290,28 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
275290
}
276291
}
277292

293+
void OptionsDialog::updateDefaultProxyNets()
294+
{
295+
proxyType proxy;
296+
std::string strProxy;
297+
QString strDefaultProxyGUI;
298+
299+
GetProxy(NET_IPV4, proxy);
300+
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
301+
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
302+
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv4->setChecked(true) : ui->proxyReachIPv4->setChecked(false);
303+
304+
GetProxy(NET_IPV6, proxy);
305+
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
306+
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
307+
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv6->setChecked(true) : ui->proxyReachIPv6->setChecked(false);
308+
309+
GetProxy(NET_TOR, proxy);
310+
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
311+
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
312+
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachTor->setChecked(true) : ui->proxyReachTor->setChecked(false);
313+
}
314+
278315
bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
279316
{
280317
if(event->type() == QEvent::FocusOut)
@@ -283,6 +320,10 @@ bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
283320
{
284321
Q_EMIT proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
285322
}
323+
else if(object == ui->proxyIpTor)
324+
{
325+
Q_EMIT proxyIpChecks(ui->proxyIpTor, ui->proxyPortTor->text().toInt());
326+
}
286327
}
287328
return QDialog::eventFilter(object, event);
288329
}

src/qt/optionsdialog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private Q_SLOTS:
4747
void showRestartWarning(bool fPersistent = false);
4848
void clearStatusLabel();
4949
void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
50+
/* query the networks, for which the default proxy is used */
51+
void updateDefaultProxyNets();
5052

5153
Q_SIGNALS:
5254
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
@@ -55,7 +57,7 @@ private Q_SLOTS:
5557
Ui::OptionsDialog *ui;
5658
OptionsModel *model;
5759
QDataWidgetMapper *mapper;
58-
bool fProxyIpValid;
60+
bool fProxyIpsValid;
5961
};
6062

6163
#endif // BITCOIN_QT_OPTIONSDIALOG_H

0 commit comments

Comments
 (0)