Ejemplo n.º 1
0
        public override SingleDownload MakeDownload(IConnection connection)
        {
            NormalSingleDownload singleDownload = new NormalSingleDownload(this, connection);

            downloads.Add(singleDownload);
            return(singleDownload);
        }
Ejemplo n.º 2
0
        public EndGameSingleDownload(EndGameDownloader downloader, IConnection connection, NormalSingleDownload old)
        {
            this.downloader = downloader;
            this.unhave     = downloader.PiecesNumber;
            ran             = new Random();

            if (old == null)
            {
                this.connection = connection;
                this.choked     = true;
                this.interested = false;
                this.have       = new bool[unhave];
                this.measure    = new Measure(downloader.MaxRatePeriod);
                this.last       = DateTime.MinValue;
            }

            else
            {
                this.connection          = old.Connection;
                this.connection.Download = this;
                this.choked     = old.Choked;
                this.have       = old.Have;
                this.interested = old.Interested;
                this.measure    = old.Measure;
                this.last       = old.Last;

                List <ActiveRequest> requests = new List <ActiveRequest>();

                while (downloader.Requests.Count > 0)
                {
                    int k = ran.Next(downloader.Requests.Count);
                    requests.Add(downloader.Requests[k]);
                    downloader.Requests.RemoveAt(k);
                }
                downloader.Requests = requests;

                foreach (bool value in this.have)
                {
                    if (value)
                    {
                        this.unhave--;
                    }
                }

                if (!choked)
                {
                    foreach (ActiveRequest request in downloader.Requests)
                    {
                        if (!old.Requests.Contains(request))
                        {
                            if (have[request.Index])
                            {
                                this.SendRequest(request.Index, request.Begin, request.Length);
                            }
                        }
                    }
                }
            }
        }