async Task <TorrentManager> AddStreamingAsync(MagnetLink magnetLink, Torrent torrent, string saveDirectory, TorrentSettings settings) { var manager = await AddAsync(magnetLink, torrent, saveDirectory, settings); var picker = new PiecePicking.StreamingPieceRequester(); await manager.ChangePickerAsync(picker); manager.StreamProvider = new StreamProvider(manager, picker); return(manager); }
public void PickHighestPriority() { var data = new TorrentData(); var ignoringBitfield = new MutableBitField(data.PieceCount()) .SetAll(false); var requester = new StreamingPieceRequester(); requester.Initialise(data, new[] { ignoringBitfield }); requester.SeekToPosition(data.Files[0], data.PieceLength * 3); var peer = PeerId.CreateNull(ignoringBitfield.Length, true, false, true); requester.AddRequests(peer, Array.Empty <IPeerWithMessaging> ()); Assert.AreEqual(4, peer.AmRequestingPiecesCount); var requests = GetRequests(peer); Assert.AreEqual(4, requests.Count); Assert.IsTrue(requests.All(r => r.PieceIndex == 3)); }