1 // Copyright (c) 2011-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef BITCOIN_QT_PEERTABLEMODEL_H
6 #define BITCOIN_QT_PEERTABLEMODEL_H
7 8 #include <net_processing.h>
9 #include <net.h>
10 11 #include <QAbstractTableModel>
12 #include <QList>
13 #include <QModelIndex>
14 #include <QStringList>
15 #include <QVariant>
16 17 class PeerTablePriv;
18 19 namespace interfaces {
20 class Node;
21 }
22 23 QT_BEGIN_NAMESPACE
24 class QTimer;
25 QT_END_NAMESPACE
26 27 struct CNodeCombinedStats {
28 CNodeStats nodeStats;
29 CNodeStateStats nodeStateStats;
30 bool fNodeStateStatsAvailable;
31 };
32 Q_DECLARE_METATYPE(CNodeCombinedStats*)
33 34 /**
35 Qt model providing information about connected peers, similar to the
36 "getpeerinfo" RPC call. Used by the rpc console UI.
37 */
38 class PeerTableModel : public QAbstractTableModel
39 {
40 Q_OBJECT
41 42 public:
43 explicit PeerTableModel(interfaces::Node& node, QObject* parent);
44 ~PeerTableModel();
45 void startAutoRefresh();
46 void stopAutoRefresh();
47 48 enum ColumnIndex {
49 NetNodeId = 0,
50 Age,
51 Address,
52 Direction,
53 ConnectionType,
54 Network,
55 Ping,
56 Sent,
57 Received,
58 Subversion
59 };
60 61 enum {
62 StatsRole = Qt::UserRole,
63 };
64 65 /** @name Methods overridden from QAbstractTableModel
66 @{*/
67 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
68 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
69 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
70 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
71 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
72 Qt::ItemFlags flags(const QModelIndex &index) const override;
73 /*@}*/
74 75 public Q_SLOTS:
76 void refresh();
77 78 private:
79 //! Internal peer data structure.
80 QList<CNodeCombinedStats> m_peers_data{};
81 interfaces::Node& m_node;
82 const QStringList columns{
83 /*: Title of Peers Table column which contains a
84 unique number used to identify a connection. */
85 tr("Peer"),
86 /*: Title of Peers Table column which indicates the duration (length of time)
87 since the peer connection started. */
88 tr("Age"),
89 /*: Title of Peers Table column which contains the
90 IP/Onion/I2P address of the connected peer. */
91 tr("Address"),
92 /*: Title of Peers Table column which indicates the direction
93 the peer connection was initiated from. */
94 tr("Direction"),
95 /*: Title of Peers Table column which describes the type of
96 peer connection. The "type" describes why the connection exists. */
97 tr("Type"),
98 /*: Title of Peers Table column which states the network the peer
99 connected through. */
100 tr("Network"),
101 /*: Title of Peers Table column which indicates the current latency
102 of the connection with the peer. */
103 tr("Ping"),
104 /*: Title of Peers Table column which indicates the total amount of
105 network information we have sent to the peer. */
106 tr("Sent"),
107 /*: Title of Peers Table column which indicates the total amount of
108 network information we have received from the peer. */
109 tr("Received"),
110 /*: Title of Peers Table column which contains the peer's
111 User Agent string. */
112 tr("User Agent")};
113 QTimer* timer{nullptr};
114 };
115 116 #endif // BITCOIN_QT_PEERTABLEMODEL_H
117