Ejemplo n.º 1
0
 protected TrackerResponseEventArgs(Tracker tracker, object state, bool successful)
 {
     if (tracker == null)
     {
         throw new ArgumentNullException("tracker");
     }
     if (!(state is TrackerConnectionID))
     {
         throw new ArgumentException("The state object must be the same object as in the call to Announce", "state");
     }
     this.id         = (TrackerConnectionID)state;
     this.successful = successful;
     this.tracker    = tracker;
 }
        private WaitHandle Scrape(Tracker tracker, bool trySubsequent)
        {
            if (tracker == null)
            {
                throw new ArgumentNullException("tracker");
            }

            if (!tracker.CanScrape)
            {
                throw new TorrentException("This tracker does not support scraping");
            }

            TrackerConnectionID id = new TrackerConnectionID(tracker, trySubsequent, TorrentEvent.None, new ManualResetEvent(false));

            tracker.Scrape(new ScrapeParameters(this.infoHash), id);
            return(id.WaitHandle);
        }
        private WaitHandle Announce(Tracker tracker, TorrentEvent clientEvent, bool trySubsequent, ManualResetEvent waitHandle)
        {
            ClientEngine engine = manager.Engine;

            // If the engine is null, we have been unregistered
            if (engine == null)
            {
                waitHandle.Set();
                return(waitHandle);
            }

            this.updateSucceeded = true;
            this.lastUpdated     = DateTime.Now;

            EncryptionTypes e = engine.Settings.AllowedEncryption;
            bool            requireEncryption  = !Toolbox.HasEncryption(e, EncryptionTypes.PlainText);
            bool            supportsEncryption = Toolbox.HasEncryption(e, EncryptionTypes.RC4Full) || Toolbox.HasEncryption(e, EncryptionTypes.RC4Header);

            requireEncryption  = requireEncryption && ClientEngine.SupportsEncryption;
            supportsEncryption = supportsEncryption && ClientEngine.SupportsEncryption;

            IPEndPoint reportedAddress = engine.Settings.ReportedAddress;
            string     ip   = reportedAddress == null ? null : reportedAddress.Address.ToString();
            int        port = reportedAddress == null ? engine.Listener.Endpoint.Port : reportedAddress.Port;

            // FIXME: In metadata mode we need to pretend we need to download data otherwise
            // tracker optimisations might result in no peers being sent back.
            long bytesLeft = 1000;

            if (manager.HasMetadata)
            {
                bytesLeft = (long)((1 - this.manager.Bitfield.PercentComplete / 100.0) * this.manager.Torrent.Size);
            }
            AnnounceParameters p = new AnnounceParameters(this.manager.Monitor.DataBytesDownloaded,
                                                          this.manager.Monitor.DataBytesUploaded,
                                                          bytesLeft,
                                                          clientEvent, this.infoHash, requireEncryption, manager.Engine.PeerId,
                                                          ip, port);

            p.SupportsEncryption = supportsEncryption;
            TrackerConnectionID id = new TrackerConnectionID(tracker, trySubsequent, clientEvent, waitHandle);

            tracker.Announce(p, id);
            return(waitHandle);
        }