Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
[Qt] show number of in/out connections in debug console
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Kaufmann authored and recursive-rat4 committed Mar 16, 2017
1 parent f8cf7f3 commit d713384
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ ClientModel::~ClientModel()
unsubscribeFromCoreSignals();
}

int ClientModel::getNumConnections() const
int ClientModel::getNumConnections(unsigned int flags) const
{
return vNodes.size();
LOCK(cs_vNodes);
if (flags == CONNECTIONS_ALL) // Shortcut if we want total
return vNodes.size();

int nNum = 0;
BOOST_FOREACH(CNode* pnode, vNodes)
if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT))
nNum++;

return nNum;
}

int ClientModel::getNumBlocks() const
Expand Down
10 changes: 9 additions & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class QDateTime;
class QTimer;
QT_END_NAMESPACE

enum NumConnections {
CONNECTIONS_NONE = 0,
CONNECTIONS_IN = (1U << 0),
CONNECTIONS_OUT = (1U << 1),
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
};

/** Model for Bitcoin network client. */
class ClientModel : public QObject
{
Expand All @@ -24,7 +31,8 @@ class ClientModel : public QObject

OptionsModel *getOptionsModel();

int getNumConnections() const;
//! Return number of connections, default is in- and outbound (total)
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
int getNumBlocks() const;
int getNumBlocksAtStartup();

Expand Down
9 changes: 8 additions & 1 deletion src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ void RPCConsole::message(int category, const QString &message, bool html)

void RPCConsole::setNumConnections(int count)
{
ui->numberOfConnections->setText(QString::number(count));
if (!clientModel)
return;

QString connections = QString::number(count) + " (";
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";

ui->numberOfConnections->setText(connections);
}

void RPCConsole::setNumBlocks(int count)
Expand Down

0 comments on commit d713384

Please sign in to comment.