@@ -1513,18 +1513,12 @@ void CConnman::SocketHandler()
1513
1513
}
1514
1514
}
1515
1515
1516
+ const NodesSnapshot snap{*this , /* shuffle=*/ false };
1517
+
1516
1518
//
1517
1519
// Service each socket
1518
1520
//
1519
- std::vector<CNode*> vNodesCopy;
1520
- {
1521
- LOCK (cs_vNodes);
1522
- vNodesCopy = vNodes;
1523
- for (CNode* pnode : vNodesCopy)
1524
- pnode->AddRef ();
1525
- }
1526
- for (CNode* pnode : vNodesCopy)
1527
- {
1521
+ for (CNode* pnode : snap.Nodes ()) {
1528
1522
if (interruptNet)
1529
1523
return ;
1530
1524
@@ -1606,11 +1600,6 @@ void CConnman::SocketHandler()
1606
1600
1607
1601
if (InactivityCheck (*pnode)) pnode->fDisconnect = true ;
1608
1602
}
1609
- {
1610
- LOCK (cs_vNodes);
1611
- for (CNode* pnode : vNodesCopy)
1612
- pnode->Release ();
1613
- }
1614
1603
}
1615
1604
1616
1605
void CConnman::ThreadSocketHandler ()
@@ -2224,49 +2213,34 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2224
2213
void CConnman::ThreadMessageHandler ()
2225
2214
{
2226
2215
SetSyscallSandboxPolicy (SyscallSandboxPolicy::MESSAGE_HANDLER);
2227
- FastRandomContext rng;
2228
2216
while (!flagInterruptMsgProc)
2229
2217
{
2230
- std::vector<CNode*> vNodesCopy;
2231
- {
2232
- LOCK (cs_vNodes);
2233
- vNodesCopy = vNodes;
2234
- for (CNode* pnode : vNodesCopy) {
2235
- pnode->AddRef ();
2236
- }
2237
- }
2238
-
2239
2218
bool fMoreWork = false ;
2240
2219
2241
- // Randomize the order in which we process messages from/to our peers.
2242
- // This prevents attacks in which an attacker exploits having multiple
2243
- // consecutive connections in the vNodes list.
2244
- Shuffle (vNodesCopy.begin (), vNodesCopy.end (), rng);
2245
-
2246
- for (CNode* pnode : vNodesCopy)
2247
2220
{
2248
- if (pnode->fDisconnect )
2249
- continue ;
2221
+ // Randomize the order in which we process messages from/to our peers.
2222
+ // This prevents attacks in which an attacker exploits having multiple
2223
+ // consecutive connections in the vNodes list.
2224
+ const NodesSnapshot snap{*this , /* shuffle=*/ true };
2250
2225
2251
- // Receive messages
2252
- bool fMoreNodeWork = m_msgproc->ProcessMessages (pnode, flagInterruptMsgProc);
2253
- fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend );
2254
- if (flagInterruptMsgProc)
2255
- return ;
2256
- // Send messages
2257
- {
2258
- LOCK (pnode->cs_sendProcessing );
2259
- m_msgproc->SendMessages (pnode);
2260
- }
2226
+ for (CNode* pnode : snap.Nodes ()) {
2227
+ if (pnode->fDisconnect )
2228
+ continue ;
2261
2229
2262
- if (flagInterruptMsgProc)
2263
- return ;
2264
- }
2230
+ // Receive messages
2231
+ bool fMoreNodeWork = m_msgproc->ProcessMessages (pnode, flagInterruptMsgProc);
2232
+ fMoreWork |= (fMoreNodeWork && !pnode->fPauseSend );
2233
+ if (flagInterruptMsgProc)
2234
+ return ;
2235
+ // Send messages
2236
+ {
2237
+ LOCK (pnode->cs_sendProcessing );
2238
+ m_msgproc->SendMessages (pnode);
2239
+ }
2265
2240
2266
- {
2267
- LOCK (cs_vNodes);
2268
- for (CNode* pnode : vNodesCopy)
2269
- pnode->Release ();
2241
+ if (flagInterruptMsgProc)
2242
+ return ;
2243
+ }
2270
2244
}
2271
2245
2272
2246
WAIT_LOCK (mutexMsgProc, lock);
0 commit comments