@@ -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 }
0 commit comments