code wiki / (root) / nx_choker.nx

nx_choker.nx

buildroot/runtime/nx_choker.nx

4380 B100 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_choker.nx -- BitTorrent choke algorithm: tit-for-tat + optimistic unchoke (deterministic). module: nishi-core.torrent.choker depends: nx_syscalls.nx capability: CORE_COMPUTE wired_status: FULLY_WIRED "Better download rates" earned the way the protocol intends: reciprocity. We give upload slots to the peers who feed US fastest (tit-for-tat) so they keep US unchoked, plus one rotating optimistic slot to discover new fast peers and bootstrap newcomers. Mainline rotates the optimistic slot RANDOMLY every ~3 rounds; we rotate it ROUND-ROBIN by a deterministic round counter instead -- same discovery behavior, but the whole choke schedule stays bit-for-bit replayable (the determinism exceed thesis; no client in the field can replay its own choke decisions). Pure selection over caller-owned arrays: no wall clock, no RNG, no syscalls on the decision path.

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_choker.nx nx_choker_test.nx nx_rate_ema_test.nx

imports: nx_syscalls.nx

imported by: nx_choker_test.nxnx_rate_ema_test.nx

structs

none

consts

19const NX_CH_DEFAULT_SLOTS: i64 = 4 // classic mainline upload slots (caller may override via k)
20const NX_CH_OPT_PERIOD: i64 = 3 // rotate the optimistic slot every 3 choke rounds (override via period)

functions

27func nx_ch_select_top_k(rates: *i64, interested: *i64, n: i64, k: i64, out_unchoked: *i64) -> i64
60func nx_ch_optimistic_slot(interested: *i64, out_unchoked: *i64, n: i64, round: i64, period: i64) -> i64
called by 2: nx_ch_computemain
87func nx_ch_compute(rates: *i64, interested: *i64, n: i64, k: i64, round: i64, period: i64, out_unchoked: *i64) -> i64
95func nx_ch_should_rotate(round: i64, period: i64) -> i64
called by 1: main