Browse Source

#74 Add Tor Support

recurring
adityapk 5 years ago
parent
commit
c5e8b01c2a
  1. 5
      src/connection.cpp
  2. 1
      src/connection.h
  3. 30
      src/mainwindow.cpp
  4. 1
      src/precompiled.h
  5. 44
      src/settings.cpp
  6. 3
      src/settings.h
  7. 78
      src/settings.ui

5
src/connection.cpp

@ -550,6 +550,9 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
if (name == "daemon" && value == "1") {
zcashconf->zcashDaemon = true;
}
if (name == "proxy") {
zcashconf->proxy = value;
}
if (name == "testnet" &&
value == "1" &&
zcashconf->port.isEmpty()) {
@ -581,7 +584,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
if (username.isEmpty() || password.isEmpty())
return nullptr;
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, false, "", ConnectionType::UISettingsZCashD};
auto uiConfig = new ConnectionConfig{ host, port, username, password, false, false, "", "", ConnectionType::UISettingsZCashD};
return std::shared_ptr<ConnectionConfig>(uiConfig);
}

1
src/connection.h

@ -23,6 +23,7 @@ struct ConnectionConfig {
bool usingZcashConf;
bool zcashDaemon;
QString zcashDir;
QString proxy;
ConnectionType connType;
};

30
src/mainwindow.cpp

@ -393,6 +393,17 @@ void MainWindow::setupSettingsModal() {
// Auto shielding
settings.chkAutoShield->setChecked(Settings::getInstance()->getAutoShield());
// Use Tor
bool isUsingTor = !rpc->getConnection()->config->proxy.isEmpty();
settings.chkTor->setChecked(isUsingTor);
if (rpc->getEZcashD() == nullptr) {
settings.chkTor->setEnabled(false);
settings.lblTor->setEnabled(false);
QString tooltip = tr("Tor configuration is available only when running an embedded zcashd.");
settings.chkTor->setToolTip(tooltip);
settings.lblTor->setToolTip(tooltip);
}
// Connection Settings
QIntValidator validator(0, 65535);
settings.port->setValidator(&validator);
@ -435,6 +446,25 @@ void MainWindow::setupSettingsModal() {
// Auto shield
Settings::getInstance()->setAutoShield(settings.chkAutoShield->isChecked());
if (!isUsingTor && settings.chkTor->isChecked()) {
// If "use tor" was previously unchecked and now checked
Settings::addToZcashConf(zcashConfLocation, "proxy=127.0.0.1:9050");
rpc->getConnection()->config->proxy = "proxy=127.0.0.1:9050";
QMessageBox::information(this, tr("Enable Tor"),
tr("Connection over Tor has been enabled. To use this feature, you need to restart zec-qt-wallet."),
QMessageBox::Ok);
}
if (isUsingTor && !settings.chkTor->isChecked()) {
// If "use tor" was previously checked and now is unchecked
Settings::removeFromZcashConf(zcashConfLocation, "proxy");
rpc->getConnection()->config->proxy.clear();
QMessageBox::information(this, tr("Disable Tor"),
tr("Connection over Tor has been disabled. To fully disconnect from Tor, you need to restart zec-qt-wallet."),
QMessageBox::Ok);
}
if (zcashConfLocation.isEmpty()) {
// Save settings
Settings::getInstance()->saveSettings(

1
src/precompiled.h

@ -36,6 +36,7 @@
#include <QSettings>
#include <QStyle>
#include <QFile>
#include <QTemporaryFile>
#include <QErrorMessage>
#include <QApplication>
#include <QStandardPaths>

44
src/settings.cpp

@ -201,6 +201,50 @@ QString Settings::getDonationAddr(bool sapling) {
return "zcEgrceTwvoiFdEvPWcsJHAMrpLsprMF6aRJiQa3fan5ZphyXLPuHghnEPrEPRoEVzUy65GnMVyCTRdkT6BYBepnXh6NBYs";
}
bool Settings::addToZcashConf(QString confLocation, QString line) {
QFile file(confLocation);
if (!file.open(QIODevice::ReadWrite | QIODevice::Append))
return false;
QTextStream out(&file);
out << line << "\n";
file.close();
return true;
}
bool Settings::removeFromZcashConf(QString confLocation, QString option) {
// To remove an option, we'll create a new file, and copy over everything but the option.
QFile file(confLocation);
if (!file.open(QIODevice::ReadOnly))
return false;
QList<QString> lines;
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
auto s = line.indexOf("=");
QString name = line.left(s).trimmed().toLower();
if (name != option) {
qDebug() << "Copied " << line;
lines.append(line);
}
}
file.close();
QFile newfile(confLocation);
if (!newfile.open(QIODevice::ReadWrite | QIODevice::Truncate))
return false;
QTextStream out(&newfile);
for (QString line : lines) {
out << line << endl;
}
newfile.close();
return true;
}
double Settings::getMinerFee() {
return 0.0001;

3
src/settings.h

@ -76,6 +76,9 @@ public:
static bool isValidAddress(QString addr);
static bool addToZcashConf(QString confLocation, QString line);
static bool removeFromZcashConf(QString confLocation, QString option);
static const QString labelRegExp;
static const int updateSpeed = 20 * 1000; // 20 sec

78
src/settings.ui

@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>460</width>
<height>464</height>
<width>540</width>
<height>504</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>460</width>
<height>464</height>
<width>540</width>
<height>500</height>
</size>
</property>
<property name="windowTitle">
@ -26,7 +26,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -145,10 +145,10 @@
<string>Options</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<item row="10" column="0" colspan="2">
<widget class="QLabel" name="lblTor">
<property name="text">
<string>Shielded transactions are saved locally and shown in the transactions tab. If you uncheck this, shielded transactions will not appear in the transactions tab.</string>
<string>Connect to the Tor network via SOCKS proxy running on 127.0.0.1:9050. Please note that you'll have to install and run the Tor service externally.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -162,6 +162,16 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Shielded transactions are saved locally and shown in the transactions tab. If you uncheck this, shielded transactions will not appear in the transactions tab.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
@ -182,14 +192,31 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="3" column="0">
<widget class="QCheckBox" name="chkCustomFees">
<property name="text">
<string>Allow custom fees</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Normally, change from t-Addresses goes to another t-Address. Checking this option will send the change to your shielded sapling address instead. Check this option to increase your privacy.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="12" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -202,13 +229,6 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkCustomFees">
<property name="text">
<string>Allow custom fees</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_6">
<property name="text">
@ -219,16 +239,6 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Normally, change from t-Addresses goes to another t-Address. Checking this option will send the change to your shielded sapling address instead. Check this option to increase your privacy.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkAutoShield">
<property name="text">
@ -243,6 +253,20 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="chkTor">
<property name="text">
<string>Connect via Tor</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

Loading…
Cancel
Save