StatChannel

Tracks the throughput of a single byte stream: pure-Kotlin port of libtorrent's stat_channel (stat.hpp, stat.cpp).

Each channel keeps three numbers:

  • a 64-bit running total of every byte ever counted,

  • a 32-bit counter accumulating the bytes seen this tick (reset each secondTick), and

  • a 32-bit exponentially-smoothed rate in bytes/second.

libtorrent uses one of these per direction-and-class (payload vs protocol vs IP overhead); Stat bundles six of them. Counters are signed like the C++ (int32 / int64); overflow is asserted away there and simply not guarded here, matching the "callers never feed absurd values" contract.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun add(count: Int)

Counts count freshly transferred bytes into this channel. Must be >= 0.

Link copied to clipboard
fun clear()

Resets all three numbers to zero. (clear())

Link copied to clipboard
fun counter(): Int

Bytes counted during the current (not-yet-ticked) interval. (counter())

Link copied to clipboard

Alias for rate; libtorrent keeps low_pass_rate() as a synonym.

Link copied to clipboard
fun offset(c: Long)

Adjusts total by c without touching the per-tick counter or rate. Used to seed a fresh connection's stats with bytes from earlier sessions. (offset())

Link copied to clipboard
operator fun plusAssign(s: StatChannel)

Folds another channel's current-tick contribution into this one, mirroring stat_channel::operator+=. Note libtorrent adds the source's counter to both this counter and this total (it does not add the source total).

Link copied to clipboard
fun rate(): Int

The smoothed transfer rate in bytes/second. (rate())

Link copied to clipboard
fun secondTick(tickIntervalMs: Int)

Advances the smoothed rate and resets the per-tick counter. Should be called once per "second", with the real elapsed tickIntervalMs so the rate is normalised to bytes/second even when ticks drift.

Link copied to clipboard
fun total(): Long

All-time total bytes counted. (total())