diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-09 13:42:58 +0000 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-09 13:49:22 +0000 |
commit | 9985013350a249a26bbb5daa51c6af1572dbb202 (patch) | |
tree | d0e1e8f8179e9a60e24b1aa3f1c6a2c4a71d7518 | |
parent | 23e2bfcbc42849daa8e2b69f9bbdc526bc8743a7 (diff) | |
parent | 4be57a5df140f52628cab8a5ca5ddc208cd3f612 (diff) |
Merge bitcoin-core/gui#717: Use the stored CSubNet entry when unbanning
4be57a5df140f52628cab8a5ca5ddc208cd3f612 gui: fix comments for BanTableModel and BanTablePriv::refreshBanlist() (Vasil Dimov)
a981af4e6fd0047bc3e96468db48dd7820dac808 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 4be57a5df140f52628cab8a5ca5ddc208cd3f612
Tree-SHA512: b783c18c9d676aa9486cff2d27039dd5c5ef3f1cc67e5056a2be68e35930926f368f26dacdf4f3d394a1f73e3e28f42dc8a6936cd1765c6e6e60695c7b4d78af
-rw-r--r-- | src/qt/bantablemodel.cpp | 8 | ||||
-rw-r--r-- | src/qt/bantablemodel.h | 4 | ||||
-rw-r--r-- | src/qt/rpcconsole.cpp | 19 |
3 files changed, 17 insertions, 14 deletions
diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 4f57cd4457..4592d29abc 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -43,7 +43,7 @@ public: /** Order (ascending or descending) to sort nodes by */ 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) { banmap_t banMap; @@ -178,3 +178,9 @@ bool BanTableModel::shouldShow() { 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); +} diff --git a/src/qt/bantablemodel.h b/src/qt/bantablemodel.h index 0a30905172..adb97ad1c0 100644 --- a/src/qt/bantablemodel.h +++ b/src/qt/bantablemodel.h @@ -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. */ class BanTableModel : public QAbstractTableModel @@ -68,6 +68,8 @@ public: bool shouldShow(); + bool unban(const QModelIndex& index); + public Q_SLOTS: void refresh(); diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b46a3c039b..0e712062af 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -11,7 +11,6 @@ #include <chainparams.h> #include <interfaces/node.h> -#include <netbase.h> #include <qt/bantablemodel.h> #include <qt/clientmodel.h> #include <qt/guiutil.h> @@ -1308,17 +1307,13 @@ void RPCConsole::unbanSelectedNode() // Get selected ban addresses QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address); - for(int i = 0; i < nodes.count(); i++) - { - // Get currently selected ban address - QString strNode = nodes.at(i).data().toString(); - CSubNet possibleSubnet; - - LookupSubNet(strNode.toStdString(), possibleSubnet); - if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet)) - { - clientModel->getBanTableModel()->refresh(); - } + BanTableModel* ban_table_model{clientModel->getBanTableModel()}; + bool unbanned{false}; + for (const auto& node_index : nodes) { + unbanned |= ban_table_model->unban(node_index); + } + if (unbanned) { + ban_table_model->refresh(); } } |