Skip to content

Commit 9985013

Browse files
committed
Merge #717: Use the stored CSubNet entry when unbanning
4be57a5 gui: fix comments for BanTableModel and BanTablePriv::refreshBanlist() (Vasil Dimov) a981af4 gui: use the stored CSubNet entry when unbanning (Vasil Dimov) Pull request description: The previous code visualized the `CSubNet` object as string, then parsed that string back to `CSubNet`. This is sub-optimal given that the original `CSubNet` object can be used directly instead. This avoids calling `LookupSubNet()` from the GUI. ACKs for top commit: furszy: utACK 4be57a5 mzumsande: Tested ACK 4be57a5 Tree-SHA512: b783c18c9d676aa9486cff2d27039dd5c5ef3f1cc67e5056a2be68e35930926f368f26dacdf4f3d394a1f73e3e28f42dc8a6936cd1765c6e6e60695c7b4d78af
2 parents 23e2bfc + 4be57a5 commit 9985013

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/qt/bantablemodel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BanTablePriv
4343
/** Order (ascending or descending) to sort nodes by */
4444
Qt::SortOrder sortOrder;
4545

46-
/** Pull a full list of banned nodes from CNode into our cache */
46+
/** Pull a full list of banned nodes from interfaces::Node into our cache */
4747
void refreshBanlist(interfaces::Node& node)
4848
{
4949
banmap_t banMap;
@@ -178,3 +178,9 @@ bool BanTableModel::shouldShow()
178178
{
179179
return priv->size() > 0;
180180
}
181+
182+
bool BanTableModel::unban(const QModelIndex& index)
183+
{
184+
CCombinedBan* ban{static_cast<CCombinedBan*>(index.internalPointer())};
185+
return ban != nullptr && m_node.unban(ban->subnet);
186+
}

src/qt/bantablemodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BannedNodeLessThan
3737
};
3838

3939
/**
40-
Qt model providing information about connected peers, similar to the
40+
Qt model providing information about banned peers, similar to the
4141
"getpeerinfo" RPC call. Used by the rpc console UI.
4242
*/
4343
class BanTableModel : public QAbstractTableModel
@@ -68,6 +68,8 @@ class BanTableModel : public QAbstractTableModel
6868

6969
bool shouldShow();
7070

71+
bool unban(const QModelIndex& index);
72+
7173
public Q_SLOTS:
7274
void refresh();
7375

src/qt/rpcconsole.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <chainparams.h>
1313
#include <interfaces/node.h>
14-
#include <netbase.h>
1514
#include <qt/bantablemodel.h>
1615
#include <qt/clientmodel.h>
1716
#include <qt/guiutil.h>
@@ -1308,17 +1307,13 @@ void RPCConsole::unbanSelectedNode()
13081307

13091308
// Get selected ban addresses
13101309
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address);
1311-
for(int i = 0; i < nodes.count(); i++)
1312-
{
1313-
// Get currently selected ban address
1314-
QString strNode = nodes.at(i).data().toString();
1315-
CSubNet possibleSubnet;
1316-
1317-
LookupSubNet(strNode.toStdString(), possibleSubnet);
1318-
if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
1319-
{
1320-
clientModel->getBanTableModel()->refresh();
1321-
}
1310+
BanTableModel* ban_table_model{clientModel->getBanTableModel()};
1311+
bool unbanned{false};
1312+
for (const auto& node_index : nodes) {
1313+
unbanned |= ban_table_model->unban(node_index);
1314+
}
1315+
if (unbanned) {
1316+
ban_table_model->refresh();
13221317
}
13231318
}
13241319

0 commit comments

Comments
 (0)