Skip to content

Commit 79c02c8

Browse files
committed
Randomize message processing peer order
1 parent 2aab8a6 commit 79c02c8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/net.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
21732173

21742174
void CConnman::ThreadMessageHandler()
21752175
{
2176+
FastRandomContext rng;
21762177
while (!flagInterruptMsgProc)
21772178
{
21782179
std::vector<CNode*> vNodesCopy;
@@ -2186,6 +2187,11 @@ void CConnman::ThreadMessageHandler()
21862187

21872188
bool fMoreWork = false;
21882189

2190+
// Randomize the order in which we process messages from/to our peers.
2191+
// This prevents attacks in which an attacker exploits having multiple
2192+
// consecutive connections in the vNodes list.
2193+
Shuffle(vNodesCopy.begin(), vNodesCopy.end(), rng);
2194+
21892195
for (CNode* pnode : vNodesCopy)
21902196
{
21912197
if (pnode->fDisconnect)

0 commit comments

Comments
 (0)