Skip to content

Commit 283c855

Browse files
committed
Showing Local Addresses in Node Window
This change adds a new row to the Node Window (debugwindow.ui) under the Network section which shows the LocalAddresses fixes #564
1 parent 058af75 commit 283c855

File tree

8 files changed

+84
-11
lines changed

8 files changed

+84
-11
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,6 +13,9 @@
1313
#include <sync.h>
1414
#include <uint256.h>
1515

16+
#include <net.h>
17+
#include <netaddress.h>
18+
1619
class BanTableModel;
1720
class CBlockIndex;
1821
class OptionsModel;
@@ -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;

src/qt/forms/debugwindow.ui

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,38 @@
249249
</widget>
250250
</item>
251251
<item row="9" column="0">
252+
<widget class="QLabel" name="label_14">
253+
<property name="text">
254+
<string>Local Addresses</string>
255+
</property>
256+
</widget>
257+
</item>
258+
<item row="9" column="1" colspan="2">
259+
<widget class="QLabel" name="localAddresses">
260+
<property name="cursor">
261+
<cursorShape>IBeamCursor</cursorShape>
262+
</property>
263+
<property name="wordWrap">
264+
<bool>true</bool>
265+
</property>
266+
<property name="sizePolicy">
267+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
268+
<horstretch>0</horstretch>
269+
<verstretch>0</verstretch>
270+
</sizepolicy>
271+
</property>
272+
<property name="text">
273+
<string notr="true">N/A</string>
274+
</property>
275+
<property name="textFormat">
276+
<enum>Qt::PlainText</enum>
277+
</property>
278+
<property name="textInteractionFlags">
279+
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
280+
</property>
281+
</widget>
282+
</item>
283+
<item row="10" column="0">
252284
<widget class="QLabel" name="label_10">
253285
<property name="font">
254286
<font>
@@ -261,14 +293,14 @@
261293
</property>
262294
</widget>
263295
</item>
264-
<item row="10" column="0">
296+
<item row="11" column="0">
265297
<widget class="QLabel" name="label_3">
266298
<property name="text">
267299
<string>Current block height</string>
268300
</property>
269301
</widget>
270302
</item>
271-
<item row="10" column="1" colspan="2">
303+
<item row="11" column="1" colspan="2">
272304
<widget class="QLabel" name="numberOfBlocks">
273305
<property name="cursor">
274306
<cursorShape>IBeamCursor</cursorShape>
@@ -284,14 +316,14 @@
284316
</property>
285317
</widget>
286318
</item>
287-
<item row="11" column="0">
319+
<item row="12" column="0">
288320
<widget class="QLabel" name="labelLastBlockTime">
289321
<property name="text">
290322
<string>Last block time</string>
291323
</property>
292324
</widget>
293325
</item>
294-
<item row="11" column="1" colspan="2">
326+
<item row="12" column="1" colspan="2">
295327
<widget class="QLabel" name="lastBlockTime">
296328
<property name="cursor">
297329
<cursorShape>IBeamCursor</cursorShape>
@@ -307,7 +339,7 @@
307339
</property>
308340
</widget>
309341
</item>
310-
<item row="12" column="0">
342+
<item row="13" column="0">
311343
<widget class="QLabel" name="labelMempoolTitle">
312344
<property name="font">
313345
<font>
@@ -320,14 +352,14 @@
320352
</property>
321353
</widget>
322354
</item>
323-
<item row="13" column="0">
355+
<item row="14" column="0">
324356
<widget class="QLabel" name="labelNumberOfTransactions">
325357
<property name="text">
326358
<string>Current number of transactions</string>
327359
</property>
328360
</widget>
329361
</item>
330-
<item row="13" column="1">
362+
<item row="14" column="1">
331363
<widget class="QLabel" name="mempoolNumberTxs">
332364
<property name="cursor">
333365
<cursorShape>IBeamCursor</cursorShape>
@@ -343,14 +375,14 @@
343375
</property>
344376
</widget>
345377
</item>
346-
<item row="14" column="0">
378+
<item row="15" column="0">
347379
<widget class="QLabel" name="labelMemoryUsage">
348380
<property name="text">
349381
<string>Memory usage</string>
350382
</property>
351383
</widget>
352384
</item>
353-
<item row="14" column="1">
385+
<item row="15" column="1">
354386
<widget class="QLabel" name="mempoolSize">
355387
<property name="cursor">
356388
<cursorShape>IBeamCursor</cursorShape>
@@ -366,7 +398,7 @@
366398
</property>
367399
</widget>
368400
</item>
369-
<item row="12" column="2" rowspan="3">
401+
<item row="13" column="2" rowspan="3">
370402
<layout class="QVBoxLayout" name="verticalLayoutDebugButton">
371403
<property name="spacing">
372404
<number>3</number>
@@ -406,7 +438,7 @@
406438
</item>
407439
</layout>
408440
</item>
409-
<item row="15" column="0">
441+
<item row="16" column="0">
410442
<spacer name="verticalSpacer">
411443
<property name="orientation">
412444
<enum>Qt::Vertical</enum>

src/qt/rpcconsole.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,18 @@ void RPCConsole::updateNetworkState()
975975
}
976976

977977
ui->numberOfConnections->setText(connections);
978+
979+
QString local_addresses;
980+
std::map<CNetAddr, LocalServiceInfo> hosts = clientModel->getNetLocalAddresses();
981+
for (const auto& [addr, info] : hosts) {
982+
local_addresses += QString::fromStdString(addr.ToStringAddr());
983+
if (!addr.IsI2P()) local_addresses += ":" + QString::number(info.nPort);
984+
local_addresses += ", ";
985+
}
986+
local_addresses.chop(2); // remove last ", "
987+
if (local_addresses.isEmpty()) local_addresses = tr("None");
988+
989+
ui->localAddresses->setText(local_addresses);
978990
}
979991

980992
void RPCConsole::setNumConnections(int count)

0 commit comments

Comments
 (0)