Skip to content

Commit b22b88b

Browse files
hebastojarolrod
authored andcommitted
qml: Add NodeModel::numOutboundPeers property
1 parent 475c63e commit b22b88b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/qml/nodemodel.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <qml/nodemodel.h>
66

77
#include <interfaces/node.h>
8+
#include <net.h>
9+
#include <node/interface_ui.h>
810
#include <validation.h>
911

1012
#include <cassert>
@@ -18,6 +20,7 @@ NodeModel::NodeModel(interfaces::Node& node)
1820
: m_node{node}
1921
{
2022
ConnectToBlockTipSignal();
23+
ConnectToNumConnectionsChangedSignal();
2124
}
2225

2326
void NodeModel::setBlockTipHeight(int new_height)
@@ -28,6 +31,14 @@ void NodeModel::setBlockTipHeight(int new_height)
2831
}
2932
}
3033

34+
void NodeModel::setNumOutboundPeers(int new_num)
35+
{
36+
if (new_num != m_num_outbound_peers) {
37+
m_num_outbound_peers = new_num;
38+
Q_EMIT numOutboundPeersChanged();
39+
}
40+
}
41+
3142
void NodeModel::setRemainingSyncTime(double new_progress)
3243
{
3344
int currentTime = QDateTime::currentDateTime().toMSecsSinceEpoch();
@@ -129,3 +140,13 @@ void NodeModel::ConnectToBlockTipSignal()
129140
});
130141
});
131142
}
143+
144+
void NodeModel::ConnectToNumConnectionsChangedSignal()
145+
{
146+
assert(!m_handler_notify_num_peers_changed);
147+
148+
m_handler_notify_num_peers_changed = m_node.handleNotifyNumConnectionsChanged(
149+
[this](PeersNumByType new_num_peers) {
150+
setNumOutboundPeers(new_num_peers.outbound_full_relay + new_num_peers.block_relay);
151+
});
152+
}

src/qml/nodemodel.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class NodeModel : public QObject
2525
{
2626
Q_OBJECT
2727
Q_PROPERTY(int blockTipHeight READ blockTipHeight NOTIFY blockTipHeightChanged)
28+
Q_PROPERTY(int numOutboundPeers READ numOutboundPeers NOTIFY numOutboundPeersChanged)
29+
Q_PROPERTY(int maxNumOutboundPeers READ maxNumOutboundPeers CONSTANT)
2830
Q_PROPERTY(int remainingSyncTime READ remainingSyncTime NOTIFY remainingSyncTimeChanged)
2931
Q_PROPERTY(double verificationProgress READ verificationProgress NOTIFY verificationProgressChanged)
3032
Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged)
@@ -34,6 +36,9 @@ class NodeModel : public QObject
3436

3537
int blockTipHeight() const { return m_block_tip_height; }
3638
void setBlockTipHeight(int new_height);
39+
int numOutboundPeers() const { return m_num_outbound_peers; }
40+
void setNumOutboundPeers(int new_num);
41+
int maxNumOutboundPeers() const { return m_max_num_outbound_peers; }
3742
int remainingSyncTime() const { return m_remaining_sync_time; }
3843
void setRemainingSyncTime(double new_progress);
3944
double verificationProgress() const { return m_verification_progress; }
@@ -51,6 +56,7 @@ public Q_SLOTS:
5156

5257
Q_SIGNALS:
5358
void blockTipHeightChanged();
59+
void numOutboundPeersChanged();
5460
void remainingSyncTimeChanged();
5561
void requestedInitialize();
5662
void requestedShutdown();
@@ -66,6 +72,8 @@ public Q_SLOTS:
6672
private:
6773
// Properties that are exposed to QML.
6874
int m_block_tip_height{0};
75+
int m_num_outbound_peers{0};
76+
static constexpr int m_max_num_outbound_peers{MAX_OUTBOUND_FULL_RELAY_CONNECTIONS + MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
6977
int m_remaining_sync_time{0};
7078
double m_verification_progress{0.0};
7179
bool m_pause{false};
@@ -76,8 +84,10 @@ public Q_SLOTS:
7684

7785
interfaces::Node& m_node;
7886
std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
87+
std::unique_ptr<interfaces::Handler> m_handler_notify_num_peers_changed;
7988

8089
void ConnectToBlockTipSignal();
90+
void ConnectToNumConnectionsChangedSignal();
8191
};
8292

8393
#endif // BITCOIN_QML_NODEMODEL_H

0 commit comments

Comments
 (0)