コード例 #1
0
ファイル: TrackerListener.cs プロジェクト: zjklee/monotorrent
        public virtual BEncodedDictionary Handle(NameValueCollection collection, IPAddress remoteAddress, bool isScrape)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }
            if (remoteAddress == null)
            {
                throw new ArgumentNullException(nameof(remoteAddress));
            }

            TrackerRequest request;

            if (isScrape)
            {
                request = new TrackerScrapeRequest(collection, remoteAddress);
            }
            else
            {
                request = new AnnounceRequest(collection, remoteAddress);
            }

            // If the parameters are invalid, the failure reason will be added to the response dictionary
            if (!request.IsValid)
            {
                return(request.Response);
            }

            // Fire the necessary event so the request will be handled and response filled in
            if (isScrape)
            {
                RaiseScrapeReceived((TrackerScrapeRequest)request);
            }
            else
            {
                RaiseAnnounceReceived((AnnounceRequest)request);
            }

            // Return the response now that the connection has been handled correctly.
            return(request.Response);
        }
コード例 #2
0
ファイル: TrackerListener.cs プロジェクト: zjklee/monotorrent
 protected void RaiseScrapeReceived(TrackerScrapeRequest e)
 {
     ScrapeReceived?.Invoke(this, e);
 }