public void ChokePeer_RequestingPiece() { var unchokeable = new Unchokeable( PeerId.CreateInterested(10), PeerId.CreateInterested(10), PeerId.CreateInterested(10)) { UploadSlots = 1 }; unchokeable.Peers.ForEach(p => { p.AmChoking = false; unchokeable.UploadingTo++; // SupportsFastPeer is set to false so this should be ignored. // This will always be empty during normal downloading. p.AmAllowedFastPieces.Add(1); p.SupportsFastPeer = false; p.Enqueue(new PieceMessage(1, 0, Piece.BlockSize)); }); new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.AreEqual(1, unchokeable.UploadingTo); foreach (var peer in unchokeable.Peers) { if (peer.AmChoking) { Assert.IsInstanceOf <ChokeMessage> (peer.Dequeue()); } else { Assert.IsInstanceOf <PieceMessage> (peer.Dequeue()); } Assert.AreEqual(0, peer.QueueLength); } }
public void ChokePeer_FastExtensions_RequestingPiece() { var unchokeable = new Unchokeable( PeerId.CreateInterested(10), PeerId.CreateInterested(10), PeerId.CreateInterested(10)) { UploadSlots = 1 }; unchokeable.Peers.ForEach(p => { p.AmChoking = false; unchokeable.UploadingTo++; p.SupportsFastPeer = true; p.Enqueue(new PieceMessage(1, 0, Piece.BlockSize)); }); new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.AreEqual(1, unchokeable.UploadingTo); foreach (var peer in unchokeable.Peers) { if (peer.AmChoking) { Assert.IsInstanceOf <ChokeMessage> (peer.Dequeue()); Assert.IsInstanceOf <RejectRequestMessage> (peer.Dequeue()); } else { Assert.IsInstanceOf <PieceMessage> (peer.Dequeue()); } Assert.AreEqual(0, peer.QueueLength); } }
public void UnchokeOneWithUnlimitedSlots() { var unchokeable = new Unchokeable(PeerId.CreateInterested(10)) { UploadSlots = 0 }; Assert.IsTrue(unchokeable.Peers[0].AmChoking); new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.IsFalse(unchokeable.Peers[0].AmChoking); Assert.AreEqual(1, unchokeable.UploadingTo); }
public void UnchokeThreeWithOneSlot() { var unchokeable = new Unchokeable( PeerId.CreateInterested(10), PeerId.CreateInterested(10), PeerId.CreateInterested(10)) { UploadSlots = 1 }; new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.AreEqual(1, unchokeable.UploadingTo); }
public void ChokeTwoPeers() { var unchokeable = new Unchokeable( PeerId.CreateInterested(10), PeerId.CreateInterested(10), PeerId.CreateInterested(10)) { UploadSlots = 1 }; unchokeable.Peers.ForEach(p => { p.AmChoking = false; unchokeable.UploadingTo++; }); new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.AreEqual(1, unchokeable.UploadingTo); foreach (var peer in unchokeable.Peers.Where(t => t.AmChoking)) { Assert.IsInstanceOf <ChokeMessage> (peer.Dequeue()); Assert.AreEqual(0, peer.QueueLength); } }