public void CanAnnouceOrScrapeTest() { HTTPTracker t = (HTTPTracker)TrackerFactory.Create(new Uri("http://mytracker.com/myurl")); Assert.IsFalse(t.CanScrape, "#1"); Assert.IsTrue(t.CanAnnounce, "#1b"); t = (HTTPTracker)TrackerFactory.Create(new Uri("http://mytracker.com/announce/yeah")); Assert.IsFalse(t.CanScrape, "#2"); Assert.IsTrue(t.CanAnnounce, "#2b"); t = (HTTPTracker)TrackerFactory.Create(new Uri("http://mytracker.com/announce")); Assert.IsTrue(t.CanScrape, "#3"); Assert.IsTrue(t.CanAnnounce, "#3b"); Assert.AreEqual(t.ScrapeUri, new Uri("http://mytracker.com/scrape")); t = (HTTPTracker)TrackerFactory.Create(new Uri("http://mytracker.com/announce/yeah/announce")); Assert.IsTrue(t.CanScrape, "#4"); Assert.IsTrue(t.CanAnnounce, "#4b"); Assert.AreEqual("http://mytracker.com/announce/yeah/scrape", t.ScrapeUri.ToString(), "#4c"); t = (HTTPTracker)TrackerFactory.Create(new Uri("http://mytracker.com/announce/")); Assert.IsTrue(t.CanScrape, "#5"); Assert.IsTrue(t.CanAnnounce, "#5b"); Assert.AreEqual(t.ScrapeUri, new Uri("http://mytracker.com/scrape/")); }
public void Setup() { keys.Clear(); listener.IncompleteAnnounce = listener.IncompleteScrape = false; server = new TrackerServer(trackerId) { AllowUnregisteredTorrents = true }; server.RegisterListener(listener); tracker = (HTTPTracker)TrackerFactory.Create(AnnounceUrl); var infoHashBytes = new[] { ' ', '%', '&', '?', '&', '&', '?', '5', '1', '=' } .Select(t => (byte)t); infoHash = new InfoHash(infoHashBytes.Concat(infoHashBytes).ToArray()); announceParams = new AnnounceParameters() .WithPort(5555) .WithPeerId(peerId) .WithInfoHash(infoHash); scrapeParams = new ScrapeParameters(new InfoHash(new byte[20])); }
public async Task NullKeyTest () { // Set a key which uses characters which need escaping. tracker = (HTTPTracker) TrackerFactory.Create (AnnounceUrl); tracker.Key = null; await tracker.AnnounceAsync (announceParams); Assert.AreEqual (null, keys[0], "#1"); }
public async Task KeyTest() { // Set a key which uses characters which need escaping. tracker = (HTTPTracker)TrackerFactory.Create(AnnounceUrl); tracker.Key = peerId; await tracker.AnnounceAsync(announceParams, CancellationToken.None); Assert.AreEqual(peerId, keys[0], "#1"); }
public override bool Equals(object obj) { HTTPTracker tracker = obj as HTTPTracker; if (tracker == null) { return(false); } // If the announce URL matches, then CanScrape and the scrape URL must match too return(Uri.Equals(tracker.Uri)); }
public void AddTracker(string track) { Uri res; if(Uri.TryCreate(track , UriKind.Absolute , out res)) { if(res.Scheme == "udp") { var t = new UdpTracker(res); t.AnnounceComplete += TrackerAnnounceComplete; _trackers.Add(t); } else if(res.Scheme == Uri.UriSchemeHttp) { var t = new HTTPTracker(res); t.AnnounceComplete += TrackerAnnounceComplete; _trackers.Add(t); } } }