[Qt] add ban functions to peers window
add ban option for peer context menu (1h, 24h, 7d, 1y).
This commit is contained in:
parent
0143a1f228
commit
50f090884c
@ -352,16 +352,37 @@ void RPCConsole::setClientModel(ClientModel *model)
|
|||||||
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
||||||
|
|
||||||
// create context menu actions
|
// 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
|
// create context menu
|
||||||
contextMenu = new QMenu();
|
contextMenu = new QMenu();
|
||||||
contextMenu->addAction(disconnectAction);
|
contextMenu->addAction(disconnectAction);
|
||||||
|
contextMenu->addAction(banAction1h);
|
||||||
|
contextMenu->addAction(banAction24h);
|
||||||
|
contextMenu->addAction(banAction7d);
|
||||||
|
contextMenu->addAction(banAction365d);
|
||||||
|
|
||||||
// context menu signals
|
// context menu signals
|
||||||
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)));
|
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)));
|
||||||
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
|
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 the peerWidget selection model to our peerSelected() handler
|
||||||
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
|
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
|
||||||
this, SLOT(peerSelected(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()
|
void RPCConsole::clearSelectedNode()
|
||||||
{
|
{
|
||||||
ui->peerWidget->selectionModel()->clearSelection();
|
ui->peerWidget->selectionModel()->clearSelection();
|
||||||
|
@ -80,6 +80,8 @@ public Q_SLOTS:
|
|||||||
void peerLayoutChanged();
|
void peerLayoutChanged();
|
||||||
/** Disconnect a selected node on the Peers tab */
|
/** Disconnect a selected node on the Peers tab */
|
||||||
void disconnectSelectedNode();
|
void disconnectSelectedNode();
|
||||||
|
/** Ban a selected node on the Peers tab */
|
||||||
|
void banSelectedNode(int bantime);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
// For RPC command executor
|
// For RPC command executor
|
||||||
|
Loading…
Reference in New Issue
Block a user