示例#1
0
        public void Advertise7()
        {
            PeerId other = rig.CreatePeer(true);

            // Check that peers which don't share only get a small number of pieces to share
            rig.Manager.Settings.UploadSlots = 1;
            unchoker.PeerDisconnected(peer);
            List <PeerId> peers = new List <PeerId>(new PeerId[] { peer, rig.CreatePeer(true) });

            peers.ForEach(unchoker.PeerConnected);
            unchoker.UnchokeReview();

            peers.ForEach(delegate(PeerId id) { id.IsInterested = true; });
            unchoker.UnchokeReview();

            Assert.AreEqual(unchoker.MaxAdvertised + 1, peers[0].QueueLength);
            while (peers[0].QueueLength > 1)
            {
                unchoker.ReceivedHave(peers[0], ((HaveMessage)peers[0].Dequeue()).PieceIndex);
            }
            unchoker.UnchokeReview();
            Assert.IsInstanceOfType(typeof(UnchokeMessage), peers[0].Dequeue());
            Assert.IsInstanceOfType(typeof(ChokeMessage), peers[0].Dequeue());

            Assert.AreEqual(unchoker.MaxAdvertised + 1, peers[1].QueueLength);
            while (peers[1].QueueLength > 1)
            {
                unchoker.ReceivedHave(other, ((HaveMessage)peers[1].Dequeue()).PieceIndex);
            }
            unchoker.UnchokeReview();
            Assert.IsInstanceOfType(typeof(UnchokeMessage), peers[1].Dequeue());
            Assert.IsInstanceOfType(typeof(ChokeMessage), peers[1].Dequeue());

            // He didn't share any, he should get 1 piece.
            Assert.AreEqual(1 + 1, peers[0].QueueLength);
            while (peers[0].QueueLength > 1)
            {
                unchoker.ReceivedHave(peers[0], ((HaveMessage)peers[0].Dequeue()).PieceIndex);
            }
            unchoker.UnchokeReview();
            Assert.IsInstanceOfType(typeof(UnchokeMessage), peers[0].Dequeue());
            Assert.IsInstanceOfType(typeof(ChokeMessage), peers[0].Dequeue());

            // He shared them all, he should get max allowance
            Assert.AreEqual(unchoker.MaxAdvertised + 1, peers[1].QueueLength);
            while (peers[1].QueueLength > 1)
            {
                unchoker.ReceivedHave(other, ((HaveMessage)peers[1].Dequeue()).PieceIndex);
            }
            unchoker.UnchokeReview();
            Assert.IsInstanceOfType(typeof(UnchokeMessage), peers[1].Dequeue());
            Assert.IsInstanceOfType(typeof(ChokeMessage), peers[1].Dequeue());
        }
示例#2
0
 public override void HandlePeerDisconnected(PeerId id)
 {
     unchoker.PeerDisconnected(id);
     base.HandlePeerDisconnected(id);
 }