コード例 #1
0
        private void FinishRequest(int hash, int factor)
        {
            if (!this.ongoingTransfer.ContainsKey(hash))
            {
                Logger.Warn("BandwidthEstimator: Not find transfer {0} in ongoingTransfer", hash);
                return;
            }

            // Push new item
            TransferItem item = this.ongoingTransfer[hash];

            this.ongoingTransfer.Remove(hash);

            item.endTime = DateTime.Now;
            int timeInterval = item.endTime.Second - item.beginTime.Second;

            if (timeInterval <= 0)
            {
                timeInterval = 1;
            }

            item.bytesPerSecond /= timeInterval;
            item.bytesPerSecond *= factor;

            this.peerBandwidth[item.peer] = item.bytesPerSecond;

            this.transferQueue.Enqueue(item);

            // Update
            this.PopQueueItems(item);
            this.UpdateTotalBandwidth();
        }
コード例 #2
0
 private void PopQueueItems(TransferItem item0)
 {
     while (this.transferQueue.Peek().endTime < item0.beginTime)
     {
         this.transferQueue.Dequeue();
     }
 }
コード例 #3
0
        public void BeginRequest(Peer peer, int hash, int size)
        {
            if (ongoingTransfer.ContainsKey(hash))
            {
                Logger.Warn("BandwidthEstimator: Transfer {0} already exists ongoingTransfer", hash);
                return;
            }

            TransferItem transfer = new TransferItem();

            transfer.ID             = hash;
            transfer.bytesPerSecond = size;      // hacky
            transfer.beginTime      = DateTime.Now;
            transfer.peer           = peer;

            ongoingTransfer[hash] = transfer;
        }
コード例 #4
0
        public void BeginRequest(Peer peer, int hash, int size)
        {
            if (ongoingTransfer.ContainsKey(hash))
            {
                Logger.Warn("BandwidthEstimator: Transfer {0} already exists ongoingTransfer", hash);
                return;
            }

            TransferItem transfer = new TransferItem();
            transfer.ID = hash;
            transfer.bytesPerSecond = size;      // hacky
            transfer.beginTime = DateTime.Now;
            transfer.peer = peer;

            ongoingTransfer[hash] = transfer;
        }
コード例 #5
0
 private void PopQueueItems(TransferItem item0)
 {
     while (this.transferQueue.Peek().endTime < item0.beginTime)
     {
         this.transferQueue.Dequeue();
     }
 }