Skip to content

Commit bf98ad6

Browse files
committed
merge bitcoin#22782: Remove unused MaybeSetAddrName
1 parent 2b65526 commit bf98ad6

File tree

7 files changed

+16
-42
lines changed

7 files changed

+16
-42
lines changed

src/llmq/dkgsession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ void CDKGSession::RelayInvToParticipants(const CInv& inv) const
13361336
if (pnode->GetVerifiedProRegTxHash().IsNull()) {
13371337
logger.Batch("node[%d:%s] not mn",
13381338
pnode->GetId(),
1339-
pnode->GetAddrName());
1339+
pnode->m_addr_name);
13401340
} else if (relayMembers.count(pnode->GetVerifiedProRegTxHash()) == 0) {
13411341
ss2 << pnode->GetVerifiedProRegTxHash().ToString().substr(0, 4) << " | ";
13421342
}

src/net.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ CNode* CConnman::FindNode(const std::string& addrName, bool fExcludeDisconnectin
364364
if (fExcludeDisconnecting && pnode->fDisconnect) {
365365
continue;
366366
}
367-
if (pnode->GetAddrName() == addrName) {
367+
if (pnode->m_addr_name == addrName) {
368368
return pnode;
369369
}
370370
}
@@ -457,14 +457,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
457457
return nullptr;
458458
}
459459
// It is possible that we already have a connection to the IP/port pszDest resolved to.
460-
// In that case, drop the connection that was just created, and return the existing CNode instead.
461-
// Also store the name we used to connect in that CNode, so that future FindNode() calls to that
462-
// name catch this early.
460+
// In that case, drop the connection that was just created.
463461
LOCK(cs_vNodes);
464462
CNode* pnode = FindNode(static_cast<CService>(addrConnect));
465-
if (pnode)
466-
{
467-
pnode->MaybeSetAddrName(std::string(pszDest));
463+
if (pnode) {
468464
LogPrintf("Failed to open new connection, already connected\n");
469465
return nullptr;
470466
}
@@ -608,19 +604,8 @@ std::string ConnectionTypeAsString(ConnectionType conn_type)
608604
assert(false);
609605
}
610606

611-
std::string CNode::GetAddrName() const {
612-
LOCK(cs_addrName);
613-
return addrName;
614-
}
615-
616-
void CNode::MaybeSetAddrName(const std::string& addrNameIn) {
617-
LOCK(cs_addrName);
618-
if (addrName.empty()) {
619-
addrName = addrNameIn;
620-
}
621-
}
622-
623-
CService CNode::GetAddrLocal() const {
607+
CService CNode::GetAddrLocal() const
608+
{
624609
LOCK(cs_addrLocal);
625610
return addrLocal;
626611
}
@@ -660,7 +645,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
660645
X(nLastBlockTime);
661646
X(nTimeConnected);
662647
X(nTimeOffset);
663-
stats.addrName = GetAddrName();
648+
X(m_addr_name);
664649
X(nVersion);
665650
{
666651
LOCK(cs_SubVer);
@@ -2629,7 +2614,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
26292614
if (pnode->addr.IsValid()) {
26302615
mapConnected[pnode->addr] = pnode->IsInboundConn();
26312616
}
2632-
std::string addrName = pnode->GetAddrName();
2617+
std::string addrName{pnode->m_addr_name};
26332618
if (!addrName.empty()) {
26342619
mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->IsInboundConn(), static_cast<const CService&>(pnode->addr));
26352620
}
@@ -4018,6 +4003,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
40184003
: nTimeConnected(GetTimeSeconds()),
40194004
addr(addrIn),
40204005
addrBind(addrBindIn),
4006+
m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn},
40214007
m_inbound_onion(inbound_onion),
40224008
nKeyedNetGroup(nKeyedNetGroupIn),
40234009
id(idIn),
@@ -4027,14 +4013,13 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
40274013
{
40284014
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
40294015
hSocket = hSocketIn;
4030-
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
40314016

40324017
for (const std::string &msg : getAllNetMessageTypes())
40334018
mapRecvBytesPerMsgCmd[msg] = 0;
40344019
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
40354020

40364021
if (fLogIPs) {
4037-
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", addrName, id);
4022+
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id);
40384023
} else {
40394024
LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
40404025
}

src/net.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class CNodeStats
281281
int64_t nLastBlockTime;
282282
int64_t nTimeConnected;
283283
int64_t nTimeOffset;
284-
std::string addrName;
284+
std::string m_addr_name;
285285
int nVersion;
286286
std::string cleanSubVer;
287287
bool fInbound;
@@ -471,6 +471,7 @@ class CNode
471471
const CAddress addr;
472472
// Bind address of our side of the connection
473473
const CAddress addrBind;
474+
const std::string m_addr_name;
474475
//! Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
475476
const bool m_inbound_onion;
476477
std::atomic<int> nNumWarningsSkipped{0};
@@ -687,11 +688,6 @@ class CNode
687688
return nLocalServices;
688689
}
689690

690-
std::string GetAddrName() const;
691-
//! Sets the addrName only if it was not previously set
692-
void MaybeSetAddrName(const std::string& addrNameIn);
693-
694-
695691
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
696692

697693
/** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */
@@ -769,9 +765,6 @@ class CNode
769765

770766
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
771767

772-
mutable RecursiveMutex cs_addrName;
773-
std::string addrName GUARDED_BY(cs_addrName);
774-
775768
// Our address, as reported by the peer
776769
CService addrLocal GUARDED_BY(cs_addrLocal);
777770
mutable RecursiveMutex cs_addrLocal;

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, const CNodeCombine
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:
@@ -163,7 +163,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
163163
return (qint64)rec->nodeStats.nodeid;
164164
case Address:
165165
// prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection
166-
return QString(rec->nodeStats.fInbound ? "" : "") + QString::fromStdString(rec->nodeStats.addrName);
166+
return QString(rec->nodeStats.fInbound ? "" : "") + QString::fromStdString(rec->nodeStats.m_addr_name);
167167
case Network:
168168
return GUIUtil::NetworkToQString(rec->nodeStats.m_network);
169169
case Ping:

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ void RPCConsole::updateDetailWidget()
12301230
}
12311231
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected_rows.first().row());
12321232
// update the detail ui with latest node information
1233-
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
1233+
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
12341234
peerAddrDetails += tr("(peer id: %1)").arg(QString::number(stats->nodeStats.nodeid));
12351235
if (!stats->nodeStats.addrLocal.empty())
12361236
peerAddrDetails += "<br />" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal));

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static RPCHelpMan getpeerinfo()
200200
CNodeStateStats statestats;
201201
bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
202202
obj.pushKV("id", stats.nodeid);
203-
obj.pushKV("addr", stats.addrName);
203+
obj.pushKV("addr", stats.m_addr_name);
204204
if (stats.addrBind.IsValid()) {
205205
obj.pushKV("addrbind", stats.addrBind.ToString());
206206
}

src/test/fuzz/net.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ FUZZ_TARGET_INIT(net, initialize_net)
4040
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>(), addrman};
4141
node.CloseSocketDisconnect(&connman);
4242
},
43-
[&] {
44-
node.MaybeSetAddrName(fuzzed_data_provider.ConsumeRandomLengthString(32));
45-
},
4643
[&] {
4744
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
4845
if (!SanityCheckASMap(asmap)) {
@@ -75,7 +72,6 @@ FUZZ_TARGET_INIT(net, initialize_net)
7572
}
7673

7774
(void)node.GetAddrLocal();
78-
(void)node.GetAddrName();
7975
(void)node.GetId();
8076
(void)node.GetLocalNonce();
8177
(void)node.GetLocalServices();

0 commit comments

Comments
 (0)