Skip to content

Commit 50f0908

Browse files
committed
[Qt] add ban functions to peers window
add ban option for peer context menu (1h, 24h, 7d, 1y).
1 parent 0143a1f commit 50f0908

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/qt/rpcconsole.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,37 @@ void RPCConsole::setClientModel(ClientModel *model)
352352
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
353353

354354
// create context menu actions
355-
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
355+
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
356+
QAction* banAction1h = new QAction(tr("&Ban Node for 1 hour"), this);
357+
QAction* banAction24h = new QAction(tr("&Ban Node for 24 hours"), this);
358+
QAction* banAction7d = new QAction(tr("&Ban Node for 7 days"), this);
359+
QAction* banAction365d = new QAction(tr("&Ban Node for 1 year"), this);
356360

357361
// create context menu
358362
contextMenu = new QMenu();
359363
contextMenu->addAction(disconnectAction);
364+
contextMenu->addAction(banAction1h);
365+
contextMenu->addAction(banAction24h);
366+
contextMenu->addAction(banAction7d);
367+
contextMenu->addAction(banAction365d);
360368

361369
// context menu signals
362370
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)));
363371
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
364372

373+
//add a signal mapping, use int instead of int64_t for bantime because signalmapper only supports int or objects
374+
//int is sufficient for our case
375+
QSignalMapper* signalMapper = new QSignalMapper(this);
376+
signalMapper->setMapping(banAction1h, 60*60);
377+
signalMapper->setMapping(banAction24h, 60*60*24);
378+
signalMapper->setMapping(banAction7d, 60*60*24*7);
379+
signalMapper->setMapping(banAction365d, 60*60*24*365);
380+
connect(banAction1h, SIGNAL(triggered()), signalMapper, SLOT(map()));
381+
connect(banAction24h, SIGNAL(triggered()), signalMapper, SLOT(map()));
382+
connect(banAction7d, SIGNAL(triggered()), signalMapper, SLOT(map()));
383+
connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map()));
384+
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(banSelectedNode(int))) ;
385+
365386
// connect the peerWidget selection model to our peerSelected() handler
366387
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
367388
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
@@ -731,6 +752,23 @@ void RPCConsole::disconnectSelectedNode()
731752
}
732753
}
733754

755+
void RPCConsole::banSelectedNode(int bantime)
756+
{
757+
// Get currently selected peer address
758+
QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address);
759+
// Find possible nodes, ban it and clear the selected node
760+
if (CNode *bannedNode = FindNode(strNode.toStdString())) {
761+
std::string nStr = strNode.toStdString();
762+
std::string addr;
763+
int port = 0;
764+
SplitHostPort(nStr, port, addr);
765+
766+
CNode::Ban(CNetAddr(addr), bantime);
767+
bannedNode->CloseSocketDisconnect();
768+
clearSelectedNode();
769+
}
770+
}
771+
734772
void RPCConsole::clearSelectedNode()
735773
{
736774
ui->peerWidget->selectionModel()->clearSelection();

src/qt/rpcconsole.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public Q_SLOTS:
8080
void peerLayoutChanged();
8181
/** Disconnect a selected node on the Peers tab */
8282
void disconnectSelectedNode();
83+
/** Ban a selected node on the Peers tab */
84+
void banSelectedNode(int bantime);
8385

8486
Q_SIGNALS:
8587
// For RPC command executor

0 commit comments

Comments
 (0)