diff options
author | Jadi <jadijadi@gmail.com> | 2024-05-23 17:41:45 +0330 |
---|---|---|
committer | Jadi <jadijadi@gmail.com> | 2024-08-02 10:40:33 +0330 |
commit | a5d7aff867a3df9ac77664deed03e930e2636db0 (patch) | |
tree | 44b05ed790f4a419e06787d7603febd46027109c | |
parent | 058af75874ffa2b4064e3d6d30cc50f0ec754ba8 (diff) | |
download | bitcoin-a5d7aff867a3df9ac77664deed03e930e2636db0.tar.xz |
net: Providing an interface for mapLocalHost
Contributes to #564 by providing an interface for mapLocalHost
through net -> node interface -> clientModel. Later this value can be
read by GUI to show the local addresses.
-rw-r--r-- | src/interfaces/node.h | 3 | ||||
-rw-r--r-- | src/net.cpp | 7 | ||||
-rw-r--r-- | src/net.h | 1 | ||||
-rw-r--r-- | src/node/interfaces.cpp | 7 | ||||
-rw-r--r-- | src/qt/clientmodel.cpp | 7 | ||||
-rw-r--r-- | src/qt/clientmodel.h | 4 |
6 files changed, 29 insertions, 0 deletions
diff --git a/src/interfaces/node.h b/src/interfaces/node.h index aeb2612c07..747ff033e4 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -168,6 +168,9 @@ public: //! 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; diff --git a/src/net.cpp b/src/net.cpp index f05b517dd2..24095adcf4 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3533,6 +3533,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); @@ -1205,6 +1205,7 @@ public: 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); diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 216f44ab9e..1610d7c3d0 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -281,6 +281,13 @@ public: } 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); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 2f3bad37e6..036a66c16e 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -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) { diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 624056b5df..3252f4af76 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -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; @@ -68,6 +71,7 @@ public: //! 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; |