Ejemplo n.º 1
0
        private void InitializeTyrant()
        {
            HaveMessagesReceived = 0;
            TyrantStartTime.Restart();

            RateLimiter        = new RateLimiter();
            UploadRateForRecip = MARKET_RATE;
            LastRateReductionTime.Restart();
            lastMeasuredDownloadRate = 0;

            maxObservedDownloadSpeed = 0;
            RoundsChoked             = 0;
            RoundsUnchoked           = 0;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Should be called by ChokeUnchokeManager.ExecuteReview
        /// Logic taken from BitTyrant implementation
        /// </summary>
        internal void UpdateTyrantStats()
        {
            // if we're still being choked, set the time of our last choking
            if (IsChoking)
            {
                RoundsChoked++;

                LastChokedTime.Restart();
            }
            else
            {
                this.RoundsUnchoked++;

                if (AmInterested)
                {
                    //if we are interested and unchoked, update last measured download rate, unless it is 0
                    if (this.Monitor.DownloadSpeed > 0)
                    {
                        this.lastMeasuredDownloadRate = this.Monitor.DownloadSpeed;

                        this.maxObservedDownloadSpeed = Math.Max(this.lastMeasuredDownloadRate, this.maxObservedDownloadSpeed);
                    }
                }
            }

            // last rate wasn't sufficient to achieve reciprocation
            if (!AmChoking && IsChoking && IsInterested) // only increase upload rate if he's interested, otherwise he won't request any pieces
            {
                this.UploadRateForRecip = (this.UploadRateForRecip * 12) / 10;
            }

            // we've been unchoked by this guy for a while....
            if (!IsChoking && !AmChoking &&
                LastChokedTime.Elapsed.TotalSeconds > 30 &&
                LastRateReductionTime.Elapsed.TotalSeconds > 30)                  // only do rate reduction every 30s
            {
                this.UploadRateForRecip = (this.UploadRateForRecip * 9) / 10;
                LastRateReductionTime.Restart();
            }
        }