code wiki / (root) / nx_peer_piece.nx

nx_peer_piece.nx

buildroot/runtime/nx_peer_piece.nx

7482 B145 linesdepth 5pulls 8 transitivereach 0 importersview sourcekind tooltopic peer
docsdependenciesstructsconstsfunctions

about

nx_peer_piece.nx -- BEP-3 REQUEST/PIECE block transfer + sha1 verify (X-TORRENT-LIVE-001 R4-b): the actual download mechanism. interested -> unchoke -> request(index,begin,length) -> PIECE (<index><begin><block>) -> extract block -> sha1-verify. Reuses nx_peerwire (BEP-3 build/parse, KAT'd) + nx_sha1 (hash) -- both on the nx_syscalls layer. GATE = SOVEREIGN LOOPBACK (TCP, the nx_peer_handshake pattern): a mock peer (listen-before-fork) completes the handshake, unchokes, and serves a known 16-byte block in a PIECE msg; the client requests it, extracts it, and asserts the block bytes + its sha1 match the expected. No external net; deterministic; no-hang. license_tier: ORIGINAL module: nishi-core.torrent.peer_piece depends: nishi-core.torrent.peerwire, nishi-core.crypto.sha1

dependencies 4 imports · 0 importers

nx_peerwire.nx nx_itoa_lib.nx nx_connect.nx nx_sha1.nx nx_peer_piece.nx

imports: nx_peerwire.nxnx_itoa_lib.nxnx_connect.nxnx_sha1.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main pp_sockaddr sys_socket sys_setsockopt sys_set_socket_timeout sys_mmap sys_setsockopt ↻ sys_munmap sys_bind sys_listen pp_w sys_fork sys_accept pp_read_n sys_read nx_pw_build_handshake pp_write_n pp_read_msg pp_read_n ↻ _pw_get_u32 nx_pw_build_msg _pw_put_u32 _pw_put_u32 ↻ nx_connect_bounded nx_fcntl sys_connect sys_mmap ↻ sys_poll nx_pw_parse_handshake nx_pw_build_request sys_mmap ↻ _pw_put_u32 ↻ nx_pw_build_msg ↻ nx_pw_msg_id sha1 sys_mmap ↻ sha1_process_block if_ge sys_wait4 pp_wn

structs

none

consts

16const K_MAGIC_53377: i64 = 53377
51const BLK: i64 = 16

functions

18func pp_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main
23func pp_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
24func pp_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 1: main
31func pp_read_n(fd: i64, buf: *u8, n: i64) -> i64
called by 2: pp_read_msgmain calls 1: sys_read
36func pp_write_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main
42func pp_read_msg(fd: i64, mb: *u8, cap: i64) -> i64
called by 1: main calls 2: pp_read_n_pw_get_u32
53func main() -> i64