@@ -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 (),
0 commit comments