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. 1
      src/connection.cpp
  5. 98
      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;
}
/*
QLineEdit, QRadioButton::indicator::unchecked, QCheckBox::indicator::unchecked {
background: #222;
border: 1px solid #333;
@ -35,11 +36,13 @@ font-size: 12px;
QLineEdit:focus {
border: 1px solid #9d8400;
}
}*/
/*
QWidget QLabel {
font-size: 11pt;
}
*/
QWidget QCheckBox {
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;
min-height:25px;
font-weight:bold;
font-size:12px;
font-size:11px;
outline:0;
border:1px ridge #222;
padding: 2px 5px;

6
src/bannedpeerstablemodel.cpp

@ -60,6 +60,7 @@ int BannedPeersTableModel::columnCount(const QModelIndex&) const
case 0: return dat.address;
case 1: return dat.subnet;
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 1: return "Subnet Mask";
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();
}
qint64 BannedPeersTableModel::getASN(int row) const {
return modeldata->at(row).asn;
}
QString BannedPeersTableModel::getSubnet(int row) const {
return modeldata->at(row).subnet;
}

1
src/bannedpeerstablemodel.h

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

1
src/connection.cpp

@ -526,6 +526,7 @@ void ConnectionLoader::refreshHushdState(Connection* connection, std::function<v
void ConnectionLoader::showInformation(QString info, QString detail) {
static int rescanCount = 0;
if (detail.toLower().startsWith("rescan")) {
qDebug() << "showInformation detail = " +detail.toLower();
rescanCount++;
}

98
src/mainwindow.cpp

@ -115,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent) :
// Initialize to the balances tab
ui->tabWidget->setCurrentIndex(0);
setupSendTab();
setupTransactionsTab();
setupReceiveTab();
@ -1148,8 +1149,30 @@ void MainWindow::getQRCode(QString addr) {
// Display QR Code for address
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);
// 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();
*isDialogAlive = false;
}
@ -1450,8 +1473,10 @@ void MainWindow::setupPeersTab() {
auto bannedPeerModel = dynamic_cast<BannedPeersTableModel *>(ui->bannedPeersTable->model());
QString addr = bannedPeerModel->getAddress(index.row());
qint64 asn = bannedPeerModel->getASN(index.row());
QString ip = peer2ip(addr);
QString subnet = bannedPeerModel->getSubnet(index.row());
QString as = QString::number(asn);
//qint64 banned_until = bannedPeerModel->getBannedUntil(index.row());
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()) {
menu.addAction(tr("Unban this peer"), [=] () {
ui->statusBar->showMessage(tr("Unbanning peer..."));
@ -2190,7 +2223,7 @@ void MainWindow::rescanButtonClicked(int number) {
if (dialog.exec() == QDialog::Accepted) {
// Show message in status bar
ui->statusBar->showMessage(tr("Rescanning..."), 3 * 1000);
ui->statusBar->showMessage(tr("Rescanning..."));
// Close settings
QWidget *modalWidget = QApplication::activeModalWidget();
@ -2204,50 +2237,33 @@ void MainWindow::rescanButtonClicked(int number) {
// Call rescan RPC
rpc->rescan(rescanHeight, [=] (QJsonValue response){
qDebug() << "rescanning finished" << response;
ui->statusBar->showMessage(tr("Rescanning finished"), 3000);
});
// TODO: Display progress somewhere by reading debug.log
#ifdef Q_OS_LINUX
auto debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".hush/HUSH3/debug.log");
if(!QFile(debugLocation).exists()) {
// legacy location
debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".komodo/HUSH3/debug.log");
}
#elif defined(Q_OS_DARWIN)
auto debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, "Library/Application Support/Hush/HUSH3/debug.log");
if(!QFile(debugLocation).exists()) {
// legacy location
debugLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, "Library/Application Support/Komodo/HUSH3/debug.log");
}
#else
auto debugLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Hush/HUSH3/debug.log");
if(!QFile(debugLocation).exists()) {
// 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();
debugLog.close();
}else{
qDebug() <<"couldn't open debug.log for reading";
// Get rescan info
QTimer *rescanTimer = new QTimer(this);
QObject::connect(rescanTimer, &QTimer::timeout, [=]() {
rpc->getRescanInfo([=] (QJsonValue response){
auto rescanning = response.toObject().value("rescanning").toBool();
auto rescan_progress = response.toObject().value("rescan_progress").toString();
auto rescan_start_height = (qint64)response.toObject().value("rescan_start_height").toInt();
auto rescan_height = (qint64)response.toObject().value("rescan_height").toInt();
double percent = QString(rescan_progress).toDouble() * 100;
qDebug() << "getrescaninfo" << rescanning << " " << percent << " " << rescan_start_height << " " << rescan_height;
if(rescanning){
qDebug() << "Rescanning...";
ui->statusBar->showMessage(tr("Rescanning... ") + QString::number(percent)+ "% " + QObject::tr("at height") + " " + QString::number(rescan_height));
}
else{
qDebug() << "rescanTimer Stop";
rescanTimer->stop();
}
});
});
rescanTimer->start(1000);
}
}

25
src/qrcode.ui

@ -7,17 +7,23 @@
<x>0</x>
<y>0</y>
<width>320</width>
<height>320</height>
<height>344</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>QR Code</string>
</property>
<layout class="QFormLayout" name="formLayout">
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="0" column="0">
<item row="0" column="0" alignment="Qt::AlignTop">
<widget class="QRCodeLabel" name="qrcodeDisplayAddr">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -57,6 +63,19 @@
</property>
</widget>
</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>
</widget>
<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);
}
// 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
void RPC::setban(QString ip, QString command, const std::function<void(QJsonValue)>& cb) {
QString method = "setban";
@ -651,7 +657,6 @@ void RPC::refresh(bool force) {
getInfoThenRefresh(force);
}
void RPC::getInfoThenRefresh(bool force) {
//qDebug() << "getinfo";
if (conn == nullptr)
@ -982,11 +987,12 @@ void RPC::refreshPeers() {
QList<BannedPeerItem> peerdata;
for (const auto& it : reply.toArray()) {
auto addr = it.toObject()["address"].toString();
auto asn = (qint64)it.toObject()["mapped_as"].toInt();
auto bantime = (qint64)it.toObject()["banned_until"].toInt();
auto parts = addr.split("/");
auto ip = parts[0];
auto subnet = parts[1];
BannedPeerItem peer { ip, subnet, bantime };
BannedPeerItem peer { ip, subnet, bantime, asn };
qDebug() << "Adding banned peer with address=" << addr;
peerdata.push_back(peer);
}

2
src/rpc.h

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

2
src/settings.cpp

@ -258,7 +258,7 @@ void Settings::setAllowCustomFees(bool allow) {
QString Settings::get_theme_name() {
// Load from the QT Settings.
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;
}

Loading…
Cancel
Save