Exemplo n.º 1
0
        public void Setup()
        {
            keys.Clear();

            listener.IncompleteAnnounce = listener.IncompleteScrape = false;

            server = new TrackerServer(trackerId)
            {
                AllowUnregisteredTorrents = true
            };
            server.RegisterListener(listener);
            client            = new HttpClient();
            trackerConnection = new HttpTrackerConnection(AnnounceUrl, client);
            tracker           = new Tracker(trackerConnection);

            var infoHashBytes = new[] { ' ', '%', '&', '?', '&', '&', '?', '5', '1', '=' }
            .Select(t => (byte)t);

            infoHash       = new InfoHash(infoHashBytes.Concat(infoHashBytes).ToArray());
            announceParams = new MonoTorrent.Trackers.AnnounceRequest(infoHash)
                             .WithPort(5555)
                             .WithPeerId(peerId.Span.ToArray());

            scrapeParams = new MonoTorrent.Trackers.ScrapeRequest(infoHash);
        }
Exemplo n.º 2
0
        public async ReusableTask <ScrapeResponse> ScrapeAsync(ScrapeRequest parameters, CancellationToken token)
        {
            try {
                StatusOverride = TrackerState.Connecting;
                var response = await Connection.ScrapeAsync(parameters, token);

                LastResponse = response;
                return(response);
            } finally {
                StatusOverride = null;
                LastAnnounced.Restart();
            }
        }
Exemplo n.º 3
0
        public async Task MultipleScrape()
        {
            Random r = new Random();

            for (int i = 0; i < 20; i++)
            {
                var buffer = new byte[20];
                r.NextBytes(buffer);
                var         infoHash   = new InfoHash(buffer);
                TrackerTier tier       = new TrackerTier(Factories.Default, new[] { uri.ToString() });
                var         parameters = new MonoTorrent.Trackers.ScrapeRequest(infoHash);
                await tier.Trackers[0].ScrapeAsync(parameters, CancellationToken.None);
            }
        }
Exemplo n.º 4
0
        public async ReusableTask ScrapeAsync(ITracker tracker, CancellationToken token)
        {
            if (!tracker.CanScrape)
            {
                throw new TorrentException("This tracker does not support scraping");
            }

            // If the user initiates a Scrape we need to go to the correct thread to process it.
            await ClientEngine.MainLoop;

            ScrapeRequest args        = RequestFactory.CreateScrape();
            var           trackerTier = Tiers.Single(t => t.Trackers.Contains(tracker));
            await trackerTier.ScrapeAsync(args, tracker, token);
        }
Exemplo n.º 5
0
        public async Task Scrape()
        {
            // make sure it's a unique infohash as the listener isn't re-created for every test.
            infoHash = new InfoHash(Enumerable.Repeat((byte)1, 20).ToArray());
            var trackable = new InfoHashTrackable("Test", infoHash);

            server.Add(trackable);
            scrapeParams = new MonoTorrent.Trackers.ScrapeRequest(infoHash);

            await tracker.ScrapeAsync(scrapeParams, CancellationToken.None);

            Assert.AreEqual(0, tracker.Complete, "#1");
            Assert.AreEqual(0, tracker.Incomplete, "#2");
            Assert.AreEqual(0, tracker.Downloaded, "#3");

            await tracker.AnnounceAsync(new MonoTorrent.Trackers.AnnounceRequest(0, 0, 100, TorrentEvent.Started, infoHash, false, new BEncodedString("peer1").Span.ToArray(), null, 1, false), CancellationToken.None);

            await tracker.ScrapeAsync(scrapeParams, CancellationToken.None);

            Assert.AreEqual(0, tracker.Complete, "#4");
            Assert.AreEqual(1, tracker.Incomplete, "#5");
            Assert.AreEqual(0, tracker.Downloaded, "#6");

            await tracker.AnnounceAsync(new MonoTorrent.Trackers.AnnounceRequest(0, 0, 0, TorrentEvent.Started, infoHash, false, new BEncodedString("peer2").Span.ToArray(), null, 2, false), CancellationToken.None);

            await tracker.ScrapeAsync(scrapeParams, CancellationToken.None);

            Assert.AreEqual(1, tracker.Complete, "#7");
            Assert.AreEqual(1, tracker.Incomplete, "#8");
            Assert.AreEqual(0, tracker.Downloaded, "#9");

            await tracker.AnnounceAsync(new MonoTorrent.Trackers.AnnounceRequest(0, 0, 0, TorrentEvent.Completed, infoHash, false, new BEncodedString("peer3").Span.ToArray(), null, 3, false), CancellationToken.None);

            await tracker.ScrapeAsync(scrapeParams, CancellationToken.None);

            Assert.AreEqual(2, tracker.Complete, "#10");
            Assert.AreEqual(1, tracker.Incomplete, "#11");
            Assert.AreEqual(1, tracker.Downloaded, "#12");
        }