0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-06 14:19:59 -05:00

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.
This commit is contained in:
Jadi 2024-05-23 17:41:45 +03:30
parent 058af75874
commit a5d7aff867
6 changed files with 29 additions and 0 deletions

View file

@ -168,6 +168,9 @@ public:
//! Get num blocks. //! Get num blocks.
virtual int getNumBlocks() = 0; virtual int getNumBlocks() = 0;
//! Get network local addresses.
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;
//! Get best block hash. //! Get best block hash.
virtual uint256 getBestBlockHash() = 0; virtual uint256 getBestBlockHash() = 0;

View file

@ -3533,6 +3533,13 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
return nNum; return nNum;
} }
std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
{
LOCK(g_maplocalhost_mutex);
return mapLocalHost;
}
uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
{ {
return m_netgroupman.GetMappedAS(addr); return m_netgroupman.GetMappedAS(addr);

View file

@ -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); 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; size_t GetNodeCount(ConnectionDirection) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
uint32_t GetMappedAS(const CNetAddr& addr) const; uint32_t GetMappedAS(const CNetAddr& addr) const;
void GetNodeStats(std::vector<CNodeStats>& vstats) const; void GetNodeStats(std::vector<CNodeStats>& vstats) const;
bool DisconnectNode(const std::string& node); bool DisconnectNode(const std::string& node);

View file

@ -281,6 +281,13 @@ public:
} }
return false; return false;
} }
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
{
if (m_context->connman)
return m_context->connman->getNetLocalAddresses();
else
return {};
}
int getNumBlocks() override int getNumBlocks() override
{ {
LOCK(::cs_main); LOCK(::cs_main);

View file

@ -123,6 +123,13 @@ int64_t ClientModel::getHeaderTipTime() const
return cachedBestHeaderTime; return cachedBestHeaderTime;
} }
std::map<CNetAddr, LocalServiceInfo> ClientModel::getNetLocalAddresses() const
{
return m_node.getNetLocalAddresses();
}
int ClientModel::getNumBlocks() const int ClientModel::getNumBlocks() const
{ {
if (m_cached_num_blocks == -1) { if (m_cached_num_blocks == -1) {

View file

@ -13,12 +13,15 @@
#include <sync.h> #include <sync.h>
#include <uint256.h> #include <uint256.h>
#include <netaddress.h>
class BanTableModel; class BanTableModel;
class CBlockIndex; class CBlockIndex;
class OptionsModel; class OptionsModel;
class PeerTableModel; class PeerTableModel;
class PeerTableSortProxy; class PeerTableSortProxy;
enum class SynchronizationState; enum class SynchronizationState;
struct LocalServiceInfo;
namespace interfaces { namespace interfaces {
class Handler; class Handler;
@ -68,6 +71,7 @@ public:
//! Return number of connections, default is in- and outbound (total) //! Return number of connections, default is in- and outbound (total)
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const; int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
int getNumBlocks() const; int getNumBlocks() const;
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex); uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
int getHeaderTipHeight() const; int getHeaderTipHeight() const;