@@ -1278,15 +1278,15 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
1278
1278
m_msgproc->InitializeNode (pnode);
1279
1279
1280
1280
if (fLogIPs ) {
1281
- LogPrint (BCLog::NET_NETCONN, " connection from %s accepted, sock=%d, peer=%d\n " , addr.ToString (), pnode-> hSocket , pnode->GetId ());
1281
+ LogPrint (BCLog::NET_NETCONN, " connection from %s accepted, sock=%d, peer=%d\n " , addr.ToString (), hSocket, pnode->GetId ());
1282
1282
} else {
1283
- LogPrint (BCLog::NET_NETCONN, " connection accepted, sock=%d, peer=%d\n " , pnode-> hSocket , pnode->GetId ());
1283
+ LogPrint (BCLog::NET_NETCONN, " connection accepted, sock=%d, peer=%d\n " , hSocket, pnode->GetId ());
1284
1284
}
1285
1285
1286
1286
{
1287
1287
LOCK (cs_vNodes);
1288
1288
vNodes.push_back (pnode);
1289
- mapSocketToNode.emplace (pnode-> hSocket , pnode);
1289
+ mapSocketToNode.emplace (hSocket, pnode);
1290
1290
RegisterEvents (pnode);
1291
1291
WakeSelect ();
1292
1292
}
@@ -1443,8 +1443,9 @@ void CConnman::CalculateNumConnectionsChangedStats()
1443
1443
}
1444
1444
mapRecvBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0 ;
1445
1445
mapSentBytesMsgStats[NET_MESSAGE_COMMAND_OTHER] = 0 ;
1446
- LOCK (cs_vNodes);
1447
- for (const CNode* pnode : vNodes) {
1446
+ auto vNodesCopy = CopyNodeVector (CConnman::FullyConnectedOnly);
1447
+ for (auto pnode : vNodesCopy) {
1448
+ LOCK (pnode->cs_vRecv );
1448
1449
for (const mapMsgCmdSize::value_type &i : pnode->mapRecvBytesPerMsgCmd )
1449
1450
mapRecvBytesMsgStats[i.first ] += i.second ;
1450
1451
for (const mapMsgCmdSize::value_type &i : pnode->mapSendBytesPerMsgCmd )
@@ -1466,6 +1467,7 @@ void CConnman::CalculateNumConnectionsChangedStats()
1466
1467
if (pnode->nPingUsecTime > 0 )
1467
1468
statsClient.timing (" peers.ping_us" , pnode->nPingUsecTime , 1 .0f );
1468
1469
}
1470
+ ReleaseNodeVector (vNodesCopy);
1469
1471
for (const std::string &msg : getAllNetMessageTypes ()) {
1470
1472
statsClient.gauge (" bandwidth.message." + msg + " .totalBytesReceived" , mapRecvBytesMsgStats[msg], 1 .0f );
1471
1473
statsClient.gauge (" bandwidth.message." + msg + " .totalBytesSent" , mapSentBytesMsgStats[msg], 1 .0f );
@@ -2787,7 +2789,12 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2787
2789
LogPrint (BCLog::NET_NETCONN, " CConnman::%s -- ConnectNode failed for %s\n " , __func__, getIpStr ());
2788
2790
return ;
2789
2791
}
2790
- LogPrint (BCLog::NET_NETCONN, " CConnman::%s -- succesfully connected to %s, sock=%d, peer=%d\n " , __func__, getIpStr (), pnode->hSocket , pnode->GetId ());
2792
+
2793
+ {
2794
+ LOCK (pnode->cs_hSocket );
2795
+ LogPrint (BCLog::NET_NETCONN, " CConnman::%s -- succesfully connected to %s, sock=%d, peer=%d\n " , __func__, getIpStr (), pnode->hSocket , pnode->GetId ());
2796
+ }
2797
+
2791
2798
if (grantOutbound)
2792
2799
grantOutbound->MoveTo (pnode->grantOutbound );
2793
2800
if (fOneShot )
@@ -2802,7 +2809,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2802
2809
pnode->m_masternode_probe_connection = true ;
2803
2810
2804
2811
{
2805
- LOCK (cs_vNodes);
2812
+ LOCK2 (cs_vNodes, pnode-> cs_hSocket );
2806
2813
mapSocketToNode.emplace (pnode->hSocket , pnode);
2807
2814
}
2808
2815
@@ -3374,7 +3381,10 @@ void CConnman::Stop()
3374
3381
}
3375
3382
vNodes.clear ();
3376
3383
mapSocketToNode.clear ();
3377
- mapReceivableNodes.clear ();
3384
+ {
3385
+ LOCK (cs_vNodes);
3386
+ mapReceivableNodes.clear ();
3387
+ }
3378
3388
{
3379
3389
LOCK (cs_mapNodesWithDataToSend);
3380
3390
mapNodesWithDataToSend.clear ();
0 commit comments