Merge bitcoin-core/gui#717: Use the stored CSubNet entry when unbanning

4be57a5df1 gui: fix comments for BanTableModel and BanTablePriv::refreshBanlist() (Vasil Dimov)
a981af4e6f 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 4be57a5d
  mzumsande:
    Tested ACK 4be57a5df1

Tree-SHA512: b783c18c9d676aa9486cff2d27039dd5c5ef3f1cc67e5056a2be68e35930926f368f26dacdf4f3d394a1f73e3e28f42dc8a6936cd1765c6e6e60695c7b4d78af
This commit is contained in:
Hennadii Stepanov 2023-03-09 13:42:58 +00:00
commit 9985013350
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 17 additions and 14 deletions

View file

@ -43,7 +43,7 @@ public:
/** Order (ascending or descending) to sort nodes by */ /** Order (ascending or descending) to sort nodes by */
Qt::SortOrder sortOrder; Qt::SortOrder sortOrder;
/** Pull a full list of banned nodes from CNode into our cache */ /** Pull a full list of banned nodes from interfaces::Node into our cache */
void refreshBanlist(interfaces::Node& node) void refreshBanlist(interfaces::Node& node)
{ {
banmap_t banMap; banmap_t banMap;
@ -178,3 +178,9 @@ bool BanTableModel::shouldShow()
{ {
return priv->size() > 0; return priv->size() > 0;
} }
bool BanTableModel::unban(const QModelIndex& index)
{
CCombinedBan* ban{static_cast<CCombinedBan*>(index.internalPointer())};
return ban != nullptr && m_node.unban(ban->subnet);
}

View file

@ -37,7 +37,7 @@ private:
}; };
/** /**
Qt model providing information about connected peers, similar to the Qt model providing information about banned peers, similar to the
"getpeerinfo" RPC call. Used by the rpc console UI. "getpeerinfo" RPC call. Used by the rpc console UI.
*/ */
class BanTableModel : public QAbstractTableModel class BanTableModel : public QAbstractTableModel
@ -68,6 +68,8 @@ public:
bool shouldShow(); bool shouldShow();
bool unban(const QModelIndex& index);
public Q_SLOTS: public Q_SLOTS:
void refresh(); void refresh();

View file

@ -11,7 +11,6 @@
#include <chainparams.h> #include <chainparams.h>
#include <interfaces/node.h> #include <interfaces/node.h>
#include <netbase.h>
#include <qt/bantablemodel.h> #include <qt/bantablemodel.h>
#include <qt/clientmodel.h> #include <qt/clientmodel.h>
#include <qt/guiutil.h> #include <qt/guiutil.h>
@ -1308,17 +1307,13 @@ void RPCConsole::unbanSelectedNode()
// Get selected ban addresses // Get selected ban addresses
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address); QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address);
for(int i = 0; i < nodes.count(); i++) BanTableModel* ban_table_model{clientModel->getBanTableModel()};
{ bool unbanned{false};
// Get currently selected ban address for (const auto& node_index : nodes) {
QString strNode = nodes.at(i).data().toString(); unbanned |= ban_table_model->unban(node_index);
CSubNet possibleSubnet;
LookupSubNet(strNode.toStdString(), possibleSubnet);
if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
{
clientModel->getBanTableModel()->refresh();
} }
if (unbanned) {
ban_table_model->refresh();
} }
} }