code wiki / (root) / nx_piece_manager.nx

nx_piece_manager.nx

buildroot/runtime/nx_piece_manager.nx

2902 B75 linesdepth 3pulls 3 transitivereach 19 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_piece_manager.nx -- BitTorrent piece/block manager (bits-up, deterministic). module: nishi-core.torrent.piece_manager depends: nx_syscalls.nx, nx_sha1.nx capability: CORE_COMPUTE wired_status: FULLY_WIRED The download brain: piece/block geometry (16 KiB blocks), per-piece integrity verification (SHA-1 of the assembled piece == the metainfo piece hash; BEP-3), and DETERMINISTIC rarest-first piece selection (lowest-index tie-break -- so a session is bit-for-bit replayable, the determinism exceed thesis). Verified pieces are written to nx_docstore. Reuses sha1 (our crypto); no new primitive.

dependencies 2 imports · 3 importers

nx_syscalls.nx nx_sha1.nx nx_piece_manager.nx nx_avail_map.nx nx_piece_manager_test.nx nx_stream_picker.nx

imports: nx_syscalls.nxnx_sha1.nx

imported by: nx_avail_map.nxnx_piece_manager_test.nxnx_stream_picker.nx

structs

none

consts

17const NX_PM_BLOCK_SIZE: i64 = 16384 // 16 KiB standard request block

functions

20func _pm_ceil_div(a: i64, b: i64) -> i64 { return (a + b - 1) / b }
22func nx_pm_num_pieces(total_length: i64, piece_length: i64) -> i64
called by 2: nx_pm_piece_sizemain calls 1: _pm_ceil_div
28func nx_pm_piece_size(index: i64, total_length: i64, piece_length: i64) -> i64
called by 1: main calls 1: nx_pm_num_pieces
34func nx_pm_num_blocks(piece_size: i64) -> i64 { return _pm_ceil_div(piece_size, NX_PM_BLOCK_SIZE) }
called by 2: nx_pm_block_sizemain calls 1: _pm_ceil_div
37func nx_pm_block_size(block_index: i64, piece_size: i64) -> i64
called by 1: main calls 1: nx_pm_num_blocks
44func nx_pm_verify_piece(piece_data: *u8, piece_size: i64, expected_hash20: *u8) -> i64
called by 1: main calls 2: sys_mmapsha1
53func nx_pm_expected_hash(pieces: *u8, index: i64) -> *u8
59func nx_pm_rarest(availability: *i64, have: *i64, n: i64) -> i64