nx_stream_picker.nx
buildroot/runtime/nx_stream_picker.nx
about
nx_stream_picker.nx -- streaming + endgame piece selection (bits-up, deterministic).
module: nishi-core.torrent.stream_picker
depends: nx_piece_manager.nx (reuses nx_pm_rarest; DRY -- one canonical tie-break)
capability: CORE_COMPUTE
wired_status: FULLY_WIRED
The modern "watch / play while you download" capability and the long-tail-killing
endgame mode, with NO wall-clock and NO RNG -- every selection is bit-for-bit
replayable (the determinism exceed thesis: no mainstream client can replay a swarm
session). The player advertises a playhead (the piece it is about to render); the
picker prioritizes a sliding deadline window so playback never starves, while still
feeding rarest-first pieces to the swarm outside the window (swarm-health is not
sacrificed for streaming -- BUILD intelligence, don't strip a feature). Endgame lets
several peers race the final outstanding blocks (cancel the losers), killing the one
slow peer who holds the last block -- the dominant source of completion-time variance.
Pipeline depth is the request-queue throughput lever, derived from the bandwidth-delay
product (no magic number: callers pass measured bandwidth/rtt and the ceiling config).
dependencies 1 imports · 3 importers
imports: nx_piece_manager.nx
imported by: nx_endgame.nxnx_stream_picker_test.nxnx_swarm_sim.nx
structs
| none |
consts
| 22 | const NX_SP_BLOCK_SIZE: i64 = 16384 // mirrors nx_piece_manager's request block |
| 23 | const NX_SP_PIPELINE_MIN: i64 = 2 // floor: at least 2 in flight to hide per-request RTT |
| 24 | const NX_SP_PIPELINE_MAX: i64 = 256 // ceiling: bound peer memory / cancel cost |
| 27 | const NX_SP_BLK_NEEDED: i64 = 0 // not yet requested from any peer |
| 28 | const NX_SP_BLK_REQUESTED: i64 = 1 // requested, not yet received (eligible to re-race in endgame) |
| 29 | const NX_SP_BLK_RECEIVED: i64 = 2 // bytes in hand; never re-pick |
functions
| 33 | func nx_sp_sequential(have: *i64, n: i64) -> i64 |
| 48 | func nx_sp_stream_pick(availability: *i64, have: *i64, n: i64, playhead: i64, window_len: i64) -> i64 |
| 66 | func nx_sp_is_urgent(piece_index: i64, playhead: i64, panic_len: i64) -> i64 called by 1: main |
| 74 | func nx_sp_contiguous_have(have: *i64, n: i64, playhead: i64) -> i64 |
| 87 | func nx_sp_can_play(have: *i64, n: i64, playhead: i64, lookahead: i64) -> i64 |
| 94 | func nx_sp_in_endgame(outstanding_blocks: i64, threshold: i64) -> i64 |
| 100 | func nx_sp_blocks_outstanding(block_state: *i64, nblocks: i64) -> i64 called by 1: main |
| 115 | func nx_sp_pick_block(block_state: *i64, nblocks: i64, endgame: i64) -> i64 called by 1: main |
| 136 | func nx_sp_pipeline_depth(bw_bytes_per_s: i64, rtt_ms: i64, block_size: i64) -> i64 called by 1: main |