show number of in/out connections in GUI console 105/head
authorfsb4000 <fsb4000@yandex.ru>
Tue, 6 Jan 2015 14:56:38 +0000 (20:56 +0600)
committerfsb4000 <fsb4000@yandex.ru>
Tue, 6 Jan 2015 14:56:38 +0000 (20:56 +0600)
https://github.com/bitcoin/bitcoin/pull/3685/

src/qt/clientmodel.cpp
src/qt/clientmodel.h
src/qt/locale/bitcoin_ru.ts
src/qt/rpcconsole.cpp

index a5e6ab7..586f046 100644 (file)
@@ -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
index c8d30f6..cf3e30e 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <QObject>
 
+#include <stdint.h>
+
 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();
 
index c1e3383..e4bac60 100644 (file)
@@ -2079,6 +2079,16 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
 <context>
     <name>RPCConsole</name>
     <message>
+      <location filename="../rpcconsole.cpp" line="352"/>
+      <source>Inbound:</source>
+      <translation>Входящие:</translation>
+    </message>
+    <message>
+      <location filename="../rpcconsole.cpp" line="353"/>
+      <source>Outbound:</source>
+      <translation>Исходящие:</translation>
+    </message>
+    <message>
       <location filename="../forms/rpcconsole.ui" line="118"/>
       <source>Using BerkeleyDB version</source>
       <translation>Используется версия BerkeleyDB</translation>
index 36459f7..bfc2d39 100644 (file)
@@ -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)