Skip to content

Commit

Permalink
Merge bitcoin-core/gui#626: Showing Local Addresses in Node Window
Browse files Browse the repository at this point in the history
189c987 Showing local addresses on the Node Window (Jadi)
a5d7aff net: Providing an interface for mapLocalHost (Jadi)

Pull request description:

  This change adds a new row to the Node Window (debugwindow.ui)
  under the Network section which shows the LocalAddresses.

  fixes bitcoin#564

  <!--
  *** Please remove the following help text before submitting: ***

  Pull requests without a rationale and clear improvement may be closed
  immediately.

  GUI-related pull requests should be opened against
  https://github.com/bitcoin-core/gui
  first. See CONTRIBUTING.md
  -->

  <!--
  Please provide clear motivation for your patch and explain how it improves
  Bitcoin Core user experience or Bitcoin Core developer experience
  significantly:

  * Any test improvements or new tests that improve coverage are always welcome.
  * All other changes should have accompanying unit tests (see `src/test/`) or
    functional tests (see `test/`). Contributors should note which tests cover
    modified code. If no tests exist for a region of modified code, new tests
    should accompany the change.
  * Bug fixes are most welcome when they come with steps to reproduce or an
    explanation of the potential issue as well as reasoning for the way the bug
    was fixed.
  * Features are welcome, but might be rejected due to design or scope issues.
    If a feature is based on a lot of dependencies, contributors should first
    consider building the system outside of Bitcoin Core, if possible.
  * Refactoring changes are only accepted if they are required for a feature or
    bug fix or otherwise improve developer experience significantly. For example,
    most "code style" refactoring changes require a thorough explanation why they
    are useful, what downsides they have and why they *significantly* improve
    developer experience or avoid serious programming bugs. Note that code style
    is often a subjective matter. Unless they are explicitly mentioned to be
    preferred in the [developer notes](/doc/developer-notes.md), stylistic code
    changes are usually rejected.
  -->

  <!--
  Bitcoin Core has a thorough review process and even the most trivial change
  needs to pass a lot of eyes and requires non-zero or even substantial time
  effort to review. There is a huge lack of active reviewers on the project, so
  patches often sit for a long time.
  -->

ACKs for top commit:
  pablomartin4btc:
    re-ACK 189c987
  furszy:
    utACK 189c987

Tree-SHA512: 93f201bc6d21d81b27b87be050a447b841f01e3efb69b9eca2cc7af103023d7cd69eb5e16e2875855573ef51a5bf74a6ee6028636c1b6798cb4bb11567cb4996
  • Loading branch information
hebasto committed Aug 2, 2024
2 parents df24197 + 189c987 commit ec8b38c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class Node
//! Get num blocks.
virtual int getNumBlocks() = 0;

//! Get network local addresses.
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;

//! Get best block hash.
virtual uint256 getBestBlockHash() = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3550,6 +3550,13 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
return nNum;
}


std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
{
LOCK(g_maplocalhost_mutex);
return mapLocalHost;
}

uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
{
return m_netgroupman.GetMappedAS(addr);
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ class CConnman
bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);

size_t GetNodeCount(ConnectionDirection) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
uint32_t GetMappedAS(const CNetAddr& addr) const;
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
bool DisconnectNode(const std::string& node);
Expand Down
7 changes: 7 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ class NodeImpl : public Node
}
return false;
}
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
{
if (m_context->connman)
return m_context->connman->getNetLocalAddresses();
else
return {};
}
int getNumBlocks() override
{
LOCK(::cs_main);
Expand Down
7 changes: 7 additions & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ int64_t ClientModel::getHeaderTipTime() const
return cachedBestHeaderTime;
}


std::map<CNetAddr, LocalServiceInfo> ClientModel::getNetLocalAddresses() const
{
return m_node.getNetLocalAddresses();
}


int ClientModel::getNumBlocks() const
{
if (m_cached_num_blocks == -1) {
Expand Down
4 changes: 4 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
#include <sync.h>
#include <uint256.h>

#include <netaddress.h>

class BanTableModel;
class CBlockIndex;
class OptionsModel;
class PeerTableModel;
class PeerTableSortProxy;
enum class SynchronizationState;
struct LocalServiceInfo;

namespace interfaces {
class Handler;
Expand Down Expand Up @@ -68,6 +71,7 @@ class ClientModel : public QObject

//! Return number of connections, default is in- and outbound (total)
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
int getNumBlocks() const;
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
int getHeaderTipHeight() const;
Expand Down
57 changes: 46 additions & 11 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,41 @@
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Local Addresses</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QLabel" name="localAddresses">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">N/A</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="toolTip">
<string>Network addresses that your Bitcoin node is currently using to communicate with other nodes.</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_10">
<property name="font">
<font>
Expand All @@ -261,14 +296,14 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="11" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Current block height</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<item row="11" column="1" colspan="2">
<widget class="QLabel" name="numberOfBlocks">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -284,14 +319,14 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="labelLastBlockTime">
<property name="text">
<string>Last block time</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<item row="12" column="1" colspan="2">
<widget class="QLabel" name="lastBlockTime">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -307,7 +342,7 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="13" column="0">
<widget class="QLabel" name="labelMempoolTitle">
<property name="font">
<font>
Expand All @@ -320,14 +355,14 @@
</property>
</widget>
</item>
<item row="13" column="0">
<item row="14" column="0">
<widget class="QLabel" name="labelNumberOfTransactions">
<property name="text">
<string>Current number of transactions</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="QLabel" name="mempoolNumberTxs">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -343,14 +378,14 @@
</property>
</widget>
</item>
<item row="14" column="0">
<item row="15" column="0">
<widget class="QLabel" name="labelMemoryUsage">
<property name="text">
<string>Memory usage</string>
</property>
</widget>
</item>
<item row="14" column="1">
<item row="15" column="1">
<widget class="QLabel" name="mempoolSize">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -366,7 +401,7 @@
</property>
</widget>
</item>
<item row="12" column="2" rowspan="3">
<item row="13" column="2" rowspan="3">
<layout class="QVBoxLayout" name="verticalLayoutDebugButton">
<property name="spacing">
<number>3</number>
Expand Down Expand Up @@ -406,7 +441,7 @@
</item>
</layout>
</item>
<item row="15" column="0">
<item row="16" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand Down
12 changes: 12 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,18 @@ void RPCConsole::updateNetworkState()
}

ui->numberOfConnections->setText(connections);

QString local_addresses;
std::map<CNetAddr, LocalServiceInfo> hosts = clientModel->getNetLocalAddresses();
for (const auto& [addr, info] : hosts) {
local_addresses += QString::fromStdString(addr.ToStringAddr());
if (!addr.IsI2P()) local_addresses += ":" + QString::number(info.nPort);
local_addresses += ", ";
}
local_addresses.chop(2); // remove last ", "
if (local_addresses.isEmpty()) local_addresses = tr("None");

ui->localAddresses->setText(local_addresses);
}

void RPCConsole::setNumConnections(int count)
Expand Down

0 comments on commit ec8b38c

Please sign in to comment.