@@ -332,7 +332,7 @@ CNode *CConnman::FindNode(const CSubNet &subNet) {
332332CNode *CConnman::FindNode (const std::string &addrName) {
333333 LOCK (cs_vNodes);
334334 for (CNode *pnode : vNodes) {
335- if (pnode->GetAddrName () == addrName) {
335+ if (pnode->m_addr_name == addrName) {
336336 return pnode;
337337 }
338338 }
@@ -424,13 +424,10 @@ CNode *CConnman::ConnectNode(CAddress addrConnect, const char *pszDest,
424424 }
425425 // It is possible that we already have a connection to the IP/port
426426 // pszDest resolved to. In that case, drop the connection that was
427- // just created, and return the existing CNode instead. Also store
428- // the name we used to connect in that CNode, so that future
429- // FindNode() calls to that name catch this early.
427+ // just created.
430428 LOCK (cs_vNodes);
431429 CNode *pnode = FindNode (static_cast <CService>(addrConnect));
432430 if (pnode) {
433- pnode->MaybeSetAddrName (std::string (pszDest));
434431 LogPrintf (" Failed to open new connection, already connected\n " );
435432 return nullptr ;
436433 }
@@ -561,18 +558,6 @@ std::string CNode::ConnectionTypeAsString() const {
561558 assert (false );
562559}
563560
564- std::string CNode::GetAddrName () const {
565- LOCK (cs_addrName);
566- return addrName;
567- }
568-
569- void CNode::MaybeSetAddrName (const std::string &addrNameIn) {
570- LOCK (cs_addrName);
571- if (addrName.empty ()) {
572- addrName = addrNameIn;
573- }
574- }
575-
576561CService CNode::GetAddrLocal () const {
577562 LOCK (cs_addrLocal);
578563 return addrLocal;
@@ -612,7 +597,7 @@ void CNode::copyStats(CNodeStats &stats) {
612597 stats.m_last_block_time = m_last_block_time;
613598 stats.m_connected = m_connected;
614599 stats.nTimeOffset = nTimeOffset;
615- stats.addrName = GetAddrName () ;
600+ stats.m_addr_name = m_addr_name ;
616601 stats.nVersion = nVersion;
617602 {
618603 LOCK (cs_SubVer);
@@ -2506,7 +2491,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() {
25062491 if (pnode->addr .IsValid ()) {
25072492 mapConnected[pnode->addr ] = pnode->IsInboundConn ();
25082493 }
2509- std::string addrName = pnode->GetAddrName () ;
2494+ std::string addrName{ pnode->m_addr_name } ;
25102495 if (!addrName.empty ()) {
25112496 mapConnectedByName[std::move (addrName)] =
25122497 std::make_pair (pnode->IsInboundConn (),
@@ -3456,8 +3441,10 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
34563441 const CAddress &addrBindIn, const std::string &addrNameIn,
34573442 ConnectionType conn_type_in, bool inbound_onion)
34583443 : m_connected(GetTime<std::chrono::seconds>()), addr(addrIn),
3459- addrBind(addrBindIn), m_inbound_onion(inbound_onion),
3460- nKeyedNetGroup(nKeyedNetGroupIn),
3444+ addrBind(addrBindIn), m_addr_name{addrNameIn.empty ()
3445+ ? addr.ToStringIPPort ()
3446+ : addrNameIn},
3447+ m_inbound_onion (inbound_onion), nKeyedNetGroup(nKeyedNetGroupIn),
34613448 m_tx_relay(conn_type_in != ConnectionType::BLOCK_RELAY
34623449 ? std::make_unique<TxRelay>()
34633450 : nullptr),
@@ -3473,15 +3460,15 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn,
34733460 assert (conn_type_in == ConnectionType::INBOUND);
34743461 }
34753462 hSocket = hSocketIn;
3476- addrName = addrNameIn == " " ? addr.ToStringIPPort () : addrNameIn;
34773463
34783464 for (const std::string &msg : getAllNetMessageTypes ()) {
34793465 mapRecvBytesPerMsgCmd[msg] = 0 ;
34803466 }
34813467 mapRecvBytesPerMsgCmd[NET_MESSAGE_COMMAND_OTHER] = 0 ;
34823468
34833469 if (fLogIPs ) {
3484- LogPrint (BCLog::NET, " Added connection to %s peer=%d\n " , addrName, id);
3470+ LogPrint (BCLog::NET, " Added connection to %s peer=%d\n " , m_addr_name,
3471+ id);
34853472 } else {
34863473 LogPrint (BCLog::NET, " Added connection peer=%d\n " , id);
34873474 }
@@ -3509,7 +3496,7 @@ void CConnman::PushMessage(CNode *pnode, CSerializedNetMsg &&msg) {
35093496 CaptureMessage (pnode->addr , msg.m_type , msg.data , /* incoming=*/ false );
35103497 }
35113498
3512- TRACE6 (net, outbound_message, pnode->GetId (), pnode->GetAddrName () .c_str (),
3499+ TRACE6 (net, outbound_message, pnode->GetId (), pnode->m_addr_name .c_str (),
35133500 pnode->ConnectionTypeAsString ().c_str (), msg.m_type .c_str (),
35143501 msg.data .size (), msg.data .data ());
35153502
0 commit comments