code wiki / (root) / nx_torrent_peer_dl.nx

nx_torrent_peer_dl.nx

buildroot/runtime/nx_torrent_peer_dl.nx

13573 B225 linesdepth 5pulls 8 transitivereach 0 importersview sourcekind tooltopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_peer_dl.nx -- ORCHESTRATION (X-TORRENT-LIVE-001): a single-peer FULL-FILE download composing the proven mechanisms into one flow -> writes the complete, verified file to disk. From info_hash + a connected peer: BEP-3 handshake(ext) -> BEP-10 ext handshake -> BEP-9 ut_metadata fetch (= the piece map: num_pieces, piece_length, total, per-piece sha1 hashes) -> interested/unchoke -> for each data piece: BEP-3 request -> PIECE -> sha1(piece)==pieces[i] (REAL per-piece verify) -> write at offset i*piece_length -> the complete file. Reuses nx_peerwire + nx_bencode + nx_sha1. GATE = SOVEREIGN LOOPBACK: a mock peer serves a small 2-piece test file (48 bytes, piece_length 32) with the REAL piece hashes in its info-dict; the client downloads the whole thing and the on-disk file must equal the original. license_tier: ORIGINAL module: nishi-core.torrent.peer_dl depends: nishi-core.torrent.peerwire, nishi-core.torrent.bencode, nishi-core.crypto.sha1

dependencies 4 imports · 0 importers

nx_peerwire.nx nx_connect.nx nx_bencode.nx nx_sha1.nx nx_torrent_peer_dl.nx

imports: nx_peerwire.nxnx_connect.nxnx_bencode.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 sha1 sys_mmap sha1_process_block if_ge td_bstr td_sockaddr sys_socket sys_setsockopt sys_set_socket_timeout sys_mmap ↻ sys_setsockopt ↻ sys_munmap sys_bind sys_listen td_w sys_fork sys_accept td_read_n sys_read nx_pw_build_handshake td_write_n td_read_msg td_read_n ↻ _pw_get_u32 td_bint td_build_ext nx_pw_build_msg _pw_put_u32 nx_pw_build_msg ↻ _pw_get_u32 ↻ _pw_put_u32 ↻ nx_connect_bounded nx_fcntl sys_connect sys_mmap ↻ sys_poll nx_bc_dict_get sys_mmap ↻ nx_bc_str

structs

none

consts

17const PW_MAGIC_8192: i64 = 8192
18const PW_MAGIC_53491: i64 = 53491
19const PW_MAGIC_2048: i64 = 2048
20const PW_MAGIC_1024: i64 = 1024
22const PW_EXTENDED: i64 = 20
23const TOTAL: i64 = 48
24const PLEN: i64 = 32 // piece length -> pieces: 0=[0,32) 1=[32,48)
25const NPIECES: i64 = 2

functions

27func td_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
28func td_wn(fd: i64, v: i64) -> i64
called by 1: main
33func td_bstr(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { buf[off+i]=s[i]; i=i+1 } return off+i }
called by 1: main
34func td_bint(buf: *u8, off: i64, v: i64) -> i64
called by 1: main
38func td_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 1: main
45func td_read_n(fd: i64, buf: *u8, n: i64) -> i64
called by 2: td_read_msgmain calls 1: sys_read
50func td_write_n(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main
55func td_read_msg(fd: i64, mb: *u8, cap: i64) -> i64
called by 1: main calls 2: td_read_n_pw_get_u32
63func td_build_ext(ext_id: i64, data: *u8, dlen: i64, out: *u8) -> i64
called by 1: main calls 1: nx_pw_build_msg
69func td_eq(a: *u8, b: *u8, n: i64) -> i64
called by 1: main
75func main() -> i64