Browse Source

getrescaninfo and other tweaks

pull/112/head
fekt 2 years ago
parent
commit
9c1db5ff8b
  1. 7
      res/css/midnight.css
  2. 6
      src/bannedpeerstablemodel.cpp
  3. 1
      src/bannedpeerstablemodel.h
  4. 101
      src/connection.cpp
  5. 126
      src/mainwindow.cpp
  6. 25
      src/qrcode.ui
  7. 10
      src/rpc.cpp
  8. 2
      src/rpc.h
  9. 2
      src/settings.cpp

7
res/css/midnight.css

@ -23,6 +23,7 @@ QPushButton:hover {
background: #222; background: #222;
} }
/*
QLineEdit, QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked { QLineEdit, QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked {
background: #222; background: #222;
border: 1px solid #333; border: 1px solid #333;
@ -35,11 +36,13 @@ font-size: 12px;
QLineEdit:focus { QLineEdit:focus {
border: 1px solid #9d8400; border: 1px solid #9d8400;
} }*/
/*
QWidget QLabel { QWidget QLabel {
font-size: 11pt; font-size: 11pt;
} }
*/
QWidget QCheckBox { QWidget QCheckBox {
font-weight: bold; font-weight: bold;
@ -74,7 +77,7 @@ background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.25, stop: 0 #333, st
color:#fff; color:#fff;
min-height:25px; min-height:25px;
font-weight:bold; font-weight:bold;
font-size:12px; font-size:11px;
outline:0; outline:0;
border:1px ridge #222; border:1px ridge #222;
padding: 2px 5px; padding: 2px 5px;

6
src/bannedpeerstablemodel.cpp

@ -60,6 +60,7 @@ int BannedPeersTableModel::columnCount(const QModelIndex&) const
case 0: return dat.address; case 0: return dat.address;
case 1: return dat.subnet; case 1: return dat.subnet;
case 2: return QDateTime::fromSecsSinceEpoch(dat.banned_until).toLocalTime().toString(); case 2: return QDateTime::fromSecsSinceEpoch(dat.banned_until).toLocalTime().toString();
case 3: return "AS" + QString::number(dat.asn);
} }
} }
@ -69,6 +70,7 @@ int BannedPeersTableModel::columnCount(const QModelIndex&) const
case 0: return "Network Address"; case 0: return "Network Address";
case 1: return "Subnet Mask"; case 1: return "Subnet Mask";
case 2: return "Banned Until " + QDateTime::fromSecsSinceEpoch(dat.banned_until).toUTC().toString(); case 2: return "Banned Until " + QDateTime::fromSecsSinceEpoch(dat.banned_until).toUTC().toString();
case 3: return "Autonomous System Number";
} }
} }
@ -120,6 +122,10 @@ QString BannedPeersTableModel::getAddress(int row) const {
return modeldata->at(row).address.trimmed(); return modeldata->at(row).address.trimmed();
} }
qint64 BannedPeersTableModel::getASN(int row) const {
return modeldata->at(row).asn;
}
QString BannedPeersTableModel::getSubnet(int row) const { QString BannedPeersTableModel::getSubnet(int row) const {
return modeldata->at(row).subnet; return modeldata->at(row).subnet;
} }

1
src/bannedpeerstablemodel.h

@ -15,6 +15,7 @@ public:
QString getSubnet(int row) const; QString getSubnet(int row) const;
QString getAddress(int row) const; QString getAddress(int row) const;
qint64 getASN(int row) const;
qint64 getBannedUntil(int row) const; qint64 getBannedUntil(int row) const;
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const;

101
src/connection.cpp

@ -68,12 +68,12 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
} else { } else {
if (config->hushDaemon) { if (config->hushDaemon) {
// hushd is configured to run as a daemon, so we must wait for a few seconds // hushd is configured to run as a daemon, so we must wait for a few seconds
// to let it start up. // to let it start up.
main->logger->write("hushd is daemon=1. Waiting for it to start up"); main->logger->write("hushd is daemon=1. Waiting for it to start up");
this->showInformation(QObject::tr("hushd is set to run as daemon"), QObject::tr("Waiting for hushd")); this->showInformation(QObject::tr("hushd is set to run as daemon"), QObject::tr("Waiting for hushd"));
QTimer::singleShot(5000, [=]() { doAutoConnect(/* don't attempt to start ehushd */ false); }); QTimer::singleShot(5000, [=]() { doAutoConnect(/* don't attempt to start ehushd */ false); });
} else { } else {
// Something is wrong. // Something is wrong.
// We're going to attempt to connect to the one in the background one last time // We're going to attempt to connect to the one in the background one last time
// and see if that works, else throw an error // and see if that works, else throw an error
main->logger->write("Unknown problem while trying to start hushd!"); main->logger->write("Unknown problem while trying to start hushd!");
@ -81,7 +81,7 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
} }
} }
} else { } else {
// We tried to start ehushd previously, and it didn't work. So, show the error. // 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"); main->logger->write("Couldn't start embedded hushd for unknown reason");
QString explanation; QString explanation;
if (config->hushDaemon) { if (config->hushDaemon) {
@ -90,18 +90,18 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
"Please remove the following line from your HUSH3.conf and restart SilentDragon\n" "Please remove the following line from your HUSH3.conf and restart SilentDragon\n"
"daemon=1"); "daemon=1");
} else { } else {
explanation = QString() % QObject::tr("Couldn't start the embedded hushd.\n\n" explanation = QString() % QObject::tr("Couldn't start the embedded hushd.\n\n"
"Please try restarting.\n\nIf you previously started hushd with custom arguments, you might need to reset HUSH3.conf.\n\n" "Please try restarting.\n\nIf you previously started hushd with custom arguments, you might need to reset HUSH3.conf.\n\n"
"If all else fails, please run hushd manually.") % "If all else fails, please run hushd manually.") %
(ehushd ? QObject::tr("The process returned") + ":\n\n" % ehushd->errorString() : QString("")); (ehushd ? QObject::tr("The process returned") + ":\n\n" % ehushd->errorString() : QString(""));
} }
this->showError(explanation); this->showError(explanation);
} }
} else { } else {
// HUSH3.conf exists, there's no connection, and the user asked us not to start hushd. Error! // HUSH3.conf exists, there's no connection, and the user asked us not to start hushd. Error!
main->logger->write("Not using embedded and couldn't connect to hushd"); main->logger->write("Not using embedded and couldn't connect to hushd");
QString explanation = QString() % QObject::tr("Couldn't connect to hushd configured in HUSH3.conf.\n\n" QString explanation = QString() % QObject::tr("Couldn't connect to hushd configured in HUSH3.conf.\n\n"
"Not starting embedded hushd because --no-embedded was passed"); "Not starting embedded hushd because --no-embedded was passed");
this->showError(explanation); this->showError(explanation);
} }
@ -114,7 +114,7 @@ void ConnectionLoader::doAutoConnect(bool tryEhushdStart) {
// Fall back to manual connect // Fall back to manual connect
doManualConnect(); doManualConnect();
} }
} }
} }
QString randomPassword() { QString randomPassword() {
@ -136,7 +136,7 @@ QString randomPassword() {
/** /**
* This will create a new HUSH3.conf and download params if they cannot be found * This will create a new HUSH3.conf and download params if they cannot be found
*/ */
void ConnectionLoader::createHushConf() { void ConnectionLoader::createHushConf() {
main->logger->write(__func__); main->logger->write(__func__);
@ -260,7 +260,7 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
} }
// The downloaded file is written to a new name, and then renamed when the operation completes. // The downloaded file is written to a new name, and then renamed when the operation completes.
currentOutput = new QFile(QDir(paramsDir).filePath(filename + ".part")); currentOutput = new QFile(QDir(paramsDir).filePath(filename + ".part"));
if (!currentOutput->open(QIODevice::WriteOnly)) { if (!currentOutput->open(QIODevice::WriteOnly)) {
main->logger->write("Couldn't open " + currentOutput->fileName() + " for writing"); main->logger->write("Couldn't open " + currentOutput->fileName() + " for writing");
@ -268,12 +268,12 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
} }
main->logger->write("Downloading to " + filename); main->logger->write("Downloading to " + filename);
qDebug() << "Downloading " << url << " to " << filename; qDebug() << "Downloading " << url << " to " << filename;
QNetworkRequest request(url); QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
currentDownload = client->get(request); currentDownload = client->get(request);
downloadTime.start(); downloadTime.start();
// Download Progress // Download Progress
QObject::connect(currentDownload, &QNetworkReply::downloadProgress, [=] (auto done, auto total) { QObject::connect(currentDownload, &QNetworkReply::downloadProgress, [=] (auto done, auto total) {
// calculate the download speed // calculate the download speed
@ -293,7 +293,7 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
QObject::tr("Downloading ") % filename % (filesRemaining > 1 ? " ( +" % QString::number(filesRemaining) % QObject::tr(" more remaining )") : QString("")), QObject::tr("Downloading ") % filename % (filesRemaining > 1 ? " ( +" % QString::number(filesRemaining) % QObject::tr(" more remaining )") : QString("")),
QString::number(done/1024/1024, 'f', 0) % QObject::tr("MB of ") % QString::number(total/1024/1024, 'f', 0) + QObject::tr("MB at ") % QString::number(speed, 'f', 2) % unit); QString::number(done/1024/1024, 'f', 0) % QObject::tr("MB of ") % QString::number(total/1024/1024, 'f', 0) + QObject::tr("MB at ") % QString::number(speed, 'f', 2) % unit);
}); });
// Download Finished // Download Finished
QObject::connect(currentDownload, &QNetworkReply::finished, [=] () { QObject::connect(currentDownload, &QNetworkReply::finished, [=] () {
// Rename file // Rename file
@ -306,22 +306,22 @@ void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
if (currentDownload->error()) { if (currentDownload->error()) {
main->logger->write("Downloading " + filename + " failed"); main->logger->write("Downloading " + filename + " failed");
this->showError(QObject::tr("Downloading ") + filename + QObject::tr(" failed. Please check the help site for more info")); this->showError(QObject::tr("Downloading ") + filename + QObject::tr(" failed. Please check the help site for more info"));
} else { } else {
doNextDownload(cb); doNextDownload(cb);
} }
}); });
// Download new data available. // Download new data available.
QObject::connect(currentDownload, &QNetworkReply::readyRead, [=] () { QObject::connect(currentDownload, &QNetworkReply::readyRead, [=] () {
currentOutput->write(currentDownload->readAll()); currentOutput->write(currentDownload->readAll());
}); });
} }
bool ConnectionLoader::startEmbeddedHushd() { bool ConnectionLoader::startEmbeddedHushd() {
if (!Settings::getInstance()->useEmbedded()) if (!Settings::getInstance()->useEmbedded())
return false; return false;
main->logger->write("Trying to start embedded hushd"); main->logger->write("Trying to start embedded hushd");
// Static because it needs to survive even after this method returns. // Static because it needs to survive even after this method returns.
@ -330,13 +330,13 @@ bool ConnectionLoader::startEmbeddedHushd() {
if (ehushd != nullptr) { if (ehushd != nullptr) {
if (ehushd->state() == QProcess::NotRunning) { if (ehushd->state() == QProcess::NotRunning) {
if (!processStdErrOutput.isEmpty()) { if (!processStdErrOutput.isEmpty()) {
QMessageBox::critical(main, QObject::tr("hushd error"), "hushd said: " + processStdErrOutput, QMessageBox::critical(main, QObject::tr("hushd error"), "hushd said: " + processStdErrOutput,
QMessageBox::Ok); QMessageBox::Ok);
} }
return false; return false;
} else { } else {
return true; return true;
} }
} }
QDir appPath(QCoreApplication::applicationDirPath()); QDir appPath(QCoreApplication::applicationDirPath());
@ -346,7 +346,7 @@ bool ConnectionLoader::startEmbeddedHushd() {
#else #else
auto hushdProgram = appPath.absoluteFilePath("hushd"); auto hushdProgram = appPath.absoluteFilePath("hushd");
#endif #endif
//if (!QFile(hushdProgram).exists()) { //if (!QFile(hushdProgram).exists()) {
if (!QFile::exists(hushdProgram)) { if (!QFile::exists(hushdProgram)) {
qDebug() << "Can't find hushd at " << hushdProgram; qDebug() << "Can't find hushd at " << hushdProgram;
@ -435,7 +435,7 @@ void ConnectionLoader::doManualConnect() {
auto connection = makeConnection(config); auto connection = makeConnection(config);
refreshHushdState(connection, [=] () { refreshHushdState(connection, [=] () {
QString explanation = QString() QString explanation = QString()
% QObject::tr("Could not connect to hushd configured in settings.\n\n" % QObject::tr("Could not connect to hushd configured in settings.\n\n"
"Please set the host/port and user/password in the Edit->Settings menu."); "Please set the host/port and user/password in the Edit->Settings menu.");
showError(explanation); showError(explanation);
@ -448,7 +448,7 @@ void ConnectionLoader::doManualConnect() {
void ConnectionLoader::doRPCSetConnection(Connection* conn) { void ConnectionLoader::doRPCSetConnection(Connection* conn) {
rpc->setEHushd(ehushd); rpc->setEHushd(ehushd);
rpc->setConnection(conn); rpc->setConnection(conn);
d->accept(); d->accept();
delete this; delete this;
@ -456,7 +456,7 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn) {
Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config) { Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config) {
QNetworkAccessManager* client = new QNetworkAccessManager(main); QNetworkAccessManager* client = new QNetworkAccessManager(main);
QUrl myurl; QUrl myurl;
myurl.setScheme("http"); myurl.setScheme("http");
myurl.setHost(config.get()->host); myurl.setHost(config.get()->host);
@ -465,10 +465,10 @@ Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> c
QNetworkRequest* request = new QNetworkRequest(); QNetworkRequest* request = new QNetworkRequest();
request->setUrl(myurl); request->setUrl(myurl);
request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain"); request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
QString userpass = config.get()->rpcuser % ":" % config.get()->rpcpassword; QString userpass = config.get()->rpcuser % ":" % config.get()->rpcpassword;
QString headerData = "Basic " + userpass.toLocal8Bit().toBase64(); QString headerData = "Basic " + userpass.toLocal8Bit().toBase64();
request->setRawHeader("Authorization", headerData.toLocal8Bit()); request->setRawHeader("Authorization", headerData.toLocal8Bit());
return new Connection(main, client, request, config); return new Connection(main, client, request, config);
} }
@ -489,20 +489,20 @@ void ConnectionLoader::refreshHushdState(Connection* connection, std::function<v
QTimer::singleShot(1000, [=]() { this->doRPCSetConnection(connection); }); QTimer::singleShot(1000, [=]() { this->doRPCSetConnection(connection); });
}, },
[=] (QNetworkReply* reply, const QJsonValue &res) { [=] (QNetworkReply* reply, const QJsonValue &res) {
// Failed, see what it is. // Failed, see what it is.
auto err = reply->error(); auto err = reply->error();
//qDebug() << err << res; //qDebug() << err << res;
if (err == QNetworkReply::NetworkError::ConnectionRefusedError) { if (err == QNetworkReply::NetworkError::ConnectionRefusedError) {
refused(); refused();
} else if (err == QNetworkReply::NetworkError::AuthenticationRequiredError) { } else if (err == QNetworkReply::NetworkError::AuthenticationRequiredError) {
main->logger->write("Authentication failed"); main->logger->write("Authentication failed");
QString explanation = QString() % QString explanation = QString() %
QObject::tr("Authentication failed. The username / password you specified was " QObject::tr("Authentication failed. The username / password you specified was "
"not accepted by hushd. Try changing it in the Edit->Settings menu"); "not accepted by hushd. Try changing it in the Edit->Settings menu");
this->showError(explanation); this->showError(explanation);
} else if (err == QNetworkReply::NetworkError::InternalServerError && } else if (err == QNetworkReply::NetworkError::InternalServerError &&
!res.isNull()) { !res.isNull()) {
// The server is loading, so just poll until it succeeds // The server is loading, so just poll until it succeeds
QString status = res["error"].toObject()["message"].toString(); QString status = res["error"].toObject()["message"].toString();
@ -526,9 +526,10 @@ void ConnectionLoader::refreshHushdState(Connection* connection, std::function<v
void ConnectionLoader::showInformation(QString info, QString detail) { void ConnectionLoader::showInformation(QString info, QString detail) {
static int rescanCount = 0; static int rescanCount = 0;
if (detail.toLower().startsWith("rescan")) { if (detail.toLower().startsWith("rescan")) {
qDebug() << "showInformation detail = " +detail.toLower();
rescanCount++; rescanCount++;
} }
if (rescanCount > 10) { if (rescanCount > 10) {
detail = detail + "\n" + QObject::tr("This may take several hours, grab some popcorn"); detail = detail + "\n" + QObject::tr("This may take several hours, grab some popcorn");
} }
@ -541,9 +542,9 @@ void ConnectionLoader::showInformation(QString info, QString detail) {
} }
/** /**
* Show error will close the loading dialog and show an error. * Show error will close the loading dialog and show an error.
*/ */
void ConnectionLoader::showError(QString explanation) { void ConnectionLoader::showError(QString explanation) {
rpc->setEHushd(nullptr); rpc->setEHushd(nullptr);
rpc->noConnection(); rpc->noConnection();
@ -659,8 +660,8 @@ bool ConnectionLoader::verifyParams() {
/** /**
* Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters * Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters
*/ */
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() { std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
auto confLocation = locateHushConfFile(); auto confLocation = locateHushConfFile();
if (confLocation.isNull()) { if (confLocation.isNull()) {
@ -682,7 +683,7 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
hushconf->usingHushConf = true; hushconf->usingHushConf = true;
hushconf->hushDir = QFileInfo(confLocation).absoluteDir().absolutePath(); hushconf->hushDir = QFileInfo(confLocation).absoluteDir().absolutePath();
hushconf->hushDaemon = false; hushconf->hushDaemon = false;
Settings::getInstance()->setUsingHushConf(confLocation); Settings::getInstance()->setUsingHushConf(confLocation);
while (!in.atEnd()) { while (!in.atEnd()) {
@ -733,21 +734,21 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectHushConf() {
hushconf->rpcuser, hushconf->rpcuser,
hushconf->rpcpassword); hushconf->rpcpassword);
// In addition to the HUSH3/HUSH3.conf file, also double check the params. // In addition to the HUSH3/HUSH3.conf file, also double check the params.
return std::shared_ptr<ConnectionConfig>(hushconf); return std::shared_ptr<ConnectionConfig>(hushconf);
} }
// Load connection settings from the UI, which indicates an unknown, external hushd // Load connection settings from the UI, which indicates an unknown, external hushd
std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() { std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
// Load from the QT Settings. // Load from the QT Settings.
QSettings s; QSettings s;
auto host = s.value("connection/host").toString(); auto host = s.value("connection/host").toString();
auto port = s.value("connection/port").toString(); auto port = s.value("connection/port").toString();
auto username = s.value("connection/rpcuser").toString(); auto username = s.value("connection/rpcuser").toString();
auto password = s.value("connection/rpcpassword").toString(); auto password = s.value("connection/rpcpassword").toString();
if (username.isEmpty() || password.isEmpty()) if (username.isEmpty() || password.isEmpty())
return nullptr; return nullptr;
@ -762,8 +763,8 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::loadFromSettings() {
/*********************************************************************************** /***********************************************************************************
* Connection Class * Connection Class
************************************************************************************/ ************************************************************************************/
Connection::Connection(MainWindow* m, QNetworkAccessManager* c, QNetworkRequest* r, Connection::Connection(MainWindow* m, QNetworkAccessManager* c, QNetworkRequest* r,
std::shared_ptr<ConnectionConfig> conf) { std::shared_ptr<ConnectionConfig> conf) {
this->restclient = c; this->restclient = c;
this->request = r; this->request = r;
@ -796,7 +797,7 @@ void Connection::doRPC(const QJsonValue& payload, const std::function<void(QJson
// Ignoring callback because shutdown in progress // Ignoring callback because shutdown in progress
return; return;
} }
QJsonDocument jd_reply = QJsonDocument::fromJson(reply->readAll()); QJsonDocument jd_reply = QJsonDocument::fromJson(reply->readAll());
QJsonValue parsed; QJsonValue parsed;
@ -808,13 +809,13 @@ void Connection::doRPC(const QJsonValue& payload, const std::function<void(QJson
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
ne(reply, parsed); ne(reply, parsed);
return; return;
} }
if (parsed.isNull()) { if (parsed.isNull()) {
ne(reply, "Unknown error"); ne(reply, "Unknown error");
} }
cb(parsed["result"]); cb(parsed["result"]);
}); });
} }
@ -850,7 +851,7 @@ void Connection::showTxError(const QString& error) {
/** /**
* Prevent all future calls from going through * Prevent all future calls from going through
*/ */
void Connection::shutdown() { void Connection::shutdown() {
shutdownInProgress = true; shutdownInProgress = true;
} }

126
src/mainwindow.cpp

@ -115,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent) :
// Initialize to the balances tab // Initialize to the balances tab
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
setupSendTab(); setupSendTab();
setupTransactionsTab(); setupTransactionsTab();
setupReceiveTab(); setupReceiveTab();
@ -510,7 +511,7 @@ void MainWindow::setupSettingsModal() {
} }
settings.chkzindex->setChecked(isUsingZindex); settings.chkzindex->setChecked(isUsingZindex);
if (rpc->getEHushD() == nullptr) { if (rpc->getEHushD() == nullptr) {
settings.chkzindex->setEnabled(false); settings.chkzindex->setEnabled(false);
} }
// Connection Settings // Connection Settings
@ -530,7 +531,7 @@ void MainWindow::setupSettingsModal() {
settings.hostname->setEnabled(true); settings.hostname->setEnabled(true);
settings.port->setEnabled(true); settings.port->setEnabled(true);
settings.rpcuser->setEnabled(true); settings.rpcuser->setEnabled(true);
settings.rpcpassword->setEnabled(true); settings.rpcpassword->setEnabled(true);
} }
// Load current values into the dialog // Load current values into the dialog
@ -715,21 +716,21 @@ void MainWindow::setupSettingsModal() {
if (!rpc->getConnection()->config->consolidation.isEmpty()==false) { if (!rpc->getConnection()->config->consolidation.isEmpty()==false) {
if (settings.chkConso->isChecked()) { if (settings.chkConso->isChecked()) {
Settings::addToHushConf(hushConfLocation, "consolidation=1"); Settings::addToHushConf(hushConfLocation, "consolidation=1");
showRestartInfo = true; showRestartInfo = true;
} }
} }
if (!rpc->getConnection()->config->consolidation.isEmpty()) { if (!rpc->getConnection()->config->consolidation.isEmpty()) {
if (settings.chkConso->isChecked() == false) { if (settings.chkConso->isChecked() == false) {
Settings::removeFromHushConf(hushConfLocation, "consolidation"); Settings::removeFromHushConf(hushConfLocation, "consolidation");
showRestartInfo = true; showRestartInfo = true;
} }
} }
if (!rpc->getConnection()->config->deletetx.isEmpty() == false) { if (!rpc->getConnection()->config->deletetx.isEmpty() == false) {
if (settings.chkDeletetx->isChecked()) { if (settings.chkDeletetx->isChecked()) {
Settings::addToHushConf(hushConfLocation, "deletetx=1"); Settings::addToHushConf(hushConfLocation, "deletetx=1");
showRestartInfo = true; showRestartInfo = true;
} }
} }
@ -739,12 +740,12 @@ void MainWindow::setupSettingsModal() {
showRestartInfo = true; showRestartInfo = true;
} }
} }
if (!rpc->getConnection()->config->zindex.isEmpty() == false) { if (!rpc->getConnection()->config->zindex.isEmpty() == false) {
if (settings.chkzindex->isChecked()) { if (settings.chkzindex->isChecked()) {
Settings::addToHushConf(hushConfLocation, "zindex=1"); Settings::addToHushConf(hushConfLocation, "zindex=1");
Settings::addToHushConf(hushConfLocation, "reindex=1"); Settings::addToHushConf(hushConfLocation, "reindex=1");
showReindexInfo = true; showReindexInfo = true;
} }
} }
@ -752,10 +753,10 @@ void MainWindow::setupSettingsModal() {
if (settings.chkzindex->isChecked() == false) { if (settings.chkzindex->isChecked() == false) {
Settings::removeFromHushConf(hushConfLocation, "zindex"); Settings::removeFromHushConf(hushConfLocation, "zindex");
Settings::addToHushConf(hushConfLocation, "reindex=1"); Settings::addToHushConf(hushConfLocation, "reindex=1");
showReindexInfo = true; showReindexInfo = true;
} }
} }
if (showRestartInfo) { if (showRestartInfo) {
auto desc = tr("SilentDragon needs to restart to rescan,reindex,consolidation or deletetx. SilentDragon will now close, please restart SilentDragon to continue"); auto desc = tr("SilentDragon needs to restart to rescan,reindex,consolidation or deletetx. SilentDragon will now close, please restart SilentDragon to continue");
@ -1148,8 +1149,30 @@ void MainWindow::getQRCode(QString addr) {
// Display QR Code for address // Display QR Code for address
qrui.qrcodeDisplayAddr->setQrcodeString(addr); qrui.qrcodeDisplayAddr->setQrcodeString(addr);
// Set text/tip
qrui.saveQRCodeBtn->setText(tr("Save"));
qrui.saveQRCodeBtn->setToolTip(tr("Save QR Code to file"));
auto isDialogAlive = std::make_shared<bool>(true); auto isDialogAlive = std::make_shared<bool>(true);
// Connect and handle Save button
QObject::connect(qrui.saveQRCodeBtn, &QPushButton::clicked, [&] () {
qDebug() << "Save QR Code clicked";
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save QR Code to file"), "",
tr("Portable Network Graphics (*.png);;All Files (*)"));
if (fileName.isEmpty())
return;
else {
QFile file(fileName);
// TODO: fix this. Saves as black image instead of QR code
qrui.qrcodeDisplayAddr->grab().save(fileName, "png", -1);
statusBar()->showMessage(tr("QR code saved"), 3000);
d.close();
}
});
d.exec(); d.exec();
*isDialogAlive = false; *isDialogAlive = false;
} }
@ -1336,11 +1359,11 @@ void MainWindow::setupBalancesTab() {
qDebug() << "ShieldCoinbase reply=" << reply; qDebug() << "ShieldCoinbase reply=" << reply;
// By default we shield 50 blocks at a time // By default we shield 50 blocks at a time
if(remainingUTXOs > 0) { if(remainingUTXOs > 0) {
//TODO: more utxos to shield //TODO: more utxos to shield
} }
ui->statusBar->showMessage(tr("Shielded") + shieldingValue + " HUSH in Mining funds to " + addr + " in opid " + opid, 3 * 1000); ui->statusBar->showMessage(tr("Shielded") + shieldingValue + " HUSH in Mining funds to " + addr + " in opid " + opid, 3 * 1000);
}, [=](QString errStr) { }, [=](QString errStr) {
//error("", errStr); //error("", errStr);
qDebug() << "z_shieldcoinbase pooped:" << errStr; qDebug() << "z_shieldcoinbase pooped:" << errStr;
if(errStr == "Could not find any coinbase funds to shield.") { if(errStr == "Could not find any coinbase funds to shield.") {
ui->statusBar->showMessage("No mining funds found to shield!"); ui->statusBar->showMessage("No mining funds found to shield!");
@ -1450,8 +1473,10 @@ void MainWindow::setupPeersTab() {
auto bannedPeerModel = dynamic_cast<BannedPeersTableModel *>(ui->bannedPeersTable->model()); auto bannedPeerModel = dynamic_cast<BannedPeersTableModel *>(ui->bannedPeersTable->model());
QString addr = bannedPeerModel->getAddress(index.row()); QString addr = bannedPeerModel->getAddress(index.row());
qint64 asn = bannedPeerModel->getASN(index.row());
QString ip = peer2ip(addr); QString ip = peer2ip(addr);
QString subnet = bannedPeerModel->getSubnet(index.row()); QString subnet = bannedPeerModel->getSubnet(index.row());
QString as = QString::number(asn);
//qint64 banned_until = bannedPeerModel->getBannedUntil(index.row()); //qint64 banned_until = bannedPeerModel->getBannedUntil(index.row());
if(!ip.isEmpty()) { if(!ip.isEmpty()) {
@ -1471,6 +1496,14 @@ void MainWindow::setupPeersTab() {
}); });
} }
if(!as.isEmpty()) {
menu.addAction(tr("View ASN on bgpview.io (3rd party service)"), [=] () {
QString url = "https://bgpview.io/asn/" + as;
qDebug() << "opening " << url;
QDesktopServices::openUrl(QUrl(url));
});
}
if(!ip.isEmpty()) { if(!ip.isEmpty()) {
menu.addAction(tr("Unban this peer"), [=] () { menu.addAction(tr("Unban this peer"), [=] () {
ui->statusBar->showMessage(tr("Unbanning peer...")); ui->statusBar->showMessage(tr("Unbanning peer..."));
@ -1585,7 +1618,7 @@ void MainWindow::setupPeersTab() {
#elif defined(Q_OS_DARWIN) #elif defined(Q_OS_DARWIN)
debuglog = "~/Library/Application Support/Komodo/HUSH3/debug.log"; debuglog = "~/Library/Application Support/Komodo/HUSH3/debug.log";
#elif defined(Q_OS_WIN64) #elif defined(Q_OS_WIN64)
// "C:/Users/<USER>/AppData/Roaming/<APPNAME>", // "C:/Users/<USER>/AppData/Roaming/<APPNAME>",
// TODO: get current username // TODO: get current username
debuglog = "C:/Users/<USER>/AppData/Roaming/Komodo/HUSH3/debug.log"; debuglog = "C:/Users/<USER>/AppData/Roaming/Komodo/HUSH3/debug.log";
#else #else
@ -2190,7 +2223,7 @@ void MainWindow::rescanButtonClicked(int number) {
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
// Show message in status bar // Show message in status bar
ui->statusBar->showMessage(tr("Rescanning..."), 3 * 1000); ui->statusBar->showMessage(tr("Rescanning..."));
// Close settings // Close settings
QWidget *modalWidget = QApplication::activeModalWidget(); QWidget *modalWidget = QApplication::activeModalWidget();
@ -2204,50 +2237,33 @@ void MainWindow::rescanButtonClicked(int number) {
// Call rescan RPC // Call rescan RPC
rpc->rescan(rescanHeight, [=] (QJsonValue response){ rpc->rescan(rescanHeight, [=] (QJsonValue response){
qDebug() << "rescanning finished" << response; qDebug() << "rescanning finished" << response;
ui->statusBar->showMessage(tr("Rescanning finished"), 3000);
}); });
// TODO: Display progress somewhere by reading debug.log // Get rescan info
#ifdef Q_OS_LINUX QTimer *rescanTimer = new QTimer(this);
auto debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".hush/HUSH3/debug.log"); QObject::connect(rescanTimer, &QTimer::timeout, [=]() {
if(!QFile(debugLocation).exists()) { rpc->getRescanInfo([=] (QJsonValue response){
// legacy location
debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".komodo/HUSH3/debug.log");
} auto rescanning = response.toObject().value("rescanning").toBool();
#elif defined(Q_OS_DARWIN) auto rescan_progress = response.toObject().value("rescan_progress").toString();
auto debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, "Library/Application Support/Hush/HUSH3/debug.log"); auto rescan_start_height = (qint64)response.toObject().value("rescan_start_height").toInt();
if(!QFile(debugLocation).exists()) { auto rescan_height = (qint64)response.toObject().value("rescan_height").toInt();
// legacy location double percent = QString(rescan_progress).toDouble() * 100;
debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, "Library/Application Support/Komodo/HUSH3/debug.log"); qDebug() << "getrescaninfo" << rescanning << " " << percent << " " << rescan_start_height << " " << rescan_height;
}
#else if(rescanning){
auto debugLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Hush/HUSH3/debug.log"); qDebug() << "Rescanning...";
if(!QFile(debugLocation).exists()) { ui->statusBar->showMessage(tr("Rescanning... ") + QString::number(percent)+ "% " + QObject::tr("at height") + " " + QString::number(rescan_height));
// legacy location
debugLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Komodo/HUSH3/debug.log");
}
#endif
if(QFile(debugLocation).exists()){
qDebug() << "Found debug.log at "+ debugLocation;
QFile debugLog(debugLocation);
if(debugLog.open(QIODevice::ReadOnly)){
debugLog.seek(debugLog.size()-1);
int count = 0;
int lines = 25;
while ( (count < lines) && (debugLog.pos() > 0) )
{
QString ch = debugLog.read(1);
debugLog.seek(debugLog.pos()-2);
if (ch == "\n")
count++;
} }
qDebug() << "debug.log =" + debugLog.readAll(); else{
debugLog.close(); qDebug() << "rescanTimer Stop";
}else{ rescanTimer->stop();
qDebug() <<"couldn't open debug.log for reading"; }
} });
} });
rescanTimer->start(1000);
} }
} }

25
src/qrcode.ui

@ -7,17 +7,23 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>320</width> <width>320</width>
<height>320</height> <height>344</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>QR Code</string> <string>QR Code</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum> <enum>QLayout::SetFixedSize</enum>
</property> </property>
<item row="0" column="0"> <item row="0" column="0" alignment="Qt::AlignTop">
<widget class="QRCodeLabel" name="qrcodeDisplayAddr"> <widget class="QRCodeLabel" name="qrcodeDisplayAddr">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -57,6 +63,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QPushButton" name="saveQRCodeBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

10
src/rpc.cpp

@ -167,6 +167,12 @@ void RPC::rescan(qint64 height, const std::function<void(QJsonValue)>& cb) {
conn->doRPCWithDefaultErrorHandling(makePayload(method, height), cb); conn->doRPCWithDefaultErrorHandling(makePayload(method, height), cb);
} }
// get rescan info
void RPC::getRescanInfo(const std::function<void(QJsonValue)>& cb){
QString method = "getrescaninfo";
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb);
}
// add/remove a banned node. ip can include an optional netmask // add/remove a banned node. ip can include an optional netmask
void RPC::setban(QString ip, QString command, const std::function<void(QJsonValue)>& cb) { void RPC::setban(QString ip, QString command, const std::function<void(QJsonValue)>& cb) {
QString method = "setban"; QString method = "setban";
@ -651,7 +657,6 @@ void RPC::refresh(bool force) {
getInfoThenRefresh(force); getInfoThenRefresh(force);
} }
void RPC::getInfoThenRefresh(bool force) { void RPC::getInfoThenRefresh(bool force) {
//qDebug() << "getinfo"; //qDebug() << "getinfo";
if (conn == nullptr) if (conn == nullptr)
@ -982,11 +987,12 @@ void RPC::refreshPeers() {
QList<BannedPeerItem> peerdata; QList<BannedPeerItem> peerdata;
for (const auto& it : reply.toArray()) { for (const auto& it : reply.toArray()) {
auto addr = it.toObject()["address"].toString(); auto addr = it.toObject()["address"].toString();
auto asn = (qint64)it.toObject()["mapped_as"].toInt();
auto bantime = (qint64)it.toObject()["banned_until"].toInt(); auto bantime = (qint64)it.toObject()["banned_until"].toInt();
auto parts = addr.split("/"); auto parts = addr.split("/");
auto ip = parts[0]; auto ip = parts[0];
auto subnet = parts[1]; auto subnet = parts[1];
BannedPeerItem peer { ip, subnet, bantime }; BannedPeerItem peer { ip, subnet, bantime, asn };
qDebug() << "Adding banned peer with address=" << addr; qDebug() << "Adding banned peer with address=" << addr;
peerdata.push_back(peer); peerdata.push_back(peer);
} }

2
src/rpc.h

@ -27,6 +27,7 @@ struct BannedPeerItem {
QString address; QString address;
QString subnet; QString subnet;
qint64 banned_until; qint64 banned_until;
qint64 asn;
}; };
struct PeerItem { struct PeerItem {
@ -118,6 +119,7 @@ public:
Connection* getConnection() { return conn; } Connection* getConnection() { return conn; }
void rescan(qint64 height, const std::function<void(QJsonValue)>& cb); void rescan(qint64 height, const std::function<void(QJsonValue)>& cb);
void getRescanInfo(const std::function<void(QJsonValue)>& cb);
private: private:
void refreshBalances(); void refreshBalances();

2
src/settings.cpp

@ -258,7 +258,7 @@ void Settings::setAllowCustomFees(bool allow) {
QString Settings::get_theme_name() { QString Settings::get_theme_name() {
// Load from the QT Settings. // Load from the QT Settings.
QString theme_name = QSettings().value("options/theme_name", false).toString(); QString theme_name = QSettings().value("options/theme_name", false).toString();
qDebug() << __func__ << ": theme_name=" << theme_name; //qDebug() << __func__ << ": theme_name=" << theme_name;
return theme_name; return theme_name;
} }

Loading…
Cancel
Save