Skip to content

Commit 22ad339

Browse files
MarcoFalkeFabcien
authored andcommitted
Remove unused MaybeSetAddrName
Summary: Backport of [[bitcoin/bitcoin#22782 | core#22782]]. Test Plan: Enable tracing, then: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D12637
1 parent d770725 commit 22ad339

File tree

8 files changed

+26
-52
lines changed

8 files changed

+26
-52
lines changed

doc/tracing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ For example:
147147
```C++
148148
TRACE6(net, inbound_message,
149149
pnode->GetId(),
150-
pnode->GetAddrName().c_str(),
150+
pnode->m_addr_name.c_str(),
151151
pnode->ConnectionTypeAsString().c_str(),
152152
sanitizedType.c_str(),
153153
msg.data.size(),

src/net.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ CNode *CConnman::FindNode(const CSubNet &subNet) {
332332
CNode *CConnman::FindNode(const std::string &addrName) {
333333
LOCK(cs_vNodes);
334334
for (CNode *pnode : vNodes) {
335-
if (pnode->GetAddrName() == addrName) {
335+
if (pnode->m_addr_name == addrName) {
336336
return pnode;
337337
}
338338
}
@@ -424,13 +424,10 @@ CNode *CConnman::ConnectNode(CAddress addrConnect, const char *pszDest,
424424
}
425425
// It is possible that we already have a connection to the IP/port
426426
// pszDest resolved to. In that case, drop the connection that was
427-
// just created, and return the existing CNode instead. Also store
428-
// the name we used to connect in that CNode, so that future
429-
// FindNode() calls to that name catch this early.
427+
// just created.
430428
LOCK(cs_vNodes);
431429
CNode *pnode = FindNode(static_cast<CService>(addrConnect));
432430
if (pnode) {
433-
pnode->MaybeSetAddrName(std::string(pszDest));
434431
LogPrintf("Failed to open new connection, already connected\n");
435432
return nullptr;
436433
}
@@ -561,18 +558,6 @@ std::string CNode::ConnectionTypeAsString() const {
561558
assert(false);
562559
}
563560

564-
std::string CNode::GetAddrName() const {
565-
LOCK(cs_addrName);
566-
return addrName;
567-
}
568-
569-
void CNode::MaybeSetAddrName(const std::string &addrNameIn) {
570-
LOCK(cs_addrName);
571-
if (addrName.empty()) {
572-
addrName = addrNameIn;
573-
}
574-
}
575-
576561
CService CNode::GetAddrLocal() const {
577562
LOCK(cs_addrLocal);
578563
return addrLocal;
@@ -612,7 +597,7 @@ void CNode::copyStats(CNodeStats &stats) {
612597
stats.m_last_block_time = m_last_block_time;
613598
stats.m_connected = m_connected;
614599
stats.nTimeOffset = nTimeOffset;
615-
stats.addrName = GetAddrName();
600+
stats.m_addr_name = m_addr_name;
616601
stats.nVersion = nVersion;
617602
{
618603
LOCK(cs_SubVer);
@@ -2506,7 +2491,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() {
25062491
if (pnode->addr.IsValid()) {
25072492
mapConnected[pnode->addr] = pnode->IsInboundConn();
25082493
}
2509-
std::string addrName = pnode->GetAddrName();
2494+
std::string addrName{pnode->m_addr_name};
25102495
if (!addrName.empty()) {
25112496
mapConnectedByName[std::move(addrName)] =
25122497
std::make_pair(pnode->IsInboundConn(),
@@ -3456,8 +3441,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
34563441
const CAddress &addrBindIn, const std::string &addrNameIn,
34573442
ConnectionType conn_type_in, bool inbound_onion)
34583443
: m_connected(GetTime<std::chrono::seconds>()), addr(addrIn),
3459-
addrBind(addrBindIn), m_inbound_onion(inbound_onion),
3460-
nKeyedNetGroup(nKeyedNetGroupIn),
3444+
addrBind(addrBindIn), m_addr_name{addrNameIn.empty()
3445+
? addr.ToStringIPPort()
3446+
: addrNameIn},
3447+
m_inbound_onion(inbound_onion), nKeyedNetGroup(nKeyedNetGroupIn),
34613448
m_tx_relay(conn_type_in != ConnectionType::BLOCK_RELAY
34623449
? std::make_unique<TxRelay>()
34633450
: nullptr),
@@ -3473,15 +3460,15 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
34733460
assert(conn_type_in == ConnectionType::INBOUND);
34743461
}
34753462
hSocket = hSocketIn;
3476-
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
34773463

34783464
for (const std::string &msg : getAllNetMessageTypes()) {
34793465
mapRecvBytesPerMsgCmd[msg] = 0;
34803466
}
34813467
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
34823468

34833469
if (fLogIPs) {
3484-
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", addrName, id);
3470+
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name,
3471+
id);
34853472
} else {
34863473
LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
34873474
}
@@ -3509,7 +3496,7 @@ void CConnman::PushMessage(CNode *pnode, CSerializedNetMsg &&msg) {
35093496
CaptureMessage(pnode->addr, msg.m_type, msg.data, /*incoming=*/false);
35103497
}
35113498

3512-
TRACE6(net, outbound_message, pnode->GetId(), pnode->GetAddrName().c_str(),
3499+
TRACE6(net, outbound_message, pnode->GetId(), pnode->m_addr_name.c_str(),
35133500
pnode->ConnectionTypeAsString().c_str(), msg.m_type.c_str(),
35143501
msg.data.size(), msg.data.data());
35153502

src/net.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ struct CNodeStats {
292292
std::chrono::seconds m_last_block_time;
293293
std::chrono::seconds m_connected;
294294
int64_t nTimeOffset;
295-
std::string addrName;
295+
std::string m_addr_name;
296296
int nVersion;
297297
std::string cleanSubVer;
298298
bool fInbound;
@@ -490,6 +490,7 @@ class CNode {
490490
const CAddress addr;
491491
// Bind address of our side of the connection
492492
const CAddress addrBind;
493+
const std::string m_addr_name;
493494
//! Whether this peer is an inbound onion, i.e. connected via our Tor onion
494495
//! service.
495496
const bool m_inbound_onion;
@@ -774,9 +775,6 @@ class CNode {
774775
// Used only by SocketHandler thread
775776
std::list<CNetMessage> vRecvMsg;
776777

777-
mutable RecursiveMutex cs_addrName;
778-
std::string addrName GUARDED_BY(cs_addrName);
779-
780778
// Our address, as reported by the peer
781779
CService addrLocal GUARDED_BY(cs_addrLocal);
782780
mutable RecursiveMutex cs_addrLocal;
@@ -872,10 +870,6 @@ class CNode {
872870

873871
ServiceFlags GetLocalServices() const { return nLocalServices; }
874872

875-
std::string GetAddrName() const;
876-
//! Sets the addrName only if it was not previously set
877-
void MaybeSetAddrName(const std::string &addrNameIn);
878-
879873
std::string ConnectionTypeAsString() const;
880874
};
881875

src/net_processing.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,6 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) {
16121612

16131613
void PeerManagerImpl::InitializeNode(const Config &config, CNode *pnode) {
16141614
CAddress addr = pnode->addr;
1615-
std::string addrName = pnode->GetAddrName();
16161615
NodeId nodeid = pnode->GetId();
16171616
{
16181617
LOCK(cs_main);
@@ -5867,7 +5866,7 @@ bool PeerManagerImpl::ProcessMessages(const Config &config, CNode *pfrom,
58675866
}
58685867
CNetMessage &msg(msgs.front());
58695868

5870-
TRACE6(net, inbound_message, pfrom->GetId(), pfrom->GetAddrName().c_str(),
5869+
TRACE6(net, inbound_message, pfrom->GetId(), pfrom->m_addr_name.c_str(),
58715870
pfrom->ConnectionTypeAsString().c_str(), msg.m_command.c_str(),
58725871
msg.m_recv.size(), msg.m_recv.data());
58735872

src/qt/peertablemodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left,
2828
case PeerTableModel::NetNodeId:
2929
return pLeft->nodeid < pRight->nodeid;
3030
case PeerTableModel::Address:
31-
return pLeft->addrName.compare(pRight->addrName) < 0;
31+
return pLeft->m_addr_name.compare(pRight->m_addr_name) < 0;
3232
case PeerTableModel::Network:
3333
return pLeft->m_network < pRight->m_network;
3434
case PeerTableModel::Ping:
@@ -151,7 +151,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const {
151151
// prepend to peer address down-arrow symbol for inbound
152152
// connection and up-arrow for outbound connection
153153
return QString(rec->nodeStats.fInbound ? "" : "") +
154-
QString::fromStdString(rec->nodeStats.addrName);
154+
QString::fromStdString(rec->nodeStats.m_addr_name);
155155
case Network:
156156
return GUIUtil::NetworkToQString(rec->nodeStats.m_network);
157157
case Ping:

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,8 @@ void RPCConsole::updateDetailWidget() {
12601260
clientModel->getPeerTableModel()->getNodeStats(
12611261
selected_rows.first().row());
12621262
// update the detail ui with latest node information
1263-
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) +
1264-
" ");
1263+
QString peerAddrDetails(
1264+
QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
12651265
peerAddrDetails +=
12661266
tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid));
12671267
if (!stats->nodeStats.addrLocal.empty()) {

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static RPCHelpMan getpeerinfo() {
235235
bool fStateStats =
236236
node.peerman->GetNodeStateStats(stats.nodeid, statestats);
237237
obj.pushKV("id", stats.nodeid);
238-
obj.pushKV("addr", stats.addrName);
238+
obj.pushKV("addr", stats.m_addr_name);
239239
if (stats.addrBind.IsValid()) {
240240
obj.pushKV("addrbind", stats.addrBind.ToString());
241241
}

src/test/fuzz/net.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,22 @@ void test_one_input(const std::vector<uint8_t> &buffer) {
6666
break;
6767
}
6868
case 1: {
69-
node.MaybeSetAddrName(
70-
fuzzed_data_provider.ConsumeRandomLengthString(32));
71-
break;
72-
}
73-
case 2: {
7469
CNodeStats stats;
7570
node.copyStats(stats);
7671
break;
7772
}
78-
case 3: {
73+
case 2: {
7974
const CNode *add_ref_node = node.AddRef();
8075
assert(add_ref_node == &node);
8176
break;
8277
}
83-
case 4: {
78+
case 3: {
8479
if (node.GetRefCount() > 0) {
8580
node.Release();
8681
}
8782
break;
8883
}
89-
case 5: {
84+
case 4: {
9085
const std::optional<CInv> inv_opt =
9186
ConsumeDeserializable<CInv>(fuzzed_data_provider);
9287
if (!inv_opt) {
@@ -96,12 +91,12 @@ void test_one_input(const std::vector<uint8_t> &buffer) {
9691
node.AddKnownTx(txid);
9792
break;
9893
}
99-
case 6: {
94+
case 5: {
10095
const TxId &txid = TxId(ConsumeUInt256(fuzzed_data_provider));
10196
node.PushTxInventory(txid);
10297
break;
10398
}
104-
case 7: {
99+
case 6: {
105100
const std::optional<CService> service_opt =
106101
ConsumeDeserializable<CService>(fuzzed_data_provider);
107102
if (!service_opt) {
@@ -110,7 +105,7 @@ void test_one_input(const std::vector<uint8_t> &buffer) {
110105
node.SetAddrLocal(*service_opt);
111106
break;
112107
}
113-
case 8: {
108+
case 7: {
114109
const std::vector<uint8_t> b =
115110
ConsumeRandomLengthByteVector(fuzzed_data_provider);
116111
bool complete;
@@ -121,7 +116,6 @@ void test_one_input(const std::vector<uint8_t> &buffer) {
121116
}
122117

123118
(void)node.GetAddrLocal();
124-
(void)node.GetAddrName();
125119
(void)node.GetId();
126120
(void)node.GetLocalNonce();
127121
(void)node.GetLocalServices();

0 commit comments

Comments
 (0)