diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index f46310a6039..25b6a7890f0 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -200,6 +200,7 @@ RES_ICONS = \ qt/res/icons/remove.png \ qt/res/icons/send.png \ qt/res/icons/synced.png \ + qt/res/icons/tor_connected.png \ qt/res/icons/transaction0.png \ qt/res/icons/transaction2.png \ qt/res/icons/transaction_abandoned.png \ diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 2c5f8627e61..0e48afef049 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -87,10 +87,17 @@ class NodeImpl : public Node } } bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); } - size_t getNodeCount(CConnman::NumConnections flags) override + + size_t peerCount() override { - return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0; + return m_context->connman ? m_context->connman->PeerCount() : 0; } + + ConnCounts connectionCounts() override + { + return m_context->connman ? m_context->connman->ConnectionCounts() : ConnCounts(); + } + bool getNodesStats(NodesStats& stats) override { stats.clear(); diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 5079be038eb..44a9b337017 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -6,7 +6,7 @@ #define BITCOIN_INTERFACES_NODE_H #include // For CAmount -#include // For CConnman::NumConnections +#include // For ConnCounts #include // For banmap_t #include // For Network #include // For SecureString @@ -87,8 +87,11 @@ class Node //! Get proxy. virtual bool getProxy(Network net, proxyType& proxy_info) = 0; - //! Get number of connections. - virtual size_t getNodeCount(CConnman::NumConnections flags) = 0; + //! Get number of peers. + virtual size_t peerCount() = 0; + + //! Get numbers of connections of different types. + virtual ConnCounts connectionCounts() = 0; //! Get stats for connected nodes. using NodesStats = std::vector>; @@ -196,11 +199,11 @@ class Node virtual std::unique_ptr handleShowProgress(ShowProgressFn fn) = 0; //! Register handler for number of connections changed messages. - using NotifyNumConnectionsChangedFn = std::function; + using NotifyNumConnectionsChangedFn = std::function; virtual std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0; //! Register handler for network active messages. - using NotifyNetworkActiveChangedFn = std::function; + using NotifyNetworkActiveChangedFn = std::function; virtual std::unique_ptr handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0; //! Register handler for notify alert messages. diff --git a/src/net.cpp b/src/net.cpp index e8a27c35305..c6448c0ecbe 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1213,15 +1213,12 @@ void CConnman::DisconnectNodes() void CConnman::NotifyNumConnectionsChanged() { - size_t vNodesSize; - { - LOCK(cs_vNodes); - vNodesSize = vNodes.size(); - } - if(vNodesSize != nPrevNodeCount) { + const size_t vNodesSize = WITH_LOCK(cs_vNodes, return vNodes.size()); + if (vNodesSize != nPrevNodeCount) { nPrevNodeCount = vNodesSize; - if(clientInterface) - clientInterface->NotifyNumConnectionsChanged(vNodesSize); + if (clientInterface) { + clientInterface->NotifyNumConnectionsChanged(); + } } } @@ -2353,8 +2350,9 @@ void CConnman::SetNetworkActive(bool active) } fNetworkActive = active; - - uiInterface.NotifyNetworkActiveChanged(fNetworkActive); + if (clientInterface) { + clientInterface->NotifyNetworkActiveChanged(); + } } CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, bool network_active) @@ -2471,7 +2469,9 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions) LogPrintf("%i block-relay-only anchors will be tried for connections.\n", m_anchors.size()); } - uiInterface.InitMessage(_("Starting network threads...").translated); + if (clientInterface) { + clientInterface->InitMessage(_("Starting network threads...").translated); + } fAddressesInitialized = true; @@ -2729,20 +2729,20 @@ bool CConnman::RemoveAddedNode(const std::string& strNode) return false; } -size_t CConnman::GetNodeCount(NumConnections flags) +ConnCounts CConnman::ConnectionCounts() { - LOCK(cs_vNodes); - if (flags == CConnman::CONNECTIONS_ALL) // Shortcut if we want total - return vNodes.size(); - - int nNum = 0; - for (const auto& pnode : vNodes) { - if (flags & (pnode->IsInboundConn() ? CONNECTIONS_IN : CONNECTIONS_OUT)) { - nNum++; + int num_in{0}; + int num_out{0}; + bool onion_only{false}; + { + LOCK(cs_vNodes); + if (!vNodes.empty()) onion_only = true; + for (const auto& pnode : vNodes) { + pnode->IsInboundConn() ? ++num_in : ++num_out; + if (pnode->ConnectedThroughNetwork() != NET_ONION) onion_only = false; } } - - return nNum; + return {num_in, num_out, onion_only}; } void CConnman::GetNodeStats(std::vector& vstats) diff --git a/src/net.h b/src/net.h index 55de7afa051..962c9531776 100644 --- a/src/net.h +++ b/src/net.h @@ -183,18 +183,28 @@ enum class ConnectionType { ADDR_FETCH, }; +struct ConnCounts +{ + const int all{0}; + const int in{0}; + const int out{0}; + const bool onion_only{false}; + + ConnCounts() + { + } + + ConnCounts(int num_in, int num_out, bool is_onion_only) + : all(num_in + num_out), in(num_in), out(num_out), onion_only(is_onion_only) + { + } +}; + class NetEventsInterface; class CConnman { public: - enum NumConnections { - CONNECTIONS_NONE = 0, - CONNECTIONS_IN = (1U << 0), - CONNECTIONS_OUT = (1U << 1), - CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT), - }; - struct Options { ServiceFlags nLocalServices = NODE_NONE; @@ -346,7 +356,8 @@ class CConnman bool RemoveAddedNode(const std::string& node); std::vector GetAddedNodeInfo(); - size_t GetNodeCount(NumConnections num); + size_t PeerCount() { return WITH_LOCK(cs_vNodes, return vNodes.size()); } + ConnCounts ConnectionCounts(); void GetNodeStats(std::vector& vstats); bool DisconnectNode(const std::string& node); bool DisconnectNode(const CSubNet& subnet); diff --git a/src/node/ui_interface.cpp b/src/node/ui_interface.cpp index 8d3665975dc..70640b9e3f4 100644 --- a/src/node/ui_interface.cpp +++ b/src/node/ui_interface.cpp @@ -45,8 +45,8 @@ ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged); bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style).value_or(false);} bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style).value_or(false);} void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); } -void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); } -void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); } +void CClientUIInterface::NotifyNumConnectionsChanged() { return g_ui_signals.NotifyNumConnectionsChanged(); } +void CClientUIInterface::NotifyNetworkActiveChanged() { return g_ui_signals.NotifyNetworkActiveChanged(); } void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); } void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); } void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); } diff --git a/src/node/ui_interface.h b/src/node/ui_interface.h index d574ab879f9..04ebed5f4a4 100644 --- a/src/node/ui_interface.h +++ b/src/node/ui_interface.h @@ -83,10 +83,10 @@ class CClientUIInterface ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message); /** Number of network connections changed. */ - ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections); + ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, void); /** Network activity state changed. */ - ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive); + ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, void); /** * Status bar alerts changed. diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc index 71154598083..4d8707baeb2 100644 --- a/src/qt/bitcoin.qrc +++ b/src/qt/bitcoin.qrc @@ -43,6 +43,7 @@ res/icons/hd_enabled.png res/icons/hd_disabled.png res/icons/network_disabled.png + res/icons/tor_connected.png res/icons/proxy.png diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0c2dcc3584e..7a86d455290 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -77,6 +77,7 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM = BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) : QMainWindow(parent), m_node(node), + m_tor_icon{new GUIUtil::ClickableLabel()}, trayIconMenu{new QMenu()}, platformStyle(_platformStyle), m_network_style(networkStyle) @@ -160,6 +161,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty frameBlocksLayout->addWidget(labelWalletEncryptionIcon); frameBlocksLayout->addWidget(labelWalletHDStatusIcon); } + frameBlocksLayout->addWidget(m_tor_icon); frameBlocksLayout->addWidget(labelProxyIcon); frameBlocksLayout->addStretch(); frameBlocksLayout->addWidget(connectionsControl); @@ -202,6 +204,9 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] { openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK); }); + connect(m_tor_icon, &GUIUtil::ClickableLabel::clicked, [this] { + openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK); + }); connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay); connect(progressBar, &GUIUtil::ClickableProgressBar::clicked, this, &BitcoinGUI::showModalOverlay); @@ -585,8 +590,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH // Keep up to date with client updateNetworkState(); - connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::setNumConnections); - connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::setNetworkActive); + connect(_clientModel, &ClientModel::numConnectionsChanged, this, &BitcoinGUI::updateNetworkState); + connect(_clientModel, &ClientModel::networkActiveChanged, this, &BitcoinGUI::updateNetworkState); modalOverlay->setKnownBestHeight(tip_info->header_height, QDateTime::fromTime_t(tip_info->header_time)); setNumBlocks(tip_info->block_height, QDateTime::fromTime_t(tip_info->block_time), tip_info->verification_progress, false, SynchronizationState::INIT_DOWNLOAD); @@ -898,7 +903,8 @@ void BitcoinGUI::gotoLoadPSBT(bool from_clipboard) void BitcoinGUI::updateNetworkState() { - int count = clientModel->getNumConnections(); + const ConnCounts conn_counts = m_node.connectionCounts(); + const int count = conn_counts.all; QString icon; switch(count) { @@ -921,18 +927,15 @@ void BitcoinGUI::updateNetworkState() // Don't word-wrap this (fixed-width) tooltip tooltip = QString("") + tooltip + QString(""); connectionsControl->setToolTip(tooltip); - connectionsControl->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE)); -} - -void BitcoinGUI::setNumConnections(int count) -{ - updateNetworkState(); -} -void BitcoinGUI::setNetworkActive(bool networkActive) -{ - updateNetworkState(); + if (conn_counts.onion_only) { + m_tor_icon->setPixmap(platformStyle->SingleColorIcon(":/icons/tor_connected").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE)); + m_tor_icon->setToolTip(tr("All connections are via Tor only")); + m_tor_icon->show(); + } else { + m_tor_icon->hide(); + } } void BitcoinGUI::updateHeadersSyncProgressLabel() diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 912297a74ee..da4edab2d23 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -122,6 +122,7 @@ class BitcoinGUI : public QMainWindow UnitDisplayStatusBarControl* unitDisplayControl = nullptr; QLabel* labelWalletEncryptionIcon = nullptr; QLabel* labelWalletHDStatusIcon = nullptr; + GUIUtil::ClickableLabel* m_tor_icon{nullptr}; GUIUtil::ClickableLabel* labelProxyIcon = nullptr; GUIUtil::ClickableLabel* connectionsControl = nullptr; GUIUtil::ClickableLabel* labelBlocksIcon = nullptr; @@ -201,9 +202,6 @@ class BitcoinGUI : public QMainWindow /** Connect core signals to GUI client */ void subscribeToCoreSignals(); - /** Update UI with latest network info from model. */ - void updateNetworkState(); - void updateHeadersSyncProgressLabel(); /** Open the OptionsDialog on the specified tab index */ @@ -217,10 +215,8 @@ class BitcoinGUI : public QMainWindow void setPrivacy(bool privacy); public Q_SLOTS: - /** Set number of connections shown in the UI */ - void setNumConnections(int count); - /** Set network state shown in the UI */ - void setNetworkActive(bool networkActive); + /** Update UI with latest network info from model. */ + void updateNetworkState(); /** Set number of blocks and last block date shown in the UI */ void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers, SynchronizationState sync_state); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index a2f46c339b8..cc90f7f3a7e 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -68,20 +68,6 @@ ClientModel::~ClientModel() m_thread->wait(); } -int ClientModel::getNumConnections(unsigned int flags) const -{ - CConnman::NumConnections connections = CConnman::CONNECTIONS_NONE; - - if(flags == CONNECTIONS_IN) - connections = CConnman::CONNECTIONS_IN; - else if (flags == CONNECTIONS_OUT) - connections = CConnman::CONNECTIONS_OUT; - else if (flags == CONNECTIONS_ALL) - connections = CConnman::CONNECTIONS_ALL; - - return m_node.getNodeCount(connections); -} - int ClientModel::getHeaderTipHeight() const { if (cachedBestHeaderHeight == -1) { @@ -141,14 +127,14 @@ uint256 ClientModel::getBestBlockHash() return m_cached_tip_blocks; } -void ClientModel::updateNumConnections(int numConnections) +void ClientModel::updateNumConnections() { - Q_EMIT numConnectionsChanged(numConnections); + Q_EMIT numConnectionsChanged(); } -void ClientModel::updateNetworkActive(bool networkActive) +void ClientModel::updateNetworkActive() { - Q_EMIT networkActiveChanged(networkActive); + Q_EMIT networkActiveChanged(); } void ClientModel::updateAlert() @@ -162,7 +148,7 @@ enum BlockSource ClientModel::getBlockSource() const return BlockSource::REINDEX; else if (m_node.getImporting()) return BlockSource::DISK; - else if (getNumConnections() > 0) + else if (m_node.peerCount() > 0) return BlockSource::NETWORK; return BlockSource::NONE; @@ -233,18 +219,16 @@ static void ShowProgress(ClientModel *clientmodel, const std::string &title, int assert(invoked); } -static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections) +static void NotifyNumConnectionsChanged(ClientModel* clientmodel) { // Too noisy: qDebug() << "NotifyNumConnectionsChanged: " + QString::number(newNumConnections); - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNumConnections", Qt::QueuedConnection, - Q_ARG(int, newNumConnections)); + bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNumConnections", Qt::QueuedConnection); assert(invoked); } -static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive) +static void NotifyNetworkActiveChanged(ClientModel* clientmodel) { - bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection, - Q_ARG(bool, networkActive)); + bool invoked = QMetaObject::invokeMethod(clientmodel, "updateNetworkActive", Qt::QueuedConnection); assert(invoked); } @@ -295,8 +279,8 @@ void ClientModel::subscribeToCoreSignals() { // Connect signals to client m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2)); - m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(std::bind(NotifyNumConnectionsChanged, this, std::placeholders::_1)); - m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(std::bind(NotifyNetworkActiveChanged, this, std::placeholders::_1)); + m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(std::bind(NotifyNumConnectionsChanged, this)); + m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(std::bind(NotifyNetworkActiveChanged, this)); m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged(std::bind(NotifyAlertChanged, this)); m_handler_banned_list_changed = m_node.handleBannedListChanged(std::bind(BannedListChanged, this)); m_handler_notify_block_tip = m_node.handleNotifyBlockTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, false)); diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 7f12cce1d91..88b6746cb0f 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -35,13 +35,6 @@ enum class BlockSource { 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. */ class ClientModel : public QObject { @@ -55,9 +48,6 @@ class ClientModel : public QObject OptionsModel *getOptionsModel(); PeerTableModel *getPeerTableModel(); BanTableModel *getBanTableModel(); - - //! Return number of connections, default is in- and outbound (total) - int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const; int getNumBlocks() const; uint256 getBestBlockHash(); int getHeaderTipHeight() const; @@ -105,10 +95,10 @@ class ClientModel : public QObject void unsubscribeFromCoreSignals(); Q_SIGNALS: - void numConnectionsChanged(int count); + void numConnectionsChanged(); void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state); void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); - void networkActiveChanged(bool networkActive); + void networkActiveChanged(); void alertsChanged(const QString &warnings); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); @@ -119,8 +109,8 @@ class ClientModel : public QObject void showProgress(const QString &title, int nProgress); public Q_SLOTS: - void updateNumConnections(int numConnections); - void updateNetworkActive(bool networkActive); + void updateNumConnections(); + void updateNetworkActive(); void updateAlert(); void updateBanlist(); }; diff --git a/src/qt/res/icons/tor_connected.png b/src/qt/res/icons/tor_connected.png new file mode 100644 index 00000000000..01df49f88ff Binary files /dev/null and b/src/qt/res/icons/tor_connected.png differ diff --git a/src/qt/res/src/tor_connected.svg b/src/qt/res/src/tor_connected.svg new file mode 100644 index 00000000000..df135f8e4cd --- /dev/null +++ b/src/qt/res/src/tor_connected.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 4c5601242e9..dbaf9185fc8 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -574,15 +574,13 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ ui->trafficGraph->setClientModel(model); if (model && clientModel->getPeerTableModel() && clientModel->getBanTableModel()) { // Keep up to date with client - setNumConnections(model->getNumConnections()); - connect(model, &ClientModel::numConnectionsChanged, this, &RPCConsole::setNumConnections); + updateNetworkState(); + connect(model, &ClientModel::numConnectionsChanged, this, &RPCConsole::updateNetworkState); + connect(model, &ClientModel::networkActiveChanged, this, &RPCConsole::updateNetworkState); setNumBlocks(bestblock_height, QDateTime::fromTime_t(bestblock_date), verification_progress, false); connect(model, &ClientModel::numBlocksChanged, this, &RPCConsole::setNumBlocks); - updateNetworkState(); - connect(model, &ClientModel::networkActiveChanged, this, &RPCConsole::setNetworkActive); - interfaces::Node& node = clientModel->node(); updateTrafficStats(node.getTotalBytesRecv(), node.getTotalBytesSent()); connect(model, &ClientModel::bytesChanged, this, &RPCConsole::updateTrafficStats); @@ -844,9 +842,10 @@ void RPCConsole::message(int category, const QString &message, bool html) void RPCConsole::updateNetworkState() { - QString connections = QString::number(clientModel->getNumConnections()) + " ("; - connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / "; - connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")"; + const ConnCounts conn_counts = m_node.connectionCounts(); + QString connections = QString::number(conn_counts.all) + " ("; + connections += tr("In:") + " " + QString::number(conn_counts.in) + " / "; + connections += tr("Out:") + " " + QString::number(conn_counts.out) + ")"; if(!clientModel->node().getNetworkActive()) { connections += " (" + tr("Network activity disabled") + ")"; @@ -855,19 +854,6 @@ void RPCConsole::updateNetworkState() ui->numberOfConnections->setText(connections); } -void RPCConsole::setNumConnections(int count) -{ - if (!clientModel) - return; - - updateNetworkState(); -} - -void RPCConsole::setNetworkActive(bool networkActive) -{ - updateNetworkState(); -} - void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers) { if (!headers) { diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 280c5bd71a9..7377c783b3a 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -103,10 +103,6 @@ public Q_SLOTS: /** Append the message to the message widget */ void message(int category, const QString &msg) { message(category, msg, false); } void message(int category, const QString &message, bool html); - /** Set number of connections shown in the UI */ - void setNumConnections(int count); - /** Set network state shown in the UI */ - void setNetworkActive(bool networkActive); /** Set number of blocks and last block date shown in the UI */ void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers); /** Set size (number of transactions and memory usage) of the mempool in the UI */ @@ -129,6 +125,8 @@ public Q_SLOTS: void unbanSelectedNode(); /** set which tab has the focus (is visible) */ void setTabFocus(enum TabTypes tabType); + /** Update UI with latest network info from model. */ + void updateNetworkState(); Q_SIGNALS: // For RPC command executor @@ -166,9 +164,6 @@ public Q_SLOTS: QThread thread; WalletModel* m_last_wallet_model{nullptr}; - /** Update UI with latest network info from model. */ - void updateNetworkState(); - private Q_SLOTS: void updateAlerts(const QString& warnings); }; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index a561b7e93cd..908a87667f8 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -663,8 +663,9 @@ static RPCHelpMan getblocktemplate() if(!node.connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - if (node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) + if (node.connman->PeerCount() == 0) { throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!"); + } if (::ChainstateActive().IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME " is in initial sync and waiting for blocks..."); diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index b81e6414a5e..d0fd8025e6c 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -56,7 +56,7 @@ static RPCHelpMan getconnectioncount() if(!node.connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - return (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL); + return (int)node.connman->PeerCount(); }, }; } @@ -533,10 +533,11 @@ static RPCHelpMan getnetworkinfo() }}, {RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"}, {RPCResult::Type::NUM, "timeoffset", "the time offset"}, + {RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"}, {RPCResult::Type::NUM, "connections", "the total number of connections"}, {RPCResult::Type::NUM, "connections_in", "the number of inbound connections"}, {RPCResult::Type::NUM, "connections_out", "the number of outbound connections"}, - {RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"}, + {RPCResult::Type::BOOL, "connections_onion_only", "whether all connection are through the onion network"}, {RPCResult::Type::ARR, "networks", "information per network", { {RPCResult::Type::OBJ, "", "", @@ -583,9 +584,11 @@ static RPCHelpMan getnetworkinfo() obj.pushKV("timeoffset", GetTimeOffset()); if (node.connman) { obj.pushKV("networkactive", node.connman->GetNetworkActive()); - obj.pushKV("connections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); - obj.pushKV("connections_in", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_IN)); - obj.pushKV("connections_out", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_OUT)); + const ConnCounts conn_counts = node.connman->ConnectionCounts(); + obj.pushKV("connections", conn_counts.all); + obj.pushKV("connections_in", conn_counts.in); + obj.pushKV("connections_out", conn_counts.out); + obj.pushKV("connections_onion_only", conn_counts.onion_only); } obj.pushKV("networks", GetNetworksInfo()); obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));