Skip to content

Commit

Permalink
Ensure non predictable peers (#1739)
Browse files Browse the repository at this point in the history
* Plugins from List to array

* Move false to init

* Fix UT

* Refactor
  • Loading branch information
shargon authored Jul 20, 2020
1 parent d542ac3 commit ae38366
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ private void OnTimer()
// If there aren't available UnconnectedPeers, it triggers an abstract implementation of NeedMorePeers
if (UnconnectedPeers.Count == 0)
NeedMorePeers(MinDesiredConnections - ConnectedPeers.Count);
IPEndPoint[] endpoints = UnconnectedPeers.Take(MinDesiredConnections - ConnectedPeers.Count).ToArray();

Random rand = new Random();
IPEndPoint[] endpoints = UnconnectedPeers.OrderBy(u => rand.Next()).Take(MinDesiredConnections - ConnectedPeers.Count).ToArray();
ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Except(endpoints));
foreach (IPEndPoint endpoint in endpoints)
{
Expand Down

0 comments on commit ae38366

Please sign in to comment.