diff --git a/src/net.cpp b/src/net.cpp index e2739b6106428..a43bf285fa033 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2965,6 +2965,7 @@ void CConnman::ThreadMessageHandler() { int64_t nLastSendMessagesTimeMasternodes = 0; + FastRandomContext rng; while (!flagInterruptMsgProc) { std::vector vNodesCopy = CopyNodeVector(); @@ -2976,6 +2977,10 @@ void CConnman::ThreadMessageHandler() fSkipSendMessagesForMasternodes = false; nLastSendMessagesTimeMasternodes = GetTimeMillis(); } + // 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) {