Merge pull request #3685

8e29623 [Qt] show number of in/out connections in debug console (Philip Kaufmann)
This commit is contained in:
Wladimir J. van der Laan 2014-03-10 09:37:03 +01:00
commit 218be95903
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
3 changed files with 28 additions and 4 deletions

View File

@ -39,9 +39,18 @@ ClientModel::~ClientModel()
unsubscribeFromCoreSignals(); unsubscribeFromCoreSignals();
} }
int ClientModel::getNumConnections() const int ClientModel::getNumConnections(unsigned int flags) const
{ {
LOCK(cs_vNodes);
if (flags == CONNECTIONS_ALL) // Shortcut if we want total
return vNodes.size(); 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 int ClientModel::getNumBlocks() const

View File

@ -25,6 +25,13 @@ enum BlockSource {
BLOCK_SOURCE_NETWORK BLOCK_SOURCE_NETWORK
}; };
enum NumConnections {
CONNECTIONS_NONE = 0,
CONNECTIONS_IN = (1U << 0),
CONNECTIONS_OUT = (1U << 1),
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
};
/** Model for Bitcoin network client. */ /** Model for Bitcoin network client. */
class ClientModel : public QObject class ClientModel : public QObject
{ {
@ -36,7 +43,8 @@ public:
OptionsModel *getOptionsModel(); 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 getNumBlocks() const;
int getNumBlocksAtStartup(); int getNumBlocksAtStartup();

View File

@ -349,7 +349,14 @@ void RPCConsole::message(int category, const QString &message, bool html)
void RPCConsole::setNumConnections(int count) 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, int countOfPeers) void RPCConsole::setNumBlocks(int count, int countOfPeers)