public EndGameSwitcher(StandardPicker standard, EndGamePicker endgame, int blocksPerPiece, TorrentManager torrentManager)
     : base(null)
 {
     this.standard = standard;
     this.endgame = endgame;
     this.blocksPerPiece = blocksPerPiece;
     this.torrentManager = torrentManager;
 }
        public void ChangePicker(PiecePicker picker)
        {
            Check.Picker(picker);

            ClientEngine.MainLoop.QueueWait((MainLoopTask) delegate {
                this.pieceManager.ChangePicker(picker, bitfield, torrent.Files);
            });
        }
Ejemplo n.º 3
0
 public EndGameSwitcher(StandardPicker standard, EndGamePicker endgame, int blocksPerPiece, TorrentManager torrentManager)
     : base(null)
 {
     this.standard       = standard;
     this.endgame        = endgame;
     this.blocksPerPiece = blocksPerPiece;
     this.torrentManager = torrentManager;
 }
Ejemplo n.º 4
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>());
            MessageBundle bundle = picker.PickPiece(peer, new MonoTorrent.Common.BitField(peer.BitField.Length), peers, 1, 0, peer.BitField.Length);

            Assert.IsNull(bundle);
        }
Ejemplo n.º 5
0
        internal void ChangePicker(PiecePicker picker, BitField bitfield)
        {
            originalPicker = picker;
            if (UnhashedPieces.Length != bitfield.Length)
            {
                UnhashedPieces = new BitField(bitfield.Length);
            }

            picker = new IgnoringPicker(bitfield, picker);
            picker = new IgnoringPicker(UnhashedPieces, picker);
            Picker = picker;
        }
Ejemplo n.º 6
0
        internal void ChangePicker(PiecePicker picker, BitField bitfield, TorrentFile[] files)
        {
            if (unhashedPieces.Length != bitfield.Length)
            {
                unhashedPieces = new BitField(bitfield.Length);
            }

            picker = new IgnoringPicker(bitfield, picker);
            picker = new IgnoringPicker(unhashedPieces, picker);
            IEnumerable <Piece> pieces = Picker == null ? new List <Piece>() : Picker.ExportActiveRequests();

            picker.Initialise(bitfield, files, pieces);
            this.picker = picker;
        }
Ejemplo n.º 7
0
        internal void ChangePicker(PiecePicker picker, BitField bitfield, ITorrentData data)
        {
            if (UnhashedPieces.Length != bitfield.Length)
            {
                UnhashedPieces = new BitField(bitfield.Length);
            }

            picker = new IgnoringPicker(bitfield, picker);
            picker = new IgnoringPicker(UnhashedPieces, picker);
            IEnumerable <Piece> pieces = Picker == null ? new List <Piece>() : Picker.ExportActiveRequests();

            picker.Initialise(bitfield, data, pieces);
            Picker = picker;
        }
Ejemplo n.º 8
0
 public virtual void Setup()
 {
     // Yes, this is horrible. Deal with it.
     rig = TestRig.CreateMultiFile();
     peers = new List<PeerId>();
     picker = new IgnoringPicker(rig.Manager.Bitfield, new StandardPicker());
     picker.Initialise(rig.Manager.Bitfield, rig.Manager.Torrent.Files, new List<Piece>());
     peer = new PeerId(new Peer(new string('a', 20), new Uri("tcp://BLAH")), rig.Manager);
     for (int i = 0; i < 20; i++)
     {
         PeerId p = new PeerId(new Peer(new string(i.ToString()[0], 20), new Uri("tcp://" + i)), rig.Manager);
         p.SupportsFastPeer = true;
         peers.Add(p);
     }
 }
Ejemplo n.º 9
0
 public virtual void Setup()
 {
     // Yes, this is horrible. Deal with it.
     rig    = TestRig.CreateMultiFile();
     peers  = new List <PeerId>();
     picker = new IgnoringPicker(rig.Manager.Bitfield, new StandardPicker());
     picker.Initialise(rig.Manager.Bitfield, rig.Manager.Torrent.Files, new List <Piece>());
     peer = new PeerId(new Peer(new string('a', 20), new Uri("tcp://BLAH")), rig.Manager);
     for (int i = 0; i < 20; i++)
     {
         PeerId p = new PeerId(new Peer(new string(i.ToString()[0], 20), new Uri("tcp://" + i)), rig.Manager);
         p.SupportsFastPeer = true;
         peers.Add(p);
     }
 }
Ejemplo n.º 10
0
        public virtual void Setup()
        {
            // Yes, this is horrible. Deal with it.
            rig   = TestRig.CreateMultiFile();
            peers = new List <PeerId>();

            manager = new PieceManager();
            manager.ChangePicker((standardPicker = new StandardPicker()), rig.Manager.Bitfield, rig.Manager.Torrent.Files);
            this.picker = manager.Picker;

            peer = new PeerId(new Peer(new string('a', 20), new Uri("ipv4://BLAH")), rig.Manager);
            for (int i = 0; i < 20; i++)
            {
                PeerId p = new PeerId(new Peer(new string(i.ToString()[0], 20), new Uri("ipv4://" + i)), rig.Manager);
                p.SupportsFastPeer = true;
                peers.Add(p);
            }
        }
Ejemplo n.º 11
0
        internal void ChangePicker(PiecePicker picker, BitField bitfield)
        {
            originalPicker = picker;
            if (PendingHashCheckPieces.Length != bitfield.Length)
            {
                PendingHashCheckPieces = new BitField(bitfield.Length);
            }

            // 'PendingHashCheckPieces' is the list of fully downloaded pieces which
            // are waiting to be hash checked. We should not begin a second download of
            // a piece while waiting to confirm if the original download was successful.
            //
            // 'Manager.UnhashedPieces' represents the pieces from the torrent which
            // have not been hash checked as they are marked as 'DoNotDownload'. If
            // a file is changed to be downloadable, the engine will hashcheck the data
            // first and then remove them from the 'UnhashedPieces' bitfield which will
            // make them downloadable. If they actually passed the hashcheck then they
            // won't actually be requested again.
            picker = new IgnoringPicker(bitfield, picker);
            picker = new IgnoringPicker(PendingHashCheckPieces, picker);
            picker = new IgnoringPicker(Manager.UnhashedPieces, picker);
            Picker = picker;
        }
Ejemplo n.º 12
0
        private bool CheckType <T>(PiecePicker picker, out T obj) where T : PiecePicker
        {
            obj = null;

            if (picker is T)
            {
                obj = (T)picker;
                return(true);
            }

            if (picker is EndGameSwitcher)
            {
                var switcher = (EndGameSwitcher)picker;

                if (switcher.ActivePicker is T)
                {
                    obj = (T)switcher.ActivePicker;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 13
0
 public RarestFirstPicker(PiecePicker picker)
     : base(picker)
 {
     rarest = new Stack <BitField>();
     spares = new Stack <BitField>();
 }
Ejemplo n.º 14
0
 public LoggingPicker(PiecePicker picker)
     : base(picker)
 {
 }
Ejemplo n.º 15
0
 public RarestFirstPicker(PiecePicker picker)
     : base(picker)
 {
     rarest = new Stack<BitField>();
     spares = new Stack<BitField>();
 }
 /// <summary>
 /// Creates a new piece picker with support for prioritization of files. The sliding window will be positioned to the start
 /// of the first file to be downloaded
 /// </summary>
 /// <param name="bitField">The bitfield associated with the torrent</param>
 /// <param name="torrentFiles">The files that are available in this torrent</param>
 /// <param name="highPrioritySetSize">Size of high priority set</param>
 internal SlidingWindowPicker(PiecePicker picker, int highPrioritySetSize)
     : this(picker, highPrioritySetSize, 4)
 {
 }
 /// <summary>
 /// Create a new SlidingWindowPicker with the given set sizes. The sliding window will be positioned to the start
 /// of the first file to be downloaded
 /// </summary>
 /// <param name="bitField">The bitfield associated with the torrent</param>
 /// <param name="torrentFiles">The files that are available in this torrent</param>
 /// <param name="highPrioritySetSize">Size of high priority set</param>
 /// <param name="mediumToHighRatio">Size of medium priority set as a multiple of the high priority set size</param>
 internal SlidingWindowPicker(PiecePicker picker, int highPrioritySetSize, int mediumToHighRatio)
     : base(picker)
 {
     this.highPrioritySetSize = highPrioritySetSize;
     this.ratio = mediumToHighRatio;
 }
Ejemplo n.º 18
0
 public IgnoringPicker(BitField bitfield, PiecePicker picker)
     : base(picker)
 {
     this.bitfield = bitfield;
     this.temp     = new BitField(bitfield.Length);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Create a new SlidingWindowPicker with the given set sizes. The sliding window will be positioned to the start
 /// of the first file to be downloaded
 /// </summary>
 /// <param name="bitField">The bitfield associated with the torrent</param>
 /// <param name="torrentFiles">The files that are available in this torrent</param>
 /// <param name="highPrioritySetSize">Size of high priority set</param>
 /// <param name="mediumToHighRatio">Size of medium priority set as a multiple of the high priority set size</param>
 internal SlidingWindowPicker(PiecePicker picker, int highPrioritySetSize, int mediumToHighRatio)
     : base(picker)
 {
     this.highPrioritySetSize = highPrioritySetSize;
     this.ratio = mediumToHighRatio;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a new piece picker with support for prioritization of files. The sliding window will be positioned to the start
 /// of the first file to be downloaded
 /// </summary>
 /// <param name="bitField">The bitfield associated with the torrent</param>
 /// <param name="torrentFiles">The files that are available in this torrent</param>
 /// <param name="highPrioritySetSize">Size of high priority set</param>
 internal SlidingWindowPicker(PiecePicker picker, int highPrioritySetSize)
     : this(picker, highPrioritySetSize, 4)
 {
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Empty constructor for changing piece pickers
 /// </summary>
 public SlidingWindowPicker(PiecePicker picker)
     : base(picker)
 {
 }
Ejemplo n.º 22
0
 public PriorityPicker(PiecePicker picker)
     : base(picker)
 {
 }
Ejemplo n.º 23
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>());
     MessageBundle bundle = picker.PickPiece(peer, new MonoTorrent.Common.BitField(peer.BitField.Length), peers, 1, 0, peer.BitField.Length);
     Assert.IsNull(bundle);
 }
Ejemplo n.º 24
0
 protected PiecePicker(PiecePicker picker)
 {
     this.picker = picker;
 }
Ejemplo n.º 25
0
 internal void ChangePicker(PiecePicker picker)
 {
     Check.Picker(picker);
     PieceManager.ChangePicker(new IgnoringPicker(UnhashedPieces, picker), Bitfield, Torrent);
 }
Ejemplo n.º 26
0
 internal PieceManager()
 {
     picker         = new NullPicker();
     unhashedPieces = new BitField(0);
 }
 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(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.Null(bundle);
 }
Ejemplo n.º 28
0
 public RandomisedPicker(PiecePicker picker)
     : base(picker)
 {
 }
Ejemplo n.º 29
0
 internal PieceManager(PiecePicker picker, BitField bitfield, TorrentFile[] files)
 {
     unhashedPieces = new BitField(bitfield.Length);
     ChangePicker(picker, bitfield, files);
 }
        private int ratio = 4; // ratio from medium priority to high priority set size

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Empty constructor for changing piece pickers
        /// </summary>
        public SlidingWindowPicker(PiecePicker picker)
            : base(picker)
        {
        }
Ejemplo n.º 31
0
 internal PieceManager()
 {
     picker = new NullPicker();
     unhashedPieces = new BitField(0);
 }
Ejemplo n.º 32
0
 public IgnoringPicker(BitField bitfield, PiecePicker picker)
     : base(picker)
 {
     this.bitfield = bitfield;
     this.temp = new BitField(bitfield.Length);
 }
Ejemplo n.º 33
0
        internal void ChangePicker(PiecePicker picker)
        {
            Check.Picker(picker);

            PieceManager.ChangePicker(picker, Bitfield, Torrent.Files);
        }
Ejemplo n.º 34
0
 protected PiecePicker(PiecePicker picker)
 {
     this.picker = picker;
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Changes the active piece picker. This can be called when the manager is running, or when it is stopped.
        /// </summary>
        /// <param name="picker">The new picker to use.</param>
        /// <returns></returns>
        public async Task ChangePickerAsync(PiecePicker picker)
        {
            await ClientEngine.MainLoop;

            ChangePicker(picker);
        }
Ejemplo n.º 36
0
 public void ChangePicker(PiecePicker piecePicker)
 {
     Torrent.ChangePicker(piecePicker);
     PiecePicker = piecePicker;
 }
 public RandomisedPicker(PiecePicker picker)
     : base(picker)
 {
 }
Ejemplo n.º 38
0
        internal void ChangePicker(PiecePicker picker, BitField bitfield, TorrentFile[] files)
        {
            if (unhashedPieces.Length != bitfield.Length)
                unhashedPieces = new BitField(bitfield.Length);

            picker = new IgnoringPicker(bitfield, picker);
            picker = new IgnoringPicker(unhashedPieces, picker);
            IEnumerable<Piece> pieces = Picker == null ? new List<Piece>() : Picker.ExportActiveRequests();
            picker.Initialise(bitfield, files, pieces);
            this.picker = picker;
        }
Ejemplo n.º 39
0
 internal void ChangePicker(PiecePicker picker, BitField bitfield, TorrentFile[] files)
 {
     //          MonoTorrent.Client.PiecePicker p = new StandardPicker();
     //          p = new RandomisedPicker(p);
     //          p = new RarestFirstPicker(p);
     //          p = new PriorityPicker(p);
     picker = new IgnoringPicker(bitfield, picker);
     picker = new IgnoringPicker(unhashedPieces, picker);
     IEnumerable<Piece> pieces = Picker == null ? new List<Piece>() : Picker.ExportActiveRequests();
     picker.Initialise(bitfield, files, pieces);
     this.picker = picker;
 }