public void ChokePeer_NotInterested_ThenInterested() { var unchokeable = new Unchokeable( PeerId.Create(10), PeerId.Create(10), PeerId.Create(10)) { UploadSlots = 1 }; unchokeable.Peers.ForEach(p => { p.IsInterested = false; p.AmChoking = true; }); var unchoker = new ChokeUnchokeManager(unchokeable); unchoker.UnchokeReview(); Assert.AreEqual(0, unchokeable.UploadingTo); unchokeable.Peers.ForEach(p => { p.IsInterested = true; }); unchoker.UnchokeReview(); Assert.AreEqual(1, unchokeable.UploadingTo); // We preferred the one who has been choked the longest Assert.IsFalse(unchokeable.Peers[0].AmChoking); }
public void ChokePeer_NotInterested() { var unchokeable = new Unchokeable( PeerId.Create(10), PeerId.Create(10), PeerId.Create(10)) { UploadSlots = 1 }; // This is a peer who we unchoked because they wanted data // but now they do not want any more data from us. unchokeable.Peers.ForEach(p => { p.IsInterested = false; p.AmChoking = false; unchokeable.UploadingTo++; }); new ChokeUnchokeManager(unchokeable).UnchokeReview(); Assert.AreEqual(0, unchokeable.UploadingTo); foreach (var peer in unchokeable.Peers) { Assert.IsTrue(peer.AmChoking); Assert.IsInstanceOf <ChokeMessage> (peer.Dequeue()); Assert.AreEqual(0, peer.QueueLength); } }