Skip to content

Commit a5d7aff

Browse files
committed
net: Providing an interface for mapLocalHost
Contributes to bitcoin#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.
1 parent 058af75 commit a5d7aff

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

src/interfaces/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class Node
168168
//! Get num blocks.
169169
virtual int getNumBlocks() = 0;
170170

171+
//! Get network local addresses.
172+
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;
173+
171174
//! Get best block hash.
172175
virtual uint256 getBestBlockHash() = 0;
173176

src/net.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,13 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
35333533
return nNum;
35343534
}
35353535

3536+
3537+
std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
3538+
{
3539+
LOCK(g_maplocalhost_mutex);
3540+
return mapLocalHost;
3541+
}
3542+
35363543
uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
35373544
{
35383545
return m_netgroupman.GetMappedAS(addr);

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ class CConnman
12051205
bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
12061206

12071207
size_t GetNodeCount(ConnectionDirection) const;
1208+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
12081209
uint32_t GetMappedAS(const CNetAddr& addr) const;
12091210
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
12101211
bool DisconnectNode(const std::string& node);

src/node/interfaces.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,13 @@ class NodeImpl : public Node
281281
}
282282
return false;
283283
}
284+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
285+
{
286+
if (m_context->connman)
287+
return m_context->connman->getNetLocalAddresses();
288+
else
289+
return {};
290+
}
284291
int getNumBlocks() override
285292
{
286293
LOCK(::cs_main);

src/qt/clientmodel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ int64_t ClientModel::getHeaderTipTime() const
123123
return cachedBestHeaderTime;
124124
}
125125

126+
127+
std::map<CNetAddr, LocalServiceInfo> ClientModel::getNetLocalAddresses() const
128+
{
129+
return m_node.getNetLocalAddresses();
130+
}
131+
132+
126133
int ClientModel::getNumBlocks() const
127134
{
128135
if (m_cached_num_blocks == -1) {

src/qt/clientmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
#include <sync.h>
1414
#include <uint256.h>
1515

16+
#include <netaddress.h>
17+
1618
class BanTableModel;
1719
class CBlockIndex;
1820
class OptionsModel;
1921
class PeerTableModel;
2022
class PeerTableSortProxy;
2123
enum class SynchronizationState;
24+
struct LocalServiceInfo;
2225

2326
namespace interfaces {
2427
class Handler;
@@ -68,6 +71,7 @@ class ClientModel : public QObject
6871

6972
//! Return number of connections, default is in- and outbound (total)
7073
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
74+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
7175
int getNumBlocks() const;
7276
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
7377
int getHeaderTipHeight() const;

0 commit comments

Comments
 (0)