code wiki / (root) / nx_rate_ema.nx

nx_rate_ema.nx

buildroot/runtime/nx_rate_ema.nx

2242 B47 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic rate
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_rate_ema.nx nx_rate_ema_test.nx

imports: nx_syscalls.nx

imported by: nx_rate_ema_test.nx

structs

none

consts

17const NX_RE_SCALE: i64 = 1000 // default fixed-point denominator for alpha
18const NX_RE_ALPHA_FAST: i64 = 500 // alpha=0.5: responsive (half weight on the new sample)
19const NX_RE_ALPHA_SLOW: i64 = 125 // alpha=0.125: smooth (classic TCP-RTT-style 1/8)

functions

22func nx_re_rate_sample(bytes_delta: i64, interval_ms: i64) -> i64
29func nx_re_ema_update(ema_old: i64, sample: i64, alpha: i64, scale: i64) -> i64
39func nx_re_update_all(rates: *i64, bytes_delta: *i64, npeers: i64, interval_ms: i64, alpha: i64, scale: i64) -> i64