public static BlockInfo?PickPiece(this IPiecePicker picker, IPeer peer, BitField available, IReadOnlyList <IPeer> otherPeers) { Span <BlockInfo> buffer = stackalloc BlockInfo[1]; var result = picker.PickPiece(peer, available, otherPeers, 0, available.Length - 1, buffer); return(result == 1 ? (BlockInfo?)buffer[0] : null); }
public static BlockInfo?PickPiece(this IPiecePicker picker, IPeer peer, BitField available) { Span <BlockInfo> buffer = stackalloc BlockInfo[1]; var picked = picker.PickPiece(peer, available, Array.Empty <IPeer> (), 0, available.Length - 1, buffer); return(picked == 1 ? (BlockInfo?)buffer[0] : null); }
public DownloadPiecesStage(IApplicationProtocol <PeerConnection> application, IMainLoop mainLoop, IPiecePicker piecePicker) { this.application = application; this.mainLoop = mainLoop; this.piecePicker = piecePicker; }
public static IPiecePicker Wrap(IPiecePicker picker, IEnumerable <BitField> ignoringBitfields) { var result = picker; foreach (var bf in ignoringBitfields) { result = new IgnoringPicker(bf, result); } return(result); }
public void DoesntHaveSuggestedPiece() { peer.IsChoking = false; peer.SupportsFastPeer = true; peer.SuggestedPieces.AddRange(new[] { 1, 2, 3, 4 }); peer.BitField.SetAll(true); picker = new StandardPicker(); picker.Initialise(torrentData); var bundle = picker.PickPiece(peer, new BitField(peer.BitField.Length), peers, 1, 0, peer.BitField.Length - 1); Assert.IsNull(bundle); }
public NormalDownloader(IStorageWrapper storageWrapper, IPiecePicker piecePicker, int backLog, double maxRatePeriod, int piecesNumber, Measure downloadMeasure, double snubTime, DataDelegate measureFunction) { this.storageWrapper = storageWrapper; this.piecePicker = piecePicker; this.backLog = backLog; this.maxRatePeriod = maxRatePeriod; this.downloadMeasure = downloadMeasure; this.piecesNumber = piecesNumber; this.snubTime = snubTime; this.measureFunction = measureFunction; this.downloads = new List <SingleDownload>(); }
public void Initialise(ITorrentData torrentData, IReadOnlyList <BitField> ignoringBitfields) { TorrentData = torrentData; IPiecePicker picker = new StandardPicker(); picker = new RandomisedPicker(picker); picker = new RarestFirstPicker(picker); picker = new PriorityPicker(picker); Picker = IgnoringPicker.Wrap(picker, ignoringBitfields); Picker.Initialise(torrentData); }
public void DoesntHaveSuggestedPiece() { Span <BlockInfo> buffer = stackalloc BlockInfo[1]; peer.IsChoking = false; peer.SupportsFastPeer = true; peer.SuggestedPieces.AddRange(new[] { 1, 2, 3, 4 }); peer.BitField.SetAll(true); picker = new StandardPicker(); picker.Initialise(torrentData); var requested = picker.PickPiece(peer, new BitField(peer.BitField.Length), peers, 0, peer.BitField.Length - 1, buffer); Assert.AreEqual(0, requested); }
public void Initialise(ITorrentData torrentData, IReadOnlyList <BitField> ignoringBitfields) { IgnorableBitfields = ignoringBitfields; TorrentData = torrentData; Temp = new MutableBitField(TorrentData.PieceCount()); IPiecePicker picker = new StandardPicker(); picker = new RandomisedPicker(picker); picker = new RarestFirstPicker(picker); Picker = new PriorityPicker(picker); Picker.Initialise(torrentData); }
/// <summary> /// 发送请求信息的队列 /// </summary> /// <param name="pp">PiecePicker片断选择类</param> /// <returns>返回发送请求信息的队列</returns> private List <int> Pull(IPiecePicker pp) { request = new List <int>(); while (true) { //调用PiecePicker选择片断 int selectIndex = pp.Next(Want); //当selectIndex == -1时,表示已经没有排片断可供选择,所以结束选择 if (selectIndex == -1) { break; } //将所选择的片断索引号加入到request中 request.Add(selectIndex); } return(request); }
public void Setup() { int pieceCount = 40; int pieceLength = 256 * 1024; bitfield = new BitField(pieceCount); torrentData = new TestTorrentData { Files = TorrentFileInfo.Create(pieceLength, ("File", pieceLength * pieceCount, "Full/Path/File")), PieceLength = pieceLength, Size = pieceLength * pieceCount }; peers = new List <PeerId> (); picker = new StandardPicker(); picker.Initialise(torrentData); peer = PeerId.CreateNull(pieceCount); for (int i = 0; i < 20; i++) { PeerId p = PeerId.CreateNull(pieceCount); p.SupportsFastPeer = true; peers.Add(p); } }
protected PiecePickerFilter(IPiecePicker picker) => Next = picker;
public static BlockInfo?ContinueAnyExistingRequest(this IPiecePicker picker, IPeer peer, int startIndex, int endIndex) => picker.ContinueAnyExistingRequest(peer, startIndex, endIndex, 1);
public static IList <BlockInfo> CancelRequests(this IPiecePicker picker, IPeer peer) { return(picker.CancelRequests(peer, 0, peer.BitField.Length - 1)); }
public RarestFirstPicker(IPiecePicker picker) : base(picker) { rarest = new Stack <MutableBitField> (); spares = new Stack <MutableBitField> (); }
public PriorityPicker(IPiecePicker picker) : base(picker) { AllSamePriority = file => file.Priority == files[0].Priority; }
public IgnoringPicker(BitField bitfield, IPiecePicker picker) : base(picker) { Bitfield = bitfield; Temp = new BitField(bitfield.Length); }
public DownloadPiecesStage(BitTorrentApplicationProtocol applicationProtocol, IMainLoop mainLoop, IPiecePicker piecePicker) { ApplicationProtocol = applicationProtocol; _mainLoop = mainLoop; _piecePicker = piecePicker; }
public static BlockInfo?PickPiece(this IPiecePicker picker, IPeer peer, BitField available) { var result = picker.PickPiece(peer, available, Array.Empty <IPeer> (), 1, 0, available.Length - 1); return(result?.Single()); }
public static IList <BlockInfo> PickPiece(this IPiecePicker picker, IPeer peer, BitField available, IReadOnlyList <IPeer> otherPeers, int count) { return(picker.PickPiece(peer, available, otherPeers, count, 0, available.Length - 1)); }
public static BlockInfo?PickPiece(this IPiecePicker picker, IPeer peer, BitField available, IReadOnlyList <IPeer> otherPeers) { var result = picker.PickPiece(peer, available, otherPeers, 1, 0, available.Length - 1); return(result?.Single()); }
public static int PickPiece(this IPiecePicker picker, IPeer peer, BitField available, IReadOnlyList <IPeer> otherPeers, Span <BlockInfo> requests) { return(picker.PickPiece(peer, available, otherPeers, 0, available.Length - 1, requests)); }
public RandomisedPicker(IPiecePicker picker) : base(picker) { Random = new Random(); }