AnnounceEntry

class AnnounceEntry(val url: String, val tier: Int = 0, var fails: Int = 0, var isWorking: Boolean = true, var nextAnnounceEpochSecs: Long = 0, var minAnnounceEpochSecs: Long = 0, var lastEvent: TrackerEvent = TrackerEvent.NONE, var completeSent: Boolean = false, var startSent: Boolean = false, var trackerId: String = "")

Per-URL announce bookkeeping. This is the KiteTorrent port of the live state libtorrent carries in aux::announce_entry and aux::announce_infohash (include/libtorrent/aux_/announce_entry.hpp). The session module owns the announce loop and tier logic; this struct is the mutable state it threads per tracker URL so the loop can decide when to (re-)announce and what to send.

It is a plain mutable holder rather than a data class because the loop mutates it in place across announces, exactly as libtorrent mutates the fields of an announce_entry between calls.

Constructors

Link copied to clipboard
constructor(url: String, tier: Int = 0, fails: Int = 0, isWorking: Boolean = true, nextAnnounceEpochSecs: Long = 0, minAnnounceEpochSecs: Long = 0, lastEvent: TrackerEvent = TrackerEvent.NONE, completeSent: Boolean = false, startSent: Boolean = false, trackerId: String = "")

Properties

Link copied to clipboard

whether we have already sent a completed event to this tracker (libtorrent announce_infohash::complete_sent); prevents re-sending it.

Link copied to clipboard
var fails: Int

consecutive failed announces; reset to 0 on success. libtorrent stores this as a 7-bit field (announce_infohash::fails), so it saturates at 127.

Link copied to clipboard

whether the most recent announce succeeded. libtorrent derives is_working() as fails == 0, which we mirror via markWorking and markFailed.

Link copied to clipboard

the last TrackerEvent we sent this tracker, so the loop can send started exactly once and decide whether completed is still owed.

Link copied to clipboard

the earliest epoch-second the loop may re-announce even for an early/forced refresh (libtorrent announce_infohash::min_announce), derived from a response's AnnounceResponse.minInterval.

Link copied to clipboard

the wall-clock epoch-second instant the loop may next announce to this tracker (libtorrent announce_infohash::next_announce), 0 meaning "as soon as possible".

Link copied to clipboard

whether we have already sent a started event (libtorrent announce_infohash::start_sent).

Link copied to clipboard
val tier: Int

the tier this tracker belongs to; trackers are tried tier by tier, lowest first (BEP-12, libtorrent announce_entry::tier).

Link copied to clipboard

the last tracker id string this tracker handed back, to be echoed on the next announce (libtorrent announce_entry::trackerid). Empty if none.

Link copied to clipboard
val url: String

the tracker's announce URL (libtorrent announce_entry::url).

Functions

Link copied to clipboard
fun markFailed(nowEpochSecs: Long, backoffRatio: Int = TrackerBackoff.DEFAULT_BACKOFF_RATIO, retryIntervalSecs: Int = 0)

Record a failed announce at nowEpochSecs, porting announce_infohash::failed: bump fails (saturating at 127), mark not-working, and push nextAnnounceEpochSecs out by the exponential back-off in TrackerBackoff.nextDelaySecs. retryIntervalSecs is libtorrent's retry_interval floor (e.g. a tracker-supplied retry hint).

Link copied to clipboard
fun markWorking(nowEpochSecs: Long, interval: Int, minInterval: Int, trackerId: String = this.trackerId)

Record a successful announce against this tracker at nowEpochSecs: clear the failure counter, mark working, and schedule the next announce interval seconds out with the floor at minInterval (libtorrent sets both next_announce and min_announce on a good response). Captures any trackerId echoed.