Beispiel #1
0
        public void AnnouncePeersTest()
        {
            AddAllTrackables();
            rig.Peers.ForEach(delegate(PeerDetails d) { rig.Listener.Handle(d, 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, 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);
        }
Beispiel #3
0
        public BEncodedValue Handle(PeerDetails d, TorrentEvent e, ITrackable trackable)
        {
            NameValueCollection c = new NameValueCollection();

            c.Add("info_hash", trackable.InfoHash.UrlEncode());
            c.Add("peer_id", d.peerId.UrlEncode());
            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));
        }
Beispiel #4
0
 private void GeneratePeers()
 {
     Peers = new List <PeerDetails> ();
     for (int i = 0; i < 100; i++)
     {
         PeerDetails d = new PeerDetails();
         d.ClientAddress = IPAddress.Parse($"127.0.{i}.2");
         d.Downloaded    = (int)(10000 * r.NextDouble());
         d.peerId        = $"-----------------{i:0.000}";
         d.Port          = r.Next(65000);
         d.Remaining     = r.Next(10000, 100000);
         d.Uploaded      = r.Next(10000, 100000);
         Peers.Add(d);
     }
 }
 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);
     }
 }