diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d02f2c1..0614c5d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1129,6 +1129,62 @@ void MainWindow::setupBalancesTab() { void MainWindow::setupPeersTab() { qDebug() << __FUNCTION__; + // Set up context menu on transactions tab + ui->peersTable->setContextMenuPolicy(Qt::CustomContextMenu); + + // Table right click + QObject::connect(ui->peersTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { + QModelIndex index = ui->peersTable->indexAt(pos); + if (index.row() < 0) return; + + QMenu menu(this); + + auto peerModel = dynamic_cast(ui->peersTable->model()); + QString addr = peerModel->getAddress(index.row()); + QString cipher = peerModel->getTLSCipher(index.row()); + qint64 asn = peerModel->getASN(index.row()); + QString ip = addr.split(":")[0]; + QString as = QString::number(asn); + + menu.addAction(tr("Copy peer address+port"), [=] () { + QGuiApplication::clipboard()->setText(addr); + ui->statusBar->showMessage(tr("Copied to clipboard"), 3 * 1000); + }); + + //TODO: support Tor correctly + menu.addAction(tr("Copy peer address"), [=] () { + QGuiApplication::clipboard()->setText(ip); + ui->statusBar->showMessage(tr("Copied to clipboard"), 3 * 1000); + }); + + menu.addAction(tr("Copy TLS ciphersuite"), [=] () { + QGuiApplication::clipboard()->setText(cipher); + ui->statusBar->showMessage(tr("Copied to clipboard"), 3 * 1000); + }); + + menu.addAction(tr("Copy ASN"), [=] () { + QGuiApplication::clipboard()->setText(as); + ui->statusBar->showMessage(tr("Copied to clipboard"), 3 * 1000); + }); + + if(!ip.isEmpty()) { + menu.addAction(tr("View host on shodan.io (3rd party service)"), [=] () { + QString url = "https://www.shodan.io/host/" + ip; + qDebug() << "opening " << url; + QDesktopServices::openUrl(QUrl(url)); + }); + } + + 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)); + }); + } + + menu.exec(ui->peersTable->viewport()->mapToGlobal(pos)); + }); } void MainWindow::setupHushTab() { diff --git a/src/peerstablemodel.cpp b/src/peerstablemodel.cpp index b89e7d7..f2c4389 100644 --- a/src/peerstablemodel.cpp +++ b/src/peerstablemodel.cpp @@ -118,10 +118,22 @@ int PeersTableModel::columnCount(const QModelIndex&) const if (role == Qt::ToolTipRole) { switch (index.column()) { - case 0: return ""; + case 0: return "Unique Peer ID"; + case 1: return "Network Address"; + case 2: return "Autonomous System Number"; + case 3: return "TLS Ciphersuite"; + case 4: return "TLS Certificate verified"; + case 5: return "Full Node Version"; + case 6: return "P2P Protocol Version"; + case 7: return "Ping Time (seconds)"; + case 8: return "Banscore"; + case 9: return "Bytes received"; + case 10: return "Bytes sent"; } } + + //TODO: show different icons for IP vs Tor vs other kinds of connections /* if (role == Qt::DecorationRole && index.column() == 0) { if (!dat.memo.isEmpty()) { @@ -149,7 +161,8 @@ int PeersTableModel::columnCount(const QModelIndex&) const QVariant PeersTableModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role == Qt::TextAlignmentRole && section == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter); + //if (role == Qt::TextAlignmentRole && section == 3) return QVariant(Qt::AlignRight | Qt::AlignVCenter); + if (role == Qt::TextAlignmentRole) return QVariant(Qt::AlignRight | Qt::AlignVCenter); if (role == Qt::FontRole) { QFont f; @@ -172,6 +185,14 @@ QString PeersTableModel::getAddress(int row) const { return modeldata->at(row).address.trimmed(); } +QString PeersTableModel::getTLSCipher(int row) const { + return modeldata->at(row).tls_cipher; +} + +qint64 PeersTableModel::getASN(int row) const { + return modeldata->at(row).asn; +} + qint64 PeersTableModel::getConntime(int row) const { return modeldata->at(row).conntime; } diff --git a/src/peerstablemodel.h b/src/peerstablemodel.h index 862a003..1c995ac 100644 --- a/src/peerstablemodel.h +++ b/src/peerstablemodel.h @@ -17,7 +17,7 @@ public: QString getAddress(int row) const; QString getType(int row) const; qint64 getConntime(int row) const; - QString getASN(int row) const; + qint64 getASN(int row) const; QString getSubver(int row) const; QString getTLSCipher(int row) const; bool getTLSVerified(int row) const;