@@ -364,7 +364,7 @@ CNode* CConnman::FindNode(const std::string& addrName, bool fExcludeDisconnectin
364
364
if (fExcludeDisconnecting && pnode->fDisconnect ) {
365
365
continue ;
366
366
}
367
- if (pnode->GetAddrName () == addrName) {
367
+ if (pnode->m_addr_name == addrName) {
368
368
return pnode;
369
369
}
370
370
}
@@ -457,14 +457,10 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
457
457
return nullptr ;
458
458
}
459
459
// 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.
463
461
LOCK (cs_vNodes);
464
462
CNode* pnode = FindNode (static_cast <CService>(addrConnect));
465
- if (pnode)
466
- {
467
- pnode->MaybeSetAddrName (std::string (pszDest));
463
+ if (pnode) {
468
464
LogPrintf (" Failed to open new connection, already connected\n " );
469
465
return nullptr ;
470
466
}
@@ -608,19 +604,8 @@ std::string ConnectionTypeAsString(ConnectionType conn_type)
608
604
assert (false );
609
605
}
610
606
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
+ {
624
609
LOCK (cs_addrLocal);
625
610
return addrLocal;
626
611
}
@@ -660,7 +645,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
660
645
X (nLastBlockTime);
661
646
X (nTimeConnected);
662
647
X (nTimeOffset);
663
- stats. addrName = GetAddrName ( );
648
+ X (m_addr_name );
664
649
X (nVersion);
665
650
{
666
651
LOCK (cs_SubVer);
@@ -2629,7 +2614,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
2629
2614
if (pnode->addr .IsValid ()) {
2630
2615
mapConnected[pnode->addr ] = pnode->IsInboundConn ();
2631
2616
}
2632
- std::string addrName = pnode->GetAddrName () ;
2617
+ std::string addrName{ pnode->m_addr_name } ;
2633
2618
if (!addrName.empty ()) {
2634
2619
mapConnectedByName[std::move (addrName)] = std::make_pair (pnode->IsInboundConn (), static_cast <const CService&>(pnode->addr ));
2635
2620
}
@@ -4018,6 +4003,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
4018
4003
: nTimeConnected(GetTimeSeconds()),
4019
4004
addr(addrIn),
4020
4005
addrBind(addrBindIn),
4006
+ m_addr_name{addrNameIn.empty () ? addr.ToStringIPPort () : addrNameIn},
4021
4007
m_inbound_onion (inbound_onion),
4022
4008
nKeyedNetGroup(nKeyedNetGroupIn),
4023
4009
id(idIn),
@@ -4027,14 +4013,13 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
4027
4013
{
4028
4014
if (inbound_onion) assert (conn_type_in == ConnectionType::INBOUND);
4029
4015
hSocket = hSocketIn;
4030
- addrName = addrNameIn == " " ? addr.ToStringIPPort () : addrNameIn;
4031
4016
4032
4017
for (const std::string &msg : getAllNetMessageTypes ())
4033
4018
mapRecvBytesPerMsgCmd[msg] = 0 ;
4034
4019
mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0 ;
4035
4020
4036
4021
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);
4038
4023
} else {
4039
4024
LogPrint (BCLog::NET, " Added connection peer=%d\n " , id);
4040
4025
}
0 commit comments