nx_piece_manager.nx
buildroot/runtime/nx_piece_manager.nx
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
imports: nx_syscalls.nxnx_sha1.nx
imported by: nx_avail_map.nxnx_piece_manager_test.nxnx_stream_picker.nx
structs
| none |
consts
| 17 | const NX_PM_BLOCK_SIZE: i64 = 16384 // 16 KiB standard request block |
functions
| 20 | func _pm_ceil_div(a: i64, b: i64) -> i64 { return (a + b - 1) / b } |
| 22 | func nx_pm_num_pieces(total_length: i64, piece_length: i64) -> i64 |
| 28 | func nx_pm_piece_size(index: i64, total_length: i64, piece_length: i64) -> i64 |
| 34 | func nx_pm_num_blocks(piece_size: i64) -> i64 { return _pm_ceil_div(piece_size, NX_PM_BLOCK_SIZE) } |
| 37 | func nx_pm_block_size(block_index: i64, piece_size: i64) -> i64 |
| 44 | func nx_pm_verify_piece(piece_data: *u8, piece_size: i64, expected_hash20: *u8) -> i64 |
| 53 | func nx_pm_expected_hash(pieces: *u8, index: i64) -> *u8 |
| 59 | func nx_pm_rarest(availability: *i64, have: *i64, n: i64) -> i64 |