Skip to content

Commit 8e29623

Browse files
author
Philip Kaufmann
committed
[Qt] show number of in/out connections in debug console
1 parent aefbf6e commit 8e29623

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/qt/clientmodel.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,18 @@ ClientModel::~ClientModel()
3939
unsubscribeFromCoreSignals();
4040
}
4141

42-
int ClientModel::getNumConnections() const
42+
int ClientModel::getNumConnections(unsigned int flags) const
4343
{
44-
return vNodes.size();
44+
LOCK(cs_vNodes);
45+
if (flags == CONNECTIONS_ALL) // Shortcut if we want total
46+
return vNodes.size();
47+
48+
int nNum = 0;
49+
BOOST_FOREACH(CNode* pnode, vNodes)
50+
if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT))
51+
nNum++;
52+
53+
return nNum;
4554
}
4655

4756
int ClientModel::getNumBlocks() const

src/qt/clientmodel.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ enum BlockSource {
2525
BLOCK_SOURCE_NETWORK
2626
};
2727

28+
enum NumConnections {
29+
CONNECTIONS_NONE = 0,
30+
CONNECTIONS_IN = (1U << 0),
31+
CONNECTIONS_OUT = (1U << 1),
32+
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
33+
};
34+
2835
/** Model for Bitcoin network client. */
2936
class ClientModel : public QObject
3037
{
@@ -36,7 +43,8 @@ class ClientModel : public QObject
3643

3744
OptionsModel *getOptionsModel();
3845

39-
int getNumConnections() const;
46+
//! Return number of connections, default is in- and outbound (total)
47+
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
4048
int getNumBlocks() const;
4149
int getNumBlocksAtStartup();
4250

src/qt/rpcconsole.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,14 @@ void RPCConsole::message(int category, const QString &message, bool html)
349349

350350
void RPCConsole::setNumConnections(int count)
351351
{
352-
ui->numberOfConnections->setText(QString::number(count));
352+
if (!clientModel)
353+
return;
354+
355+
QString connections = QString::number(count) + " (";
356+
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
357+
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";
358+
359+
ui->numberOfConnections->setText(connections);
353360
}
354361

355362
void RPCConsole::setNumBlocks(int count, int countOfPeers)

0 commit comments

Comments
 (0)