Skip to content

Commit 493768c

Browse files
committed
merge bitcoin-core/gui#626: Showing Local Addresses in Node Window
1 parent 4e1b06b commit 493768c

File tree

8 files changed

+97
-23
lines changed

8 files changed

+97
-23
lines changed

src/interfaces/node.h

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

245+
//! Get network local addresses.
246+
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;
247+
245248
//! Get best block hash.
246249
virtual uint256 getBestBlockHash() = 0;
247250

src/net.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,10 +4449,17 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
44494449
return nNum;
44504450
}
44514451

4452+
std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
4453+
{
4454+
LOCK(g_maplocalhost_mutex);
4455+
return mapLocalHost;
4456+
}
4457+
44524458
size_t CConnman::GetMaxOutboundNodeCount()
44534459
{
44544460
return m_max_outbound;
44554461
}
4462+
44564463
size_t CConnman::GetMaxOutboundOnionNodeCount()
44574464
{
44584465
return m_max_outbound_onion;

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ friend class CNode;
14891489
void AddPendingProbeConnections(const std::set<uint256>& proTxHashes);
14901490

14911491
size_t GetNodeCount(ConnectionDirection) const;
1492+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
14921493
size_t GetMaxOutboundNodeCount();
14931494
size_t GetMaxOutboundOnionNodeCount();
14941495
void GetNodeStats(std::vector<CNodeStats>& vstats) const;

src/node/interfaces.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ class NodeImpl : public Node
531531
}
532532
return false;
533533
}
534+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
535+
{
536+
if (m_context->connman)
537+
return m_context->connman->getNetLocalAddresses();
538+
else
539+
return {};
540+
}
534541
int getNumBlocks() override
535542
{
536543
LOCK(::cs_main);

src/qt/clientmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ void ClientModel::getAllGovernanceObjects(std::vector<CGovernanceObject> &obj)
157157
m_node.gov().getAllNewerThan(obj, 0);
158158
}
159159

160+
std::map<CNetAddr, LocalServiceInfo> ClientModel::getNetLocalAddresses() const
161+
{
162+
return m_node.getNetLocalAddresses();
163+
}
164+
160165
int ClientModel::getNumBlocks() const
161166
{
162167
if (m_cached_num_blocks == -1) {

src/qt/clientmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
#include <memory>
1717
#include <uint256.h>
1818

19+
#include <netaddress.h>
20+
1921
class BanTableModel;
2022
class CBlockIndex;
2123
class OptionsModel;
2224
class PeerTableModel;
2325
class PeerTableSortProxy;
2426
enum class SynchronizationState;
27+
struct LocalServiceInfo;
2528

2629
namespace interfaces {
2730
struct BlockTip;
@@ -69,6 +72,7 @@ class ClientModel : public QObject
6972

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

src/qt/forms/debugwindow.ui

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,48 @@
297297
</widget>
298298
</item>
299299
<item row="9" column="0">
300+
<widget class="QLabel" name="label_14">
301+
<property name="text">
302+
<string>Local Addresses</string>
303+
</property>
304+
</widget>
305+
</item>
306+
<item row="9" column="1" colspan="2">
307+
<widget class="QLabel" name="localAddresses">
308+
<property name="cursor">
309+
<cursorShape>IBeamCursor</cursorShape>
310+
</property>
311+
<property name="wordWrap">
312+
<bool>true</bool>
313+
</property>
314+
<property name="sizePolicy">
315+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
316+
<horstretch>0</horstretch>
317+
<verstretch>0</verstretch>
318+
</sizepolicy>
319+
</property>
320+
<property name="text">
321+
<string notr="true">N/A</string>
322+
</property>
323+
<property name="textFormat">
324+
<enum>Qt::PlainText</enum>
325+
</property>
326+
<property name="textInteractionFlags">
327+
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
328+
</property>
329+
<property name="toolTip">
330+
<string>Network addresses that your Dash node is currently using to communicate with other nodes.</string>
331+
</property>
332+
</widget>
333+
</item>
334+
<item row="10" column="0">
300335
<widget class="QLabel" name="masternodeCountLabel">
301336
<property name="text">
302337
<string>Number of regular Masternodes</string>
303338
</property>
304339
</widget>
305340
</item>
306-
<item row="9" column="1">
341+
<item row="10" column="1">
307342
<widget class="QLabel" name="masternodeCount">
308343
<property name="cursor">
309344
<cursorShape>IBeamCursor</cursorShape>
@@ -316,14 +351,14 @@
316351
</property>
317352
</widget>
318353
</item>
319-
<item row="10" column="0">
354+
<item row="11" column="0">
320355
<widget class="QLabel" name="evoCountLabel">
321356
<property name="text">
322357
<string>Number of EvoNodes</string>
323358
</property>
324359
</widget>
325360
</item>
326-
<item row="10" column="1">
361+
<item row="11" column="1">
327362
<widget class="QLabel" name="evoCount">
328363
<property name="cursor">
329364
<cursorShape>IBeamCursor</cursorShape>
@@ -336,21 +371,21 @@
336371
</property>
337372
</widget>
338373
</item>
339-
<item row="11" column="0">
374+
<item row="12" column="0">
340375
<widget class="QLabel" name="label_10">
341376
<property name="text">
342377
<string>Block chain</string>
343378
</property>
344379
</widget>
345380
</item>
346-
<item row="12" column="0">
381+
<item row="13" column="0">
347382
<widget class="QLabel" name="label_3">
348383
<property name="text">
349384
<string>Current block height</string>
350385
</property>
351386
</widget>
352387
</item>
353-
<item row="12" column="1" colspan="2">
388+
<item row="13" column="1" colspan="2">
354389
<widget class="QLabel" name="numberOfBlocks">
355390
<property name="cursor">
356391
<cursorShape>IBeamCursor</cursorShape>
@@ -366,14 +401,14 @@
366401
</property>
367402
</widget>
368403
</item>
369-
<item row="13" column="0">
404+
<item row="14" column="0">
370405
<widget class="QLabel" name="labelLastBlockTime">
371406
<property name="text">
372407
<string>Last block time</string>
373408
</property>
374409
</widget>
375410
</item>
376-
<item row="13" column="1" colspan="2">
411+
<item row="14" column="1" colspan="2">
377412
<widget class="QLabel" name="lastBlockTime">
378413
<property name="cursor">
379414
<cursorShape>IBeamCursor</cursorShape>
@@ -389,14 +424,14 @@
389424
</property>
390425
</widget>
391426
</item>
392-
<item row="14" column="0">
427+
<item row="15" column="0">
393428
<widget class="QLabel" name="lastBlockHashLabel">
394429
<property name="text">
395430
<string>Last block hash</string>
396431
</property>
397432
</widget>
398433
</item>
399-
<item row="14" column="1">
434+
<item row="15" column="1">
400435
<widget class="QLabel" name="lastBlockHash">
401436
<property name="cursor">
402437
<cursorShape>IBeamCursor</cursorShape>
@@ -412,14 +447,14 @@
412447
</property>
413448
</widget>
414449
</item>
415-
<item row="15" column="0">
450+
<item row="16" column="0">
416451
<widget class="QLabel" name="bestChainLockHashLabel">
417452
<property name="text">
418453
<string>Latest ChainLocked block hash</string>
419454
</property>
420455
</widget>
421456
</item>
422-
<item row="15" column="1">
457+
<item row="16" column="1">
423458
<widget class="QLabel" name="bestChainLockHash">
424459
<property name="cursor">
425460
<cursorShape>IBeamCursor</cursorShape>
@@ -435,14 +470,14 @@
435470
</property>
436471
</widget>
437472
</item>
438-
<item row="16" column="0">
473+
<item row="17" column="0">
439474
<widget class="QLabel" name="bestChainLockHeightLabel">
440475
<property name="text">
441476
<string>Latest ChainLocked block height</string>
442477
</property>
443478
</widget>
444479
</item>
445-
<item row="16" column="1">
480+
<item row="17" column="1">
446481
<widget class="QLabel" name="bestChainLockHeight">
447482
<property name="cursor">
448483
<cursorShape>IBeamCursor</cursorShape>
@@ -458,21 +493,21 @@
458493
</property>
459494
</widget>
460495
</item>
461-
<item row="17" column="0">
496+
<item row="18" column="0">
462497
<widget class="QLabel" name="labelMempoolTitle">
463498
<property name="text">
464499
<string>Memory Pool</string>
465500
</property>
466501
</widget>
467502
</item>
468-
<item row="18" column="0">
503+
<item row="19" column="0">
469504
<widget class="QLabel" name="labelNumberOfTransactions">
470505
<property name="text">
471506
<string>Current number of transactions</string>
472507
</property>
473508
</widget>
474509
</item>
475-
<item row="18" column="1">
510+
<item row="19" column="1">
476511
<widget class="QLabel" name="mempoolNumberTxs">
477512
<property name="cursor">
478513
<cursorShape>IBeamCursor</cursorShape>
@@ -488,14 +523,14 @@
488523
</property>
489524
</widget>
490525
</item>
491-
<item row="19" column="0">
526+
<item row="20" column="0">
492527
<widget class="QLabel" name="labelMemoryUsage">
493528
<property name="text">
494529
<string>Memory usage</string>
495530
</property>
496531
</widget>
497532
</item>
498-
<item row="19" column="1">
533+
<item row="20" column="1">
499534
<widget class="QLabel" name="mempoolSize">
500535
<property name="cursor">
501536
<cursorShape>IBeamCursor</cursorShape>
@@ -511,7 +546,7 @@
511546
</property>
512547
</widget>
513548
</item>
514-
<item row="18" column="2" rowspan="3">
549+
<item row="19" column="2" rowspan="3">
515550
<layout class="QVBoxLayout" name="verticalLayoutDebugButton">
516551
<property name="spacing">
517552
<number>3</number>
@@ -551,14 +586,14 @@
551586
</item>
552587
</layout>
553588
</item>
554-
<item row="20" column="0">
589+
<item row="21" column="0">
555590
<widget class="QLabel" name="labelInstantSendLockCount">
556591
<property name="text">
557592
<string>InstantSend locks</string>
558593
</property>
559594
</widget>
560595
</item>
561-
<item row="20" column="1">
596+
<item row="21" column="1">
562597
<widget class="QLabel" name="instantSendLockCount">
563598
<property name="cursor">
564599
<cursorShape>IBeamCursor</cursorShape>
@@ -574,7 +609,7 @@
574609
</property>
575610
</widget>
576611
</item>
577-
<item row="21" column="0">
612+
<item row="22" column="0">
578613
<spacer name="verticalSpacer">
579614
<property name="orientation">
580615
<enum>Qt::Vertical</enum>

src/qt/rpcconsole.cpp

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

10471047
ui->numberOfConnections->setText(connections);
1048+
1049+
QString local_addresses;
1050+
std::map<CNetAddr, LocalServiceInfo> hosts = clientModel->getNetLocalAddresses();
1051+
for (const auto& [addr, info] : hosts) {
1052+
local_addresses += QString::fromStdString(addr.ToStringAddr());
1053+
if (!addr.IsI2P()) local_addresses += ":" + QString::number(info.nPort);
1054+
local_addresses += ", ";
1055+
}
1056+
local_addresses.chop(2); // remove last ", "
1057+
if (local_addresses.isEmpty()) local_addresses = tr("None");
1058+
1059+
ui->localAddresses->setText(local_addresses);
10481060
}
10491061

10501062
void RPCConsole::setNumConnections(int count)

0 commit comments

Comments
 (0)