public void Setup()
 {
     rig.Manager.UploadingTo          = 0;
     rig.Manager.Settings.UploadSlots = 4;
     peer     = rig.CreatePeer(true);
     unchoker = new InitialSeedUnchoker(rig.Manager);
     unchoker.PeerConnected(peer);
 }
        public async Task Setup()
        {
            rig.Manager.UploadingTo = 0;
            await rig.Manager.UpdateSettingsAsync(new TorrentSettingsBuilder (rig.Manager.Settings) { UploadSlots = 4 }.ToSettings());

            peer     = rig.CreatePeer(true);
            unchoker = new InitialSeedUnchoker(rig.Manager);
            unchoker.PeerConnected(peer);
        }
        public async Task AddPeers_Dht()
        {
            var dht = (ManualDhtEngine)rig.Engine.DhtEngine;

            var tcs     = new TaskCompletionSource <DhtPeersAdded> ();
            var manager = rig.Engine.Torrents[0];

            manager.PeersFound += (o, e) => {
                if (e is DhtPeersAdded args)
                {
                    tcs.TrySetResult(args);
                }
            };

            dht.RaisePeersFound(manager.InfoHash, new[] { rig.CreatePeer(false).Peer });
            var result = await tcs.Task.WithTimeout(TimeSpan.FromSeconds(5));

            Assert.AreEqual(1, result.NewPeers, "#2");
            Assert.AreEqual(0, result.ExistingPeers, "#3");
            Assert.AreEqual(1, manager.Peers.AvailablePeers.Count, "#4");
        }
        public void Advertise5()
        {
            List <PeerId> peers = new List <PeerId>(new PeerId[] { rig.CreatePeer(true), rig.CreatePeer(true), rig.CreatePeer(true) });

            peers.ForEach(unchoker.PeerConnected);
            peers.Add(this.peer);

            peers[0].BitField.SetTrue(0).SetTrue(7).SetTrue(14);
            peers[1].BitField.SetTrue(2).SetTrue(6).SetTrue(10);
            peers[2].BitField.SetTrue(5).SetTrue(9).SetTrue(12);

            unchoker.UnchokeReview();

            foreach (PeerId peer in peers)
            {
                while (peer.QueueLength > 0)
                {
                    int index = ((HaveMessage)peer.Dequeue()).PieceIndex;
                    Assert.IsFalse(peers.Exists(delegate(PeerId p) { return(p.BitField[index]); }));
                }
            }
        }