From: fsb4000 Date: Tue, 6 Jan 2015 14:56:38 +0000 (+0600) Subject: show number of in/out connections in GUI console X-Git-Tag: nvc-v0.5.1~21^2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=3388a07d955c9f53e049cb6abf446bb242092a07 show number of in/out connections in GUI console https://github.com/bitcoin/bitcoin/pull/3685/ --- diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index a5e6ab7..586f046 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -48,9 +48,18 @@ double ClientModel::getDifficulty(bool fProofofStake) return GetDifficulty(GetLastBlockIndex(pindexBest,false)); } -int ClientModel::getNumConnections() const +int ClientModel::getNumConnections(uint8_t 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 diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index c8d30f6..cf3e30e 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -3,6 +3,8 @@ #include +#include + class OptionsModel; class AddressTableModel; class TransactionTableModel; @@ -13,6 +15,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 { @@ -26,7 +35,8 @@ public: double getPoSKernelPS(); double getDifficulty(bool fProofofStake); - int getNumConnections() const; + //! Return number of connections, default is in- and outbound (total) + int getNumConnections(uint8_t flags = CONNECTIONS_ALL) const; int getNumBlocks() const; int getNumBlocksAtStartup(); diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index c1e3383..e4bac60 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -2079,6 +2079,16 @@ This label turns red, if the priority is smaller than "medium". RPCConsole + + Inbound: + Входящие: + + + + Outbound: + Исходящие: + + Using BerkeleyDB version Используется версия BerkeleyDB diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 36459f7..bfc2d39 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -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("Inbound:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / "; + connections += tr("Outbound:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")"; + + ui->numberOfConnections->setText(connections); } void RPCConsole::setNumBlocks(int count, int countOfPeers)