Skip to content

Commit 3034a46

Browse files
ryanofskyjnewbery
authored andcommitted
Remove direct bitcoin calls from qt/bantablemodel.cpp
1 parent e0b66a3 commit 3034a46

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/interface/node.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <interface/node.h>
66

7+
#include <addrdb.h>
78
#include <chain.h>
89
#include <chainparams.h>
910
#include <init.h>
@@ -105,6 +106,14 @@ class NodeImpl : public Node
105106
}
106107
return false;
107108
}
109+
bool getBanned(banmap_t& banmap) override
110+
{
111+
if (g_connman) {
112+
g_connman->GetBanned(banmap);
113+
return true;
114+
}
115+
return false;
116+
}
108117
int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; }
109118
int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; }
110119
size_t getMempoolSize() override { return ::mempool.size(); }

src/interface/node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_INTERFACE_NODE_H
66
#define BITCOIN_INTERFACE_NODE_H
77

8+
#include <addrdb.h> // For banmap_t
89
#include <init.h> // For HelpMessageMode
910
#include <net.h> // For CConnman::NumConnections
1011
#include <netaddress.h> // For Network
@@ -87,6 +88,9 @@ class Node
8788
using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
8889
virtual bool getNodesStats(NodesStats& stats) = 0;
8990

91+
//! Get ban map entries.
92+
virtual bool getBanned(banmap_t& banmap) = 0;
93+
9094
//! Get total bytes recv.
9195
virtual int64_t getTotalBytesRecv() = 0;
9296

src/qt/bantablemodel.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <qt/guiconstants.h>
99
#include <qt/guiutil.h>
1010

11+
#include <interface/node.h>
1112
#include <sync.h>
1213
#include <utiltime.h>
1314

@@ -45,11 +46,10 @@ class BanTablePriv
4546
Qt::SortOrder sortOrder;
4647

4748
/** Pull a full list of banned nodes from CNode into our cache */
48-
void refreshBanlist()
49+
void refreshBanlist(interface::Node& node)
4950
{
5051
banmap_t banMap;
51-
if(g_connman)
52-
g_connman->GetBanned(banMap);
52+
node.getBanned(banMap);
5353

5454
cachedBanlist.clear();
5555
#if QT_VERSION >= 0x040700
@@ -82,8 +82,9 @@ class BanTablePriv
8282
}
8383
};
8484

85-
BanTableModel::BanTableModel(ClientModel *parent) :
85+
BanTableModel::BanTableModel(interface::Node& node, ClientModel *parent) :
8686
QAbstractTableModel(parent),
87+
m_node(node),
8788
clientModel(parent)
8889
{
8990
columns << tr("IP/Netmask") << tr("Banned Until");
@@ -168,7 +169,7 @@ QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent)
168169
void BanTableModel::refresh()
169170
{
170171
Q_EMIT layoutAboutToBeChanged();
171-
priv->refreshBanlist();
172+
priv->refreshBanlist(m_node);
172173
Q_EMIT layoutChanged();
173174
}
174175

src/qt/bantablemodel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
class ClientModel;
1414
class BanTablePriv;
1515

16+
namespace interface {
17+
class Node;
18+
}
19+
1620
struct CCombinedBan {
1721
CSubNet subnet;
1822
CBanEntry banEntry;
@@ -39,7 +43,7 @@ class BanTableModel : public QAbstractTableModel
3943
Q_OBJECT
4044

4145
public:
42-
explicit BanTableModel(ClientModel *parent = 0);
46+
explicit BanTableModel(interface::Node& node, ClientModel *parent = 0);
4347
~BanTableModel();
4448
void startAutoRefresh();
4549
void stopAutoRefresh();
@@ -65,6 +69,7 @@ public Q_SLOTS:
6569
void refresh();
6670

6771
private:
72+
interface::Node& m_node;
6873
ClientModel *clientModel;
6974
QStringList columns;
7075
std::unique_ptr<BanTablePriv> priv;

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ClientModel::ClientModel(interface::Node& node, OptionsModel *_optionsModel, QOb
4343
cachedBestHeaderHeight = -1;
4444
cachedBestHeaderTime = -1;
4545
peerTableModel = new PeerTableModel(m_node, this);
46-
banTableModel = new BanTableModel(this);
46+
banTableModel = new BanTableModel(m_node, this);
4747
pollTimer = new QTimer(this);
4848
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
4949
pollTimer->start(MODEL_UPDATE_DELAY);

0 commit comments

Comments
 (0)