Skip to content

Commit 33707a2

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22782: Remove unused MaybeSetAddrName
fa9eade Remove GetAddrName (MarcoFalke) fa78657 Remove unused RecursiveMutex cs_addrName (MarcoFalke) fa82f4e Remove unused MaybeSetAddrName (MarcoFalke) Pull request description: . ACKs for top commit: jnewbery: Code review ACK fa9eade naumenkogs: utACK fa9eade Tree-SHA512: 61501a699add59225dc8127b6dfdda450d768c86f958fdf94e9c28309c3705ecfbee4b064d44228b8c1190c19c39272becc7ede8386ac1406699ea2285881c72
2 parents 19364c0 + fa9eade commit 33707a2

File tree

9 files changed

+19
-44
lines changed

9 files changed

+19
-44
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: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ CNode* CConnman::FindNode(const std::string& addrName)
331331
{
332332
LOCK(cs_vNodes);
333333
for (CNode* pnode : vNodes) {
334-
if (pnode->GetAddrName() == addrName) {
334+
if (pnode->m_addr_name == addrName) {
335335
return pnode;
336336
}
337337
}
@@ -414,14 +414,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
414414
return nullptr;
415415
}
416416
// It is possible that we already have a connection to the IP/port pszDest resolved to.
417-
// In that case, drop the connection that was just created, and return the existing CNode instead.
418-
// Also store the name we used to connect in that CNode, so that future FindNode() calls to that
419-
// name catch this early.
417+
// In that case, drop the connection that was just created.
420418
LOCK(cs_vNodes);
421419
CNode* pnode = FindNode(static_cast<CService>(addrConnect));
422-
if (pnode)
423-
{
424-
pnode->MaybeSetAddrName(std::string(pszDest));
420+
if (pnode) {
425421
LogPrintf("Failed to open new connection, already connected\n");
426422
return nullptr;
427423
}
@@ -534,19 +530,8 @@ std::string ConnectionTypeAsString(ConnectionType conn_type)
534530
assert(false);
535531
}
536532

537-
std::string CNode::GetAddrName() const {
538-
LOCK(cs_addrName);
539-
return addrName;
540-
}
541-
542-
void CNode::MaybeSetAddrName(const std::string& addrNameIn) {
543-
LOCK(cs_addrName);
544-
if (addrName.empty()) {
545-
addrName = addrNameIn;
546-
}
547-
}
548-
549-
CService CNode::GetAddrLocal() const {
533+
CService CNode::GetAddrLocal() const
534+
{
550535
LOCK(cs_addrLocal);
551536
return addrLocal;
552537
}
@@ -587,7 +572,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
587572
X(nLastBlockTime);
588573
X(nTimeConnected);
589574
X(nTimeOffset);
590-
stats.addrName = GetAddrName();
575+
X(m_addr_name);
591576
X(nVersion);
592577
{
593578
LOCK(cs_SubVer);
@@ -2137,7 +2122,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
21372122
if (pnode->addr.IsValid()) {
21382123
mapConnected[pnode->addr] = pnode->IsInboundConn();
21392124
}
2140-
std::string addrName = pnode->GetAddrName();
2125+
std::string addrName{pnode->m_addr_name};
21412126
if (!addrName.empty()) {
21422127
mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->IsInboundConn(), static_cast<const CService&>(pnode->addr));
21432128
}
@@ -2966,6 +2951,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29662951
: nTimeConnected(GetTimeSeconds()),
29672952
addr(addrIn),
29682953
addrBind(addrBindIn),
2954+
m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn},
29692955
m_inbound_onion(inbound_onion),
29702956
nKeyedNetGroup(nKeyedNetGroupIn),
29712957
id(idIn),
@@ -2975,7 +2961,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29752961
{
29762962
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);
29772963
hSocket = hSocketIn;
2978-
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
29792964
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
29802965
m_tx_relay = std::make_unique<TxRelay>();
29812966
}
@@ -2985,7 +2970,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29852970
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0;
29862971

29872972
if (fLogIPs) {
2988-
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", addrName, id);
2973+
LogPrint(BCLog::NET, "Added connection to %s peer=%d\n", m_addr_name, id);
29892974
} else {
29902975
LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
29912976
}
@@ -3014,7 +2999,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
30142999

30153000
TRACE6(net, outbound_message,
30163001
pnode->GetId(),
3017-
pnode->GetAddrName().c_str(),
3002+
pnode->m_addr_name.c_str(),
30183003
pnode->ConnectionTypeAsString().c_str(),
30193004
msg.m_type.c_str(),
30203005
msg.data.size(),

src/net.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class CNodeStats
248248
int64_t nLastBlockTime;
249249
int64_t nTimeConnected;
250250
int64_t nTimeOffset;
251-
std::string addrName;
251+
std::string m_addr_name;
252252
int nVersion;
253253
std::string cleanSubVer;
254254
bool fInbound;
@@ -430,6 +430,7 @@ class CNode
430430
const CAddress addr;
431431
// Bind address of our side of the connection
432432
const CAddress addrBind;
433+
const std::string m_addr_name;
433434
//! Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
434435
const bool m_inbound_onion;
435436
std::atomic<int> nVersion{0};
@@ -658,10 +659,6 @@ class CNode
658659
return nLocalServices;
659660
}
660661

661-
std::string GetAddrName() const;
662-
//! Sets the addrName only if it was not previously set
663-
void MaybeSetAddrName(const std::string& addrNameIn);
664-
665662
std::string ConnectionTypeAsString() const { return ::ConnectionTypeAsString(m_conn_type); }
666663

667664
/** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */
@@ -693,10 +690,7 @@ class CNode
693690
//! service advertisements.
694691
const ServiceFlags nLocalServices;
695692

696-
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
697-
698-
mutable RecursiveMutex cs_addrName;
699-
std::string addrName GUARDED_BY(cs_addrName);
693+
std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
700694

701695
// Our address, as reported by the peer
702696
CService addrLocal GUARDED_BY(cs_addrLocal);

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
40864086

40874087
TRACE6(net, inbound_message,
40884088
pfrom->GetId(),
4089-
pfrom->GetAddrName().c_str(),
4089+
pfrom->m_addr_name.c_str(),
40904090
pfrom->ConnectionTypeAsString().c_str(),
40914091
msg.m_command.c_str(),
40924092
msg.m_recv.size(),

src/qt/peertablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
7272
case NetNodeId:
7373
return (qint64)rec->nodeStats.nodeid;
7474
case Address:
75-
return QString::fromStdString(rec->nodeStats.addrName);
75+
return QString::fromStdString(rec->nodeStats.m_addr_name);
7676
case Direction:
7777
return QString(rec->nodeStats.fInbound ?
7878
//: An Inbound Connection from a Peer.

src/qt/peertablesortproxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
2525
case PeerTableModel::NetNodeId:
2626
return left_stats.nodeid < right_stats.nodeid;
2727
case PeerTableModel::Address:
28-
return left_stats.addrName.compare(right_stats.addrName) < 0;
28+
return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;
2929
case PeerTableModel::Direction:
3030
return left_stats.fInbound > right_stats.fInbound; // default sort Inbound, then Outbound
3131
case PeerTableModel::ConnectionType:

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ void RPCConsole::updateDetailWidget()
11361136
}
11371137
const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
11381138
// update the detail ui with latest node information
1139-
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.addrName) + " ");
1139+
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
11401140
peerAddrDetails += tr("(peer: %1)").arg(QString::number(stats->nodeStats.nodeid));
11411141
if (!stats->nodeStats.addrLocal.empty())
11421142
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
@@ -197,7 +197,7 @@ static RPCHelpMan getpeerinfo()
197197
CNodeStateStats statestats;
198198
bool fStateStats = peerman.GetNodeStateStats(stats.nodeid, statestats);
199199
obj.pushKV("id", stats.nodeid);
200-
obj.pushKV("addr", stats.addrName);
200+
obj.pushKV("addr", stats.m_addr_name);
201201
if (stats.addrBind.IsValid()) {
202202
obj.pushKV("addrbind", stats.addrBind.ToString());
203203
}

src/test/fuzz/net.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ FUZZ_TARGET_INIT(net, initialize_net)
3737
[&] {
3838
node.CloseSocketDisconnect();
3939
},
40-
[&] {
41-
node.MaybeSetAddrName(fuzzed_data_provider.ConsumeRandomLengthString(32));
42-
},
4340
[&] {
4441
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
4542
if (!SanityCheckASMap(asmap)) {
@@ -82,7 +79,6 @@ FUZZ_TARGET_INIT(net, initialize_net)
8279
}
8380

8481
(void)node.GetAddrLocal();
85-
(void)node.GetAddrName();
8682
(void)node.GetId();
8783
(void)node.GetLocalNonce();
8884
(void)node.GetLocalServices();

0 commit comments

Comments
 (0)