OctoTorrent.Client.ChokeUnchokeManager.ReallocateSlots C# (CSharp) Method

ReallocateSlots() private method

Reallocates the specified number of upload slots
private ReallocateSlots ( int NumberOfSlots, int NumberOfUnchokedPeers ) : void
NumberOfSlots int
NumberOfUnchokedPeers int
return void
        private void ReallocateSlots(int NumberOfSlots, int NumberOfUnchokedPeers)
        {
            //First determine the maximum number of peers we can unchoke in this review = maximum of:
            //  half the number of upload slots; and
            //  slots not already unchoked
            var maximumUnchokes = NumberOfSlots/2;
            maximumUnchokes = Math.Max(maximumUnchokes, NumberOfSlots - NumberOfUnchokedPeers);

            //Now work through the lists of peers in turn until we have allocated all the slots
            while (NumberOfSlots > 0)
            {
                if (_nascentPeers.MorePeers)
                    ReallocateSlot(ref NumberOfSlots, ref maximumUnchokes, _nascentPeers.GetNextPeer());
                else if (_candidatePeers.MorePeers)
                    ReallocateSlot(ref NumberOfSlots, ref maximumUnchokes, _candidatePeers.GetNextPeer());
                else if (_optimisticUnchokeCandidates.MorePeers)
                    ReallocateSlot(ref NumberOfSlots, ref maximumUnchokes, _optimisticUnchokeCandidates.GetNextPeer());
                else
                    //No more peers left, we're done
                    break;
            }
        }