void ListenerReceivedAnnounce(object?sender, AnnounceRequest e) { if (Disposed) { e.Response.Add(TrackerRequest.FailureKey, (BEncodedString)"The tracker has been shut down"); return; } Requests.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(e.InfoHash !.ToHex(), e.InfoHash)); manager = Torrents[e.InfoHash]; } else { e.Response.Add(TrackerRequest.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(TrackerRequest.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(IntervalKey, new BEncodedNumber((int)AnnounceInterval.TotalSeconds)); e.Response.Add(MinIntervalKey, new BEncodedNumber((int)MinAnnounceInterval.TotalSeconds)); e.Response.Add(TrackerIdKey, TrackerId); // FIXME: Is this right? e.Response.Add(CompleteKey, new BEncodedNumber(manager.Complete)); e.Response.Add(IncompleteKey, new BEncodedNumber(manager.Incomplete)); e.Response.Add(DownloadedKey, new BEncodedNumber(manager.Downloaded)); //FIXME is this the right behaivour //if (par.TrackerId == null) // par.TrackerId = "monotorrent-tracker"; }