Skip to content

Commit ec8b38c

Browse files
committed
Merge bitcoin-core#626: Showing Local Addresses in Node Window
189c987 Showing local addresses on the Node Window (Jadi) a5d7aff net: Providing an interface for mapLocalHost (Jadi) Pull request description: This change adds a new row to the Node Window (debugwindow.ui) under the Network section which shows the LocalAddresses. fixes bitcoin-core#564 <!-- *** Please remove the following help text before submitting: *** Pull requests without a rationale and clear improvement may be closed immediately. GUI-related pull requests should be opened against https://github.com/bitcoin-core/gui first. See CONTRIBUTING.md --> <!-- Please provide clear motivation for your patch and explain how it improves Bitcoin Core user experience or Bitcoin Core developer experience significantly: * Any test improvements or new tests that improve coverage are always welcome. * All other changes should have accompanying unit tests (see `src/test/`) or functional tests (see `test/`). Contributors should note which tests cover modified code. If no tests exist for a region of modified code, new tests should accompany the change. * Bug fixes are most welcome when they come with steps to reproduce or an explanation of the potential issue as well as reasoning for the way the bug was fixed. * Features are welcome, but might be rejected due to design or scope issues. If a feature is based on a lot of dependencies, contributors should first consider building the system outside of Bitcoin Core, if possible. * Refactoring changes are only accepted if they are required for a feature or bug fix or otherwise improve developer experience significantly. For example, most "code style" refactoring changes require a thorough explanation why they are useful, what downsides they have and why they *significantly* improve developer experience or avoid serious programming bugs. Note that code style is often a subjective matter. Unless they are explicitly mentioned to be preferred in the [developer notes](/doc/developer-notes.md), stylistic code changes are usually rejected. --> <!-- Bitcoin Core has a thorough review process and even the most trivial change needs to pass a lot of eyes and requires non-zero or even substantial time effort to review. There is a huge lack of active reviewers on the project, so patches often sit for a long time. --> ACKs for top commit: pablomartin4btc: re-ACK 189c987 furszy: utACK 189c987 Tree-SHA512: 93f201bc6d21d81b27b87be050a447b841f01e3efb69b9eca2cc7af103023d7cd69eb5e16e2875855573ef51a5bf74a6ee6028636c1b6798cb4bb11567cb4996
2 parents df24197 + 189c987 commit ec8b38c

File tree

8 files changed

+87
-11
lines changed

8 files changed

+87
-11
lines changed

src/interfaces/node.h

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

174+
//! Get network local addresses.
175+
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;
176+
174177
//! Get best block hash.
175178
virtual uint256 getBestBlockHash() = 0;
176179

src/net.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,13 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
35503550
return nNum;
35513551
}
35523552

3553+
3554+
std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
3555+
{
3556+
LOCK(g_maplocalhost_mutex);
3557+
return mapLocalHost;
3558+
}
3559+
35533560
uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
35543561
{
35553562
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
@@ -290,6 +290,13 @@ class NodeImpl : public Node
290290
}
291291
return false;
292292
}
293+
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
294+
{
295+
if (m_context->connman)
296+
return m_context->connman->getNetLocalAddresses();
297+
else
298+
return {};
299+
}
293300
int getNumBlocks() override
294301
{
295302
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;

src/qt/forms/debugwindow.ui

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,41 @@
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+
<property name="toolTip">
282+
<string>Network addresses that your Bitcoin node is currently using to communicate with other nodes.</string>
283+
</property>
284+
</widget>
285+
</item>
286+
<item row="10" column="0">
252287
<widget class="QLabel" name="label_10">
253288
<property name="font">
254289
<font>
@@ -261,14 +296,14 @@
261296
</property>
262297
</widget>
263298
</item>
264-
<item row="10" column="0">
299+
<item row="11" column="0">
265300
<widget class="QLabel" name="label_3">
266301
<property name="text">
267302
<string>Current block height</string>
268303
</property>
269304
</widget>
270305
</item>
271-
<item row="10" column="1" colspan="2">
306+
<item row="11" column="1" colspan="2">
272307
<widget class="QLabel" name="numberOfBlocks">
273308
<property name="cursor">
274309
<cursorShape>IBeamCursor</cursorShape>
@@ -284,14 +319,14 @@
284319
</property>
285320
</widget>
286321
</item>
287-
<item row="11" column="0">
322+
<item row="12" column="0">
288323
<widget class="QLabel" name="labelLastBlockTime">
289324
<property name="text">
290325
<string>Last block time</string>
291326
</property>
292327
</widget>
293328
</item>
294-
<item row="11" column="1" colspan="2">
329+
<item row="12" column="1" colspan="2">
295330
<widget class="QLabel" name="lastBlockTime">
296331
<property name="cursor">
297332
<cursorShape>IBeamCursor</cursorShape>
@@ -307,7 +342,7 @@
307342
</property>
308343
</widget>
309344
</item>
310-
<item row="12" column="0">
345+
<item row="13" column="0">
311346
<widget class="QLabel" name="labelMempoolTitle">
312347
<property name="font">
313348
<font>
@@ -320,14 +355,14 @@
320355
</property>
321356
</widget>
322357
</item>
323-
<item row="13" column="0">
358+
<item row="14" column="0">
324359
<widget class="QLabel" name="labelNumberOfTransactions">
325360
<property name="text">
326361
<string>Current number of transactions</string>
327362
</property>
328363
</widget>
329364
</item>
330-
<item row="13" column="1">
365+
<item row="14" column="1">
331366
<widget class="QLabel" name="mempoolNumberTxs">
332367
<property name="cursor">
333368
<cursorShape>IBeamCursor</cursorShape>
@@ -343,14 +378,14 @@
343378
</property>
344379
</widget>
345380
</item>
346-
<item row="14" column="0">
381+
<item row="15" column="0">
347382
<widget class="QLabel" name="labelMemoryUsage">
348383
<property name="text">
349384
<string>Memory usage</string>
350385
</property>
351386
</widget>
352387
</item>
353-
<item row="14" column="1">
388+
<item row="15" column="1">
354389
<widget class="QLabel" name="mempoolSize">
355390
<property name="cursor">
356391
<cursorShape>IBeamCursor</cursorShape>
@@ -366,7 +401,7 @@
366401
</property>
367402
</widget>
368403
</item>
369-
<item row="12" column="2" rowspan="3">
404+
<item row="13" column="2" rowspan="3">
370405
<layout class="QVBoxLayout" name="verticalLayoutDebugButton">
371406
<property name="spacing">
372407
<number>3</number>
@@ -406,7 +441,7 @@
406441
</item>
407442
</layout>
408443
</item>
409-
<item row="15" column="0">
444+
<item row="16" column="0">
410445
<spacer name="verticalSpacer">
411446
<property name="orientation">
412447
<enum>Qt::Vertical</enum>

src/qt/rpcconsole.cpp

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

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

983995
void RPCConsole::setNumConnections(int count)

0 commit comments

Comments
 (0)