Skip to content

Commit

Permalink
Randomize message processing peer order
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jun 2, 2021
1 parent 2aab8a6 commit 79c02c8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai

void CConnman::ThreadMessageHandler()
{
FastRandomContext rng;
while (!flagInterruptMsgProc)
{
std::vector<CNode*> vNodesCopy;
Expand All @@ -2186,6 +2187,11 @@ void CConnman::ThreadMessageHandler()

bool fMoreWork = false;

// Randomize the order in which we process messages from/to our peers.
// This prevents attacks in which an attacker exploits having multiple
// consecutive connections in the vNodes list.
Shuffle(vNodesCopy.begin(), vNodesCopy.end(), rng);

for (CNode* pnode : vNodesCopy)
{
if (pnode->fDisconnect)
Expand Down

0 comments on commit 79c02c8

Please sign in to comment.