private void OnTimer() { if (ConnectedPeers.Count >= MinDesiredConnections) { return; } if (UnconnectedPeers.Count == 0) { NeedMorePeers(MinDesiredConnections - ConnectedPeers.Count); } IPEndPoint[] endpoints = UnconnectedPeers.Take(MinDesiredConnections - ConnectedPeers.Count).ToArray(); ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Except(endpoints)); foreach (IPEndPoint endpoint in endpoints) { ConnectToPeer(endpoint); } }
private void OnTimer() { // Check if the number of desired connections is already enough if (ConnectedPeers.Count >= MinDesiredConnections) { return; } // 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(); ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Except(endpoints)); foreach (IPEndPoint endpoint in endpoints) { ConnectToPeer(endpoint); } }