Esempio n. 1
0
        public void AnnouncePeersTest()
        {
            AddAllTrackables();
            rig.Peers.ForEach(delegate(PeerDetails d) { rig.Listener.Handle(d, System.Net.BitTorrent.Common.TorrentEvent.Started, rig.Trackables[0]); });

            SimpleTorrentManager manager = rig.Tracker.GetManager(rig.Trackables[0]);

            Assert.AreEqual(rig.Peers.Count, manager.Count, "#1");
            foreach (ITrackable t in rig.Trackables)
            {
                SimpleTorrentManager m = rig.Tracker.GetManager(t);
                if (m == manager)
                {
                    continue;
                }
                Assert.AreEqual(0, m.Count, "#2");
            }

            foreach (Peer p in manager.GetPeers())
            {
                PeerDetails d = rig.Peers.Find(delegate(PeerDetails details) {
                    return(details.ClientAddress == p.ClientAddress.Address && details.Port == p.ClientAddress.Port);
                });
                Assert.AreEqual(d.Downloaded, p.Downloaded, "#3");
                Assert.AreEqual(d.peerId, p.PeerId, "#4");
                Assert.AreEqual(d.Remaining, p.Remaining, "#5");
                Assert.AreEqual(d.Uploaded, p.Uploaded, "#6");
            }
        }
        public BEncodedValue Handle(PeerDetails d, System.Net.BitTorrent.Common.TorrentEvent e, ITrackable trackable)
        {
            NameValueCollection c = new NameValueCollection();

            c.Add("info_hash", trackable.InfoHash.UrlEncode());
            c.Add("peer_id", d.peerId);
            c.Add("port", d.Port.ToString());
            c.Add("uploaded", d.Uploaded.ToString());
            c.Add("downloaded", d.Downloaded.ToString());
            c.Add("left", d.Remaining.ToString());
            c.Add("compact", "0");

            return(base.Handle(c, d.ClientAddress, false));
        }
 private void GeneratePeers()
 {
     Peers = new List <PeerDetails>();
     for (int i = 0; i < 100; i++)
     {
         PeerDetails d = new PeerDetails();
         d.ClientAddress = IPAddress.Parse(string.Format("127.0.{0}.2", i));
         d.Downloaded    = (int)(10000 * r.NextDouble());
         d.peerId        = string.Format("-----------------{0:0.000}", i);
         d.Port          = r.Next(65000);
         d.Remaining     = r.Next(10000, 100000);
         d.Uploaded      = r.Next(10000, 100000);
         Peers.Add(d);
     }
 }