diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-19 13:24:34 +0200 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-09-16 16:50:19 +0200 |
commit | 50f090884ccd29e439720aeb83fcd293fae34921 (patch) | |
tree | 578f740e33d6c6b4dfdcb761661f167dd08583e5 /src/qt | |
parent | 0143a1f228c3447ae2e025c697b0ad53a0d8d306 (diff) |
[Qt] add ban functions to peers window
add ban option for peer context menu (1h, 24h, 7d, 1y).
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/rpcconsole.cpp | 40 | ||||
-rw-r--r-- | src/qt/rpcconsole.h | 2 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index ec18ea8f71..2a94312be0 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -352,16 +352,37 @@ void RPCConsole::setClientModel(ClientModel *model) ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH); // create context menu actions - QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this); + QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this); + QAction* banAction1h = new QAction(tr("&Ban Node for 1 hour"), this); + QAction* banAction24h = new QAction(tr("&Ban Node for 24 hours"), this); + QAction* banAction7d = new QAction(tr("&Ban Node for 7 days"), this); + QAction* banAction365d = new QAction(tr("&Ban Node for 1 year"), this); // create context menu contextMenu = new QMenu(); contextMenu->addAction(disconnectAction); + contextMenu->addAction(banAction1h); + contextMenu->addAction(banAction24h); + contextMenu->addAction(banAction7d); + contextMenu->addAction(banAction365d); // context menu signals connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&))); connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode())); + //add a signal mapping, use int instead of int64_t for bantime because signalmapper only supports int or objects + //int is sufficient for our case + QSignalMapper* signalMapper = new QSignalMapper(this); + signalMapper->setMapping(banAction1h, 60*60); + signalMapper->setMapping(banAction24h, 60*60*24); + signalMapper->setMapping(banAction7d, 60*60*24*7); + signalMapper->setMapping(banAction365d, 60*60*24*365); + connect(banAction1h, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(banAction24h, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(banAction7d, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int))) ; + // connect the peerWidget selection model to our peerSelected() handler connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &))); @@ -731,6 +752,23 @@ void RPCConsole::disconnectSelectedNode() } } +void RPCConsole::banSelectedNode(int bantime) +{ + // Get currently selected peer address + QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address); + // Find possible nodes, ban it and clear the selected node + if (CNode *bannedNode = FindNode(strNode.toStdString())) { + std::string nStr = strNode.toStdString(); + std::string addr; + int port = 0; + SplitHostPort(nStr, port, addr); + + CNode::Ban(CNetAddr(addr), bantime); + bannedNode->CloseSocketDisconnect(); + clearSelectedNode(); + } +} + void RPCConsole::clearSelectedNode() { ui->peerWidget->selectionModel()->clearSelection(); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 1409fca525..3218a635d7 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -80,6 +80,8 @@ public Q_SLOTS: void peerLayoutChanged(); /** Disconnect a selected node on the Peers tab */ void disconnectSelectedNode(); + /** Ban a selected node on the Peers tab */ + void banSelectedNode(int bantime); Q_SIGNALS: // For RPC command executor |