Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            AnnounceParameters other = obj as AnnounceParameters;

            return(other == null ? false : other.clientAddress.Equals(clientAddress) &&
                   other.Port.Equals(Port));
        }
Ejemplo n.º 2
0
        private void ListenerReceivedAnnounce(object sender, AnnounceParameters e)
        {
            if (disposed)
            {
                e.Response.Add(RequestParameters.FailureKey, (BEncodedString)"The tracker has been shut down");
                return;
            }

            monitor.AnnounceReceived();
            SimpleTorrentManager manager;

            // Check to see if we're monitoring the requested torrent
            lock (torrents)
            {
                if (!torrents.TryGetValue(e.InfoHash, out manager))
                {
                    if (AllowUnregisteredTorrents)
                    {
                        Add(new InfoHashTrackable(BitConverter.ToString(e.InfoHash.Hash), e.InfoHash));
                        manager = torrents[e.InfoHash];
                    }
                    else
                    {
                        e.Response.Add(RequestParameters.FailureKey, (BEncodedString)"The requested torrent is not registered with this tracker");
                        return;
                    }
                }
            }

            // If a non-compact response is expected and we do not allow non-compact responses
            // bail out
            if (!AllowNonCompact && !e.HasRequestedCompact)
            {
                e.Response.Add(RequestParameters.FailureKey, (BEncodedString)"This tracker does not support non-compact responses");
                return;
            }

            lock (manager)
            {
                // Update the tracker with the peers information. This adds the peer to the tracker,
                // updates it's information or removes it depending on the context
                manager.Update(e);

                // Clear any peers who haven't announced within the allowed timespan and may be inactive
                manager.ClearZombiePeers(DateTime.Now.Add(-TimeoutInterval));

                // Fulfill the announce request
                manager.GetPeers(e.Response, e.NumberWanted, e.HasRequestedCompact);
            }

            e.Response.Add(Tracker.IntervalKey, new BEncodedNumber((int)AnnounceInterval.TotalSeconds));
            e.Response.Add(Tracker.MinIntervalKey, new BEncodedNumber((int)MinAnnounceInterval.TotalSeconds));
            e.Response.Add(Tracker.TrackerIdKey, trackerId); // FIXME: Is this right?
            e.Response.Add(Tracker.CompleteKey, new BEncodedNumber(manager.Complete));
            e.Response.Add(Tracker.Incomplete, new BEncodedNumber(manager.Incomplete));

            //FIXME is this the right behaivour
            //if (par.TrackerId == null)
            //    par.TrackerId = "monotorrent-tracker";
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the peer in the tracker database based on the announce parameters
        /// </summary>
        /// <param name="par"></param>
        internal void Update(AnnounceParameters par)
        {
            Peer peer;
            var  peerKey = _comparer.GetKey(par);

            if (!_peers.TryGetValue(peerKey, out peer))
            {
                peer = new Peer(par, peerKey);
                Add(peer);
            }
            else
            {
                Debug.WriteLine("Updating: {0} with key {1}", peer.ClientAddress, peerKey);
                peer.Update(par);
            }
            switch (par.Event)
            {
            case TorrentEvent.Completed:
                System.Threading.Interlocked.Increment(ref _downloaded.InternalNumber);
                break;

            case TorrentEvent.Stopped:
                Remove(peer);
                break;
            }

            _tracker.RaisePeerAnnounced(new AnnounceEventArgs(peer, this));
            UpdateCounts();
        }
Ejemplo n.º 4
0
        internal void Update(AnnounceParameters parameters)
        {
            DateTime now         = DateTime.Now;
            double   elapsedTime = (now - lastAnnounceTime).TotalSeconds;

            if (elapsedTime < 1)
            {
                elapsedTime = 1;
            }

            clientAddress    = parameters.ClientAddress;
            downloadSpeed    = (int)((parameters.Downloaded - downloaded) / elapsedTime);
            uploadSpeed      = (int)((parameters.Uploaded - uploaded) / elapsedTime);
            downloaded       = parameters.Downloaded;
            uploaded         = parameters.Uploaded;
            left             = parameters.Left;
            peerId           = parameters.PeerId;
            lastAnnounceTime = now;
        }
Ejemplo n.º 5
0
 public object GetKey(AnnounceParameters parameters)
 {
     return parameters.ClientAddress;
 }
Ejemplo n.º 6
0
 public object GetKey(AnnounceParameters parameters)
 {
     return parameters.Uploaded;
 }
Ejemplo n.º 7
0
 internal Peer(AnnounceParameters par, object dictionaryKey)
 {
     this.dictionaryKey = dictionaryKey;
     Update(par);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates the peer in the tracker database based on the announce parameters
        /// </summary>
        /// <param name="par"></param>
        internal void Update(AnnounceParameters par)
        {
            Peer peer;
            var peerKey = _comparer.GetKey(par);
            if (!_peers.TryGetValue(peerKey, out peer))
            {
                peer = new Peer(par, peerKey);
                Add(peer);
            }
            else
            {
                Debug.WriteLine("Updating: {0} with key {1}", peer.ClientAddress, peerKey);
                peer.Update(par);
            }
            switch (par.Event)
            {
                case TorrentEvent.Completed:
                    System.Threading.Interlocked.Increment(ref _downloaded.InternalNumber);
                    break;
                case TorrentEvent.Stopped:
                    Remove(peer);
                    break;
            }

            _tracker.RaisePeerAnnounced(new AnnounceEventArgs(peer, this));
            UpdateCounts();
        }
Ejemplo n.º 9
0
 public object GetKey(AnnounceParameters parameters)
 {
     return(parameters.ClientAddress);
 }