nx_torrent_peer_dl.nx
buildroot/runtime/nx_torrent_peer_dl.nx
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
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
structs
| none |
consts
| 17 | const PW_MAGIC_8192: i64 = 8192 |
| 18 | const PW_MAGIC_53491: i64 = 53491 |
| 19 | const PW_MAGIC_2048: i64 = 2048 |
| 20 | const PW_MAGIC_1024: i64 = 1024 |
| 22 | const PW_EXTENDED: i64 = 20 |
| 23 | const TOTAL: i64 = 48 |
| 24 | const PLEN: i64 = 32 // piece length -> pieces: 0=[0,32) 1=[32,48) |
| 25 | const NPIECES: i64 = 2 |
functions
| 27 | func 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 |
| 28 | func td_wn(fd: i64, v: i64) -> i64 called by 1: main |
| 33 | func 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 |
| 34 | func td_bint(buf: *u8, off: i64, v: i64) -> i64 called by 1: main |
| 38 | func td_sockaddr(sa: *u8, port: i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64 called by 1: main |
| 45 | func td_read_n(fd: i64, buf: *u8, n: i64) -> i64 |
| 50 | func td_write_n(fd: i64, buf: *u8, n: i64) -> i64 called by 1: main |
| 55 | func td_read_msg(fd: i64, mb: *u8, cap: i64) -> i64 |
| 63 | func td_build_ext(ext_id: i64, data: *u8, dlen: i64, out: *u8) -> i64 |
| 69 | func td_eq(a: *u8, b: *u8, n: i64) -> i64 called by 1: main |
| 75 | func main() -> i64 |