code wiki / (root) / nx_swarm_sim.nx

nx_swarm_sim.nx

buildroot/runtime/nx_swarm_sim.nx

6714 B147 linesdepth 5pulls 5 transitivereach 4 importersview sourcekind librarytopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_sim.nx -- deterministic swarm simulator + download engine (bits-up, replayable). module: nishi-core.torrent.swarm_sim depends: nx_stream_picker.nx (-> nx_piece_manager), nx_syscalls.nx capability: CORE_COMPUTE wired_status: FULLY_WIRED The "session loop" made TESTABLE: a discrete-round model that drives the REAL picker (nx_sp_stream_pick / nx_pm_rarest) and the REAL endgame logic (nx_sp_in_endgame) against a scripted swarm of honest / stalling / lying peers. Because every decision is integer and the peer script is fixed, the whole download REPLAYS bit-for-bit -- the determinism exceed no mainstream client has, here turned into a measurement instrument: a decision-trace hash that must be identical across runs. This is also the substrate the benchmark grades on (adverse-swarm completion, endgame value, streaming-to-playable). It is a SIMULATOR, not a live client -- it measures the selection brain, honestly named as such; the live socket loop is the named next rung.

dependencies 1 imports · 3 importers

nx_stream_picker.nx nx_swarm_sim.nx nx_swarm_sim_test.nx nx_torrent_bench.nx nx_torrent_capbench.nx

imports: nx_stream_picker.nx

imported by: nx_swarm_sim_test.nxnx_torrent_bench.nxnx_torrent_capbench.nx

structs

none

consts

19const NX_MAGIC_1000000007: i64 = 1000000007
21const NX_SS_HONEST: i64 = 0 // delivers a requested piece it holds (verify passes)
22const NX_SS_STALL: i64 = 1 // advertises pieces but never delivers (snub)
23const NX_SS_LIE: i64 = 2 // advertises pieces it will not deliver / delivers corrupt (verify fails)
25const NX_SS_DNF: i64 = 0 - 1 // did-not-finish within max_rounds (a real stall, reported honestly)

functions

29func nx_ss_availability(peer_has: *i64, npeers: i64, n: i64, out_avail: *i64) -> i64
45func nx_ss_holder(peer_has: *i64, npeers: i64, n: i64, piece: i64) -> i64
55func nx_ss_any_honest_holder(peer_has: *i64, behavior: *i64, npeers: i64, n: i64, piece: i64) -> i64
called by 2: nx_ss_runmain
67func nx_ss_outstanding(have: *i64, n: i64) -> i64
82func nx_ss_run(peer_has: *i64, behavior: *i64, npeers: i64, n: i64, have: *i64,
125func nx_ss_rounds_to_playable(peer_has: *i64, behavior: *i64, npeers: i64, n: i64, have: *i64,