Esempio n. 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();
        }
Esempio n. 2
0
 private void PopQueueItems(TransferItem item0)
 {
     while (this.transferQueue.Peek().endTime < item0.beginTime)
     {
         this.transferQueue.Dequeue();
     }
 }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 5
0
 private void PopQueueItems(TransferItem item0)
 {
     while (this.transferQueue.Peek().endTime < item0.beginTime)
     {
         this.transferQueue.Dequeue();
     }
 }