Beispiel #1
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;
            object peerKey = comparer.GetKey(par);

            if (!peers.TryGetValue(peerKey, out peer))
            {
                peer = new Peer(par, peerKey);
                Add(peer);
            }
            else
            {
                Debug.WriteLine(string.Format("Updating: {0} with key {1}", peer.ClientAddress, peerKey));
                peer.Update(par);
            }
            if (par.Event == TorrentEvent.Completed)
            {
                System.Threading.Interlocked.Increment(ref downloaded.number);
            }

            else if (par.Event == TorrentEvent.Stopped)
            {
                Remove(peer);
            }

            tracker.RaisePeerAnnounced(new AnnounceEventArgs(peer, this));
            UpdateCounts();
        }
        /// <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();
        }