コード例 #1
0
        public AnnounceRequest CreateAnnounce(TorrentEvent clientEvent)
        {
            ClientEngine engine = Manager.Engine !;

            bool requireEncryption  = !engine.Settings.AllowedEncryption.Contains(EncryptionType.PlainText);
            bool supportsEncryption = EncryptionTypes.SupportsRC4(engine.Settings.AllowedEncryption);

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

            string?ip = null;
            int    port;

            if (engine.Settings.ReportedAddress != null)
            {
                ip   = engine.Settings.ReportedAddress.Address.ToString();
                port = engine.Settings.ReportedAddress.Port;
            }
            else if (engine.PeerListener.LocalEndPoint != null)
            {
                port = engine.PeerListener.LocalEndPoint.Port;
            }
            else
            {
                port = engine.Settings.ListenEndPoint?.Port ?? -1;
            }

            // 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 - Manager.Bitfield.PercentComplete / 100.0) * Manager.Torrent !.Size);
            }

            return(new AnnounceRequest(Manager.Monitor.DataBytesReceived,
                                       Manager.Monitor.DataBytesSent,
                                       bytesLeft,
                                       clientEvent, Manager.InfoHashes.V1OrV2.Truncate(), requireEncryption, Manager.Engine !.PeerId.AsMemory(),
                                       ip, port, supportsEncryption));
        }