diff options
author | Pieter Wuille <pieter@wuille.net> | 2021-06-02 13:54:41 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2021-06-02 13:55:14 -0700 |
commit | 79c02c88b347f1408a2db307db2654917f9b0bcc (patch) | |
tree | 09faae30f4645f5e362019b33bf40e8e82051ebf /src | |
parent | 2aab8a6dd0b555d0550a050064623fa7c812364b (diff) | |
download | bitcoin-79c02c88b347f1408a2db307db2654917f9b0bcc.tar.xz |
Randomize message processing peer order
Diffstat (limited to 'src')
-rw-r--r-- | src/net.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 6f9f17ed4e..9c6cb379d2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2173,6 +2173,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai void CConnman::ThreadMessageHandler() { + FastRandomContext rng; while (!flagInterruptMsgProc) { std::vector<CNode*> vNodesCopy; @@ -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) |