From 791094077e9a87ffd89f95d779185df415a5120b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 9 Sep 2020 17:15:44 -0400 Subject: [PATCH] Cleanups --- src/connection.cpp | 40 ++++++++++++++++++++-------------------- src/connection.h | 2 +- src/mainwindow.cpp | 32 ++++++++++++++++---------------- src/rpc.cpp | 8 ++++---- src/sendtab.cpp | 4 ++-- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 6c9c962..31951cb 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -75,7 +75,7 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) { main->logger->write("Embedded hushd started up, trying autoconnect in 1 sec"); QTimer::singleShot(1000, [=]() { doAutoConnect(); } ); } else { - if (config->zcashDaemon) { + if (config->hushDaemon) { // hushd is configured to run as a daemon, so we must wait for a few seconds // to let it start up. main->logger->write("hushd is daemon=1. Waiting for it to start up"); @@ -93,7 +93,7 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) { // We tried to start ehushd previously, and it didn't work. So, show the error. main->logger->write("Couldn't start embedded hushd for unknown reason"); QString explanation; - if (config->zcashDaemon) { + if (config->hushDaemon) { explanation = QString() % QObject::tr("You have hushd set to start as a daemon, which can cause problems " "with SilentDragon\n\n." "Please remove the following line from your HUSH3.conf and restart SilentDragon\n" @@ -667,12 +667,12 @@ std::shared_ptr ConnectionLoader::autoDetectHushConf() { QTextStream in(&file); - auto zcashconf = new ConnectionConfig(); - zcashconf->host = "127.0.0.1"; - zcashconf->connType = ConnectionType::DetectedConfExternalZcashD; - zcashconf->usingHushConf = true; - zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath(); - zcashconf->zcashDaemon = false; + auto hushconf = new ConnectionConfig(); + hushconf->host = "127.0.0.1"; + hushconf->connType = ConnectionType::DetectedConfExternalZcashD; + hushconf->usingHushConf = true; + hushconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath(); + hushconf->hushDaemon = false; Settings::getInstance()->setUsingHushConf(confLocation); @@ -683,43 +683,43 @@ std::shared_ptr ConnectionLoader::autoDetectHushConf() { QString value = line.right(line.length() - s - 1).trimmed(); if (name == "rpcuser") { - zcashconf->rpcuser = value; + hushconf->rpcuser = value; } if (name == "rpcpassword") { - zcashconf->rpcpassword = value; + hushconf->rpcpassword = value; } if (name == "rpcport") { - zcashconf->port = value; + hushconf->port = value; } if (name == "daemon" && value == "1") { - zcashconf->zcashDaemon = true; + hushconf->hushDaemon = true; } if (name == "proxy") { - zcashconf->proxy = value; + hushconf->proxy = value; } if (name == "consolidation") { - zcashconf->consolidation = value; + hushconf->consolidation = value; } if (name == "deletetx") { - zcashconf->deletetx = value; + hushconf->deletetx = value; } if (name == "zindex") { - zcashconf->zindex = value; + hushconf->zindex = value; } if (name == "testnet" && value == "1" && - zcashconf->port.isEmpty()) { - zcashconf->port = "18232"; + hushconf->port.isEmpty()) { + hushconf->port = "18232"; } } // If rpcport is not in the file, and it was not set by the testnet=1 flag, then go to default - if (zcashconf->port.isEmpty()) zcashconf->port = "18031"; + if (hushconf->port.isEmpty()) hushconf->port = "18031"; file.close(); // In addition to the HUSH3/HUSH3.conf file, also double check the params. - return std::shared_ptr(zcashconf); + return std::shared_ptr(hushconf); } /** diff --git a/src/connection.h b/src/connection.h index 3ebc53d..574fec8 100644 --- a/src/connection.h +++ b/src/connection.h @@ -21,7 +21,7 @@ struct ConnectionConfig { QString rpcuser; QString rpcpassword; bool usingHushConf; - bool zcashDaemon; + bool hushDaemon; QString zcashDir; QString proxy; QString consolidation; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fde6e2e..f6722cb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -396,9 +396,9 @@ void MainWindow::setupSettingsModal() { settings.port->setValidator(&validator); // If values are coming from HUSH3.conf, then disable all the fields - auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation(); - if (!zcashConfLocation.isEmpty()) { - settings.confMsg->setText("Settings are being read from \n" + zcashConfLocation); + auto hushConfLocation = Settings::getInstance()->getZcashdConfLocation(); + if (!hushConfLocation.isEmpty()) { + settings.confMsg->setText("Settings are being read from \n" + hushConfLocation); settings.hostname->setEnabled(false); settings.port->setEnabled(false); settings.rpcuser->setEnabled(false); @@ -457,7 +457,7 @@ void MainWindow::setupSettingsModal() { if (!isUsingTor && settings.chkTor->isChecked()) { // If "use tor" was previously unchecked and now checked - Settings::addToHushConf(zcashConfLocation, "proxy=127.0.0.1:9050"); + Settings::addToHushConf(hushConfLocation, "proxy=127.0.0.1:9050"); rpc->getConnection()->config->proxy = "proxy=127.0.0.1:9050"; QMessageBox::information(this, tr("Enable Tor"), @@ -467,7 +467,7 @@ void MainWindow::setupSettingsModal() { if (isUsingTor && !settings.chkTor->isChecked()) { // If "use tor" was previously checked and now is unchecked - Settings::removeFromHushConf(zcashConfLocation, "proxy"); + Settings::removeFromHushConf(hushConfLocation, "proxy"); rpc->getConnection()->config->proxy.clear(); QMessageBox::information(this, tr("Disable Tor"), @@ -475,7 +475,7 @@ void MainWindow::setupSettingsModal() { QMessageBox::Ok); } - if (zcashConfLocation.isEmpty()) { + if (hushConfLocation.isEmpty()) { // Save settings Settings::getInstance()->saveSettings( settings.hostname->text(), @@ -498,55 +498,55 @@ void MainWindow::setupSettingsModal() { bool showRestartInfo = false; bool showReindexInfo = false; if (settings.chkRescan->isChecked()) { - Settings::addToHushConf(zcashConfLocation, "rescan=1"); + Settings::addToHushConf(hushConfLocation, "rescan=1"); showRestartInfo = true; } if (settings.chkReindex->isChecked()) { - Settings::addToHushConf(zcashConfLocation, "reindex=1"); + Settings::addToHushConf(hushConfLocation, "reindex=1"); showRestartInfo = true; } if (!rpc->getConnection()->config->consolidation.isEmpty()==false) { if (settings.chkConso->isChecked()) { - Settings::addToHushConf(zcashConfLocation, "consolidation=1"); + Settings::addToHushConf(hushConfLocation, "consolidation=1"); showRestartInfo = true; } } if (!rpc->getConnection()->config->consolidation.isEmpty()) { if (settings.chkConso->isChecked() == false) { - Settings::removeFromHushConf(zcashConfLocation, "consolidation"); + Settings::removeFromHushConf(hushConfLocation, "consolidation"); showRestartInfo = true; } } if (!rpc->getConnection()->config->deletetx.isEmpty() == false) { if (settings.chkDeletetx->isChecked()) { - Settings::addToHushConf(zcashConfLocation, "deletetx=1"); + Settings::addToHushConf(hushConfLocation, "deletetx=1"); showRestartInfo = true; } } if (!rpc->getConnection()->config->deletetx.isEmpty()) { if (settings.chkDeletetx->isChecked() == false) { - Settings::removeFromHushConf(zcashConfLocation, "deletetx"); + Settings::removeFromHushConf(hushConfLocation, "deletetx"); showRestartInfo = true; } } if (!rpc->getConnection()->config->zindex.isEmpty() == false) { if (settings.chkzindex->isChecked()) { - Settings::addToHushConf(zcashConfLocation, "zindex=1"); - Settings::addToHushConf(zcashConfLocation, "reindex=1"); + Settings::addToHushConf(hushConfLocation, "zindex=1"); + Settings::addToHushConf(hushConfLocation, "reindex=1"); showReindexInfo = true; } } if (!rpc->getConnection()->config->zindex.isEmpty()) { if (settings.chkzindex->isChecked() == false) { - Settings::removeFromHushConf(zcashConfLocation, "zindex"); - Settings::addToHushConf(zcashConfLocation, "reindex=1"); + Settings::removeFromHushConf(hushConfLocation, "zindex"); + Settings::addToHushConf(hushConfLocation, "reindex=1"); showReindexInfo = true; } } diff --git a/src/rpc.cpp b/src/rpc.cpp index 66caf63..91e1680 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -82,9 +82,9 @@ void RPC::setConnection(Connection* c) { ui->statusBar->showMessage("Ready! Thank you for helping secure the Hush network by running a full node."); // See if we need to remove the reindex/rescan flags from the zcash.conf file - auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation(); - Settings::removeFromHushConf(zcashConfLocation, "rescan"); - Settings::removeFromHushConf(zcashConfLocation, "reindex"); + auto hushConfLocation = Settings::getInstance()->getZcashdConfLocation(); + Settings::removeFromHushConf(hushConfLocation, "rescan"); + Settings::removeFromHushConf(hushConfLocation, "reindex"); // Refresh the UI refreshPrice(); @@ -1257,7 +1257,7 @@ void RPC::shutdownHushd() { if ((ehushd->atEnd() && ehushd->processId() == 0) || ehushd->state() == QProcess::NotRunning || waitCount > 30 || - conn->config->zcashDaemon) { // If hushd is daemon, then we don't have to do anything else + conn->config->hushDaemon) { // If hushd is daemon, then we don't have to do anything else qDebug() << "Ended"; waiter.stop(); QTimer::singleShot(1000, [&]() { d.accept(); }); diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 0925e0b..9b21801 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -512,9 +512,9 @@ Tx MainWindow::createTxFromSendPage() { } if (Settings::getInstance()->getAutoShield() && sendChangeToSapling) { + // We're finding a sapling address that is not one of the To addresses, which adds some non-determinism auto saplingAddr = std::find_if(rpc->getAllZAddresses()->begin(), rpc->getAllZAddresses()->end(), [=](auto i) -> bool { - // We're finding a sapling address that is not one of the To addresses, because zcash doesn't allow duplicated addresses - // TODO: Should we disable this in Hush? What are the privacy and chain analysis considerations? + // TODO: randomize the order we process addresses to add more non-determinism bool isSapling = Settings::getInstance()->isSaplingAddress(i); if (!isSapling) return false;