nx_rate_ema.nx
buildroot/runtime/nx_rate_ema.nx
about
nx_rate_ema.nx -- rolling per-peer download-rate accounting (bits-up, deterministic).
module: nishi-core.torrent.rate_ema
depends: nx_syscalls.nx
capability: CORE_COMPUTE
wired_status: FULLY_WIRED
The fuel the choker runs on: tit-for-tat needs a per-peer "bytes/sec we got from them"
number, and a real client must DERIVE it from raw byte counters, smoothed so one bursty
interval does not flip the unchoke set. Fixed-point integer EMA (no float, no wall-clock
in the math itself -- the caller passes the measured interval), so the smoothed rates --
and therefore every choke decision built on them -- stay bit-for-bit replayable. Writes
straight into the choker's rates[] array (nx_ch_select_top_k consumes it unchanged).
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_rate_ema_test.nx
structs
| none |
consts
| 17 | const NX_RE_SCALE: i64 = 1000 // default fixed-point denominator for alpha |
| 18 | const NX_RE_ALPHA_FAST: i64 = 500 // alpha=0.5: responsive (half weight on the new sample) |
| 19 | const NX_RE_ALPHA_SLOW: i64 = 125 // alpha=0.125: smooth (classic TCP-RTT-style 1/8) |
functions
| 22 | func nx_re_rate_sample(bytes_delta: i64, interval_ms: i64) -> i64 |
| 29 | func nx_re_ema_update(ema_old: i64, sample: i64, alpha: i64, scale: i64) -> i64 |
| 39 | func nx_re_update_all(rates: *i64, bytes_delta: *i64, npeers: i64, interval_ms: i64, alpha: i64, scale: i64) -> i64 |