Exemplo n.º 1
0
        public override void Initialise(BitField bitfield, ITorrentData torrentData, IEnumerable <Piece> requests)
        {
            this.bitfield        = bitfield;
            this.endgameSelector = new BitField(bitfield.Length);
            this.torrentData     = torrentData;
            inEndgame            = false;

            // Always initialize both pickers, but we should only give the active requests to the Standard picker.
            // We should never *default* to endgame mode, we should always start in regular mode and enter endgame
            // mode after we fail to pick a piece.
            standard.Initialise(bitfield, torrentData, requests);
            endgame.Initialise(bitfield, torrentData, Enumerable.Empty <Piece> ());
        }
Exemplo n.º 2
0
        public void DoesntHaveSuggestedPiece()
        {
            peer.IsChoking        = false;
            peer.SupportsFastPeer = true;
            peer.SuggestedPieces.AddRange(new int[] { 1, 2, 3, 4 });
            peer.BitField.SetAll(true);
            picker = new StandardPicker();
            picker.Initialise(rig.Manager.Bitfield, rig.Torrent.Files, new List <Piece>());
            var bundle = picker.PickPiece(peer, new BitField(peer.BitField.Length), peers, 1, 0, peer.BitField.Length);

            Assert.IsNull(bundle);
        }
        public void DoesntHaveFastPiece()
        {
            peer.IsChoking        = true;
            peer.SupportsFastPeer = true;
            peer.IsAllowedFastPieces.AddRange(new[] { 1, 2, 3, 4 });
            peer.BitField.SetAll(true);
            picker = new StandardPicker();
            picker.Initialise(bitfield, torrentData, new List <Piece> ());
            var bundle = picker.PickPiece(peer, new BitField(peer.BitField.Length), peers, 1, 0, peer.BitField.Length);

            Assert.IsNull(bundle);
        }
Exemplo n.º 4
0
        private bool TryEnableEndgame()
        {
            if (inEndgame)
            {
                return(false);
            }

            // We need to activate endgame mode when there are less than 20 requestable blocks
            // available. We OR the bitfields of all the files which are downloadable and then
            // NAND it with the torrents bitfield to get a list of pieces which remain to be downloaded.

            // Essentially we get a list of all the pieces we're allowed download, then get a list of
            // the pieces which we still need to get and AND them together.

            // Create the bitfield of pieces which are downloadable
            endgameSelector.SetAll(false);
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Priority != Priority.DoNotDownload)
                {
                    endgameSelector.Or(files[i].GetSelector(bitfield.Length));
                }
            }

            // NAND it with the pieces we already have (i.e. AND it with the pieces we still need to receive)
            endgameSelector.NAnd(bitfield);

            // If the total number of blocks remaining is less than Threshold, activate Endgame mode.
            int count = standard.CurrentReceivedCount();

            inEndgame = Math.Max(blocksPerPiece, (endgameSelector.TrueCount * blocksPerPiece)) - count < Threshold;
            if (inEndgame)
            {
                endgame.Initialise(bitfield, files, standard.ExportActiveRequests());
                standard.Reset();
                // Set torrent's IsInEndGame flag
                torrentManager.isInEndGame = true;
            }
            return(inEndgame);
        }
        public void Setup()
        {
            int pieceCount  = 40;
            int pieceLength = 256 * 1024;

            bitfield    = new BitField(pieceCount);
            torrentData = new TestTorrentData {
                Files       = new[] { new TorrentFile("File", pieceLength * pieceCount) },
                PieceLength = pieceLength,
                Size        = pieceLength * pieceCount
            };
            peers = new List <PeerId> ();

            picker = new StandardPicker();
            picker.Initialise(bitfield, torrentData, Enumerable.Empty <Piece> ());

            peer = PeerId.CreateNull(pieceCount);
            for (int i = 0; i < 20; i++)
            {
                PeerId p = PeerId.CreateNull(pieceCount);
                p.SupportsFastPeer = true;
                peers.Add(p);
            }
        }
Exemplo n.º 6
0
 public virtual void Initialise(BitField bitfield, TorrentFile[] files, IEnumerable <Piece> requests)
 {
     CheckOverriden();
     picker.Initialise(bitfield, files, requests);
 }
Exemplo n.º 7
0
 public virtual void Initialise(BitField bitfield, ITorrentData torrentData, IEnumerable <Piece> requests)
 {
     CheckOverriden();
     picker.Initialise(bitfield, torrentData, requests);
 }