Browse Source

[Qt] add ban functions to peers window

add ban option for peer context menu (1h, 24h, 7d, 1y).
pull/1/head
Jonas Schnelli 7 years ago
parent
commit
50f090884c
  1. 40
      src/qt/rpcconsole.cpp
  2. 2
      src/qt/rpcconsole.h

40
src/qt/rpcconsole.cpp

@ -352,16 +352,37 @@ void RPCConsole::setClientModel(ClientModel *model) @@ -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() @@ -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();

2
src/qt/rpcconsole.h

@ -80,6 +80,8 @@ public Q_SLOTS: @@ -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

Loading…
Cancel
Save