code wiki / (root) / nx_peer_download.nx

nx_peer_download.nx

buildroot/runtime/nx_peer_download.nx

8401 B166 linesdepth 5pulls 8 transitivereach 0 importersview sourcekind tooltopic peer
docsdependenciesstructsconstsfunctions

about

nx_peer_download.nx -- DOWNLOAD a multi-block piece off a peer + WRITE it to a LOCAL FILE, read-back verified (X-TORRENT-LIVE-001 R5): the literal "download locally" step. Builds on R4-b: handshake -> interested -> unchoke -> request each 16-byte block -> PIECE -> assemble the 32-byte piece -> sha1-verify -> sys_openat_wr the piece to a local file at its offset -> read it back -> assert on-disk bytes + sha1 match. Reuses nx_peerwire (BEP-3) + nx_sha1. GATE = SOVEREIGN LOOPBACK: a mock peer serves the two known blocks in request order; the client downloads, assembles, writes, and re-reads from disk. Deterministic; no external net; no-hang (timeouts). license_tier: ORIGINAL module: nishi-core.torrent.peer_download 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_download.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 pd_sockaddr sys_socket sys_setsockopt sys_set_socket_timeout sys_mmap sys_setsockopt ↻ sys_munmap sys_bind sys_listen pd_w sys_fork sys_accept pd_read_n sys_read nx_pw_build_handshake pd_write_n pd_read_msg pd_read_n ↻ _pw_get_u32 nx_pw_build_msg _pw_put_u32 _pw_get_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_openat_wr

structs

none

consts

15const K_MAGIC_53401: i64 = 53401
49const BLK: i64 = 16
50const NBLK: i64 = 2
51const PIECE: i64 = 32 // BLK*NBLK

functions

17func pd_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
22func pd_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
23func pd_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 1: main
30func pd_read_n(fd: i64, buf: *u8, n: i64) -> i64
called by 2: pd_read_msgmain calls 1: sys_read
35func pd_write_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main
40func pd_read_msg(fd: i64, mb: *u8, cap: i64) -> i64
called by 1: main calls 2: pd_read_n_pw_get_u32
53func main() -> i64