nx_torrent_get.nx
buildroot/runtime/nx_torrent_get.nx
about
nx_torrent_get.nx -- the DOWNLOAD WORKER (X-TORRENT-LIVE-001 L5): magnet -> a real file on disk +
a live STATUS file the daemon/UI polls. Composes the proven engine (mg_parse + cl_announce + BEP-3
handshake + BEP-9 metadata + BEP-3 data pieces + sha1 verify). FORK-BOUNDED per peer (parent
wait4(WNOHANG)+sys_sleep_ms+nx_kill so an unreachable peer can't hang ~127s). Forked children share
progress via on-disk files: outfile (non-trunc, write each verified piece at its offset), donefile
(bitmap, set [i]=1 per piece), npcfile (piece count). argv[1]=magnet argv[2]=outdir.
nx_sov_build_run drops args -> run the built elf directly. license_tier: ORIGINAL
module: nishi-core.torrent.get
depends: nishi-core.torrent.peer_piece_live, nishi-core.torrent.magnet
dependencies 11 imports · 5 importers
diagram shows first 10 each side; +1 more imports, +0 more importers in the complete lists below.
imports: nx_connect.nxnx_peer_piece_live.nxnx_magnet.nxnx_http_tracker.nxnx_dht_get_peers.nxnx_endgame.nxnx_pex.nxnx_tracker_list.nxnx_mse_wire.nxnx_ipfilter.nxnx_poolgov.nx
imported by: nx_pex_harvest_gate.nxnx_tg_autoseed_gate.nxnx_tg_mftotal_gate.nxnx_tg_wanted_gate.nxnx_unchoke_gate.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 22 | const TG_MAGIC_1410: i64 = 1410 |
| 23 | const TG_MAGIC_1450: i64 = 1450 |
| 24 | const TG_MAGIC_1024: i64 = 1024 |
| 25 | const TG_MAGIC_15728640: i64 = 15728640 |
| 26 | const TG_MAGIC_65536: i64 = 65536 |
| 27 | const TG_MAGIC_262144: i64 = 262144 |
| 28 | const TG_MAGIC_40000: i64 = 40000 |
| 32 | const TG_SLOT_COOLDOWN: i64 = 2 |
| 36 | const TG_CONNECT_MS: i64 = 6000 |
| 41 | const TG_ANN_MAX_TICKS: i64 = 45 |
| 42 | const TG_MAGIC_2000000: i64 = 2000000 |
| 43 | const TG_MAGIC_2000000: i64 = 2000000 |
| 44 | const TG_MAGIC_16383: i64 = 16383 |
| 45 | const TG_MAGIC_16384: i64 = 16384 |
| 46 | const TG_MAGIC_1000000000: i64 = 1000000000 |
| 47 | const TG_MAGIC_65535: i64 = 65535 |
| 48 | const TG_MAGIC_1337: i64 = 1337 |
| 49 | const TG_MAGIC_262143: i64 = 262143 |
| 50 | const TG_MAGIC_80000: i64 = 80000 |
| 51 | const TG_MAGIC_2000: i64 = 2000 |
| 57 | const TG_ENDGAME_THRESHOLD: i64 = 16 |
| 63 | const TG_UNCHOKE_WAIT: i64 = 90 |
| 71 | const TG_DATA_TIMEOUT: i64 = 30 |
functions
| 74 | func tg_dhpriv(x: *i64) -> i64 { return mse_gen_priv(x) } // CSPRNG per-connection key (nx_mse_wire) |
| 77 | func tg_mse_on() -> i64 { let f: i64 = sys_openat_rd("/volume1/ai/torrent/mse.on" as *u8); if f>=0 { sys_close(f); return 1 } return 0 } called by 1: tg_from_peer |
| 82 | func tg_multifile_total(meta: *u8, msize: i64, npc: i64, plen: i64) -> i64 |
| 112 | func tg_meta_total_of(metapath: *u8, npc: i64, plen: i64) -> i64 |
| 127 | func tg_build_wanted(meta: *u8, msize: i64, npc: i64, plen: i64, wanted: *u8, min_bytes: i64) -> i64 |
| 151 | func tg_wanted_min() -> i64 |
| 160 | func tg_read_msg(ctx: *MseCtx, fd: i64, mb: *u8, cap: i64) -> i64 |
| 170 | func tg_open_rw(path: *u8) -> i64 { return __syscall(SYS_OPENAT, AT_FDCWD, path as i64, 0x42, 0x1a4, 0, 0) } |
| 177 | func tg_pex_append(pexpath: *u8, ips: *i64, ports: *i64, cnt: i64) -> i64 |
| 199 | func tg_pex_merge(pexpath: *u8, ips: *i64, ports: *i64, have: i64, max: i64) -> i64 |
| 221 | func tg_ipf_filter(ips: *i64, ports: *i64, np: i64, arr: *i64, cnt: i64) -> i64 |
| 230 | func tg_stop(ctlpath: *u8) -> i64 |
| 241 | func tg_status(path: *u8, name: *u8, total: i64, done: i64, have: i64, npc: i64, peers: i64, state: *u8) -> i64 |
| 261 | func tg_stream_on(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } called by 1: tg_from_peer |
| 266 | func tg_seq_pick(donebits: *u8, peerbits: *u8, byte_len: i64, havebits: i64, inf: *i64, npc: i64) -> i64 |
| 293 | func tg_ppart_get(ppath: *u8, piece: i64) -> i64 |
| 301 | func tg_ppart_set(ppath: *u8, piece: i64, val: i64) -> i64 |
| 308 | func tg_ppart_flush(spath: *u8, ppath: *u8, piece: i64, plen: i64, pbuf: *u8, cprefix: i64) -> i64 |
| 316 | func tg_ppart_load(spath: *u8, piece: i64, plen: i64, pbuf: *u8, cprefix: i64) -> i64 |
| 324 | func tg_seed_hello(ctx: *MseCtx, fd: i64, lbits: *u8, npc: i64) -> i64 |
| 333 | func tg_from_peer(ipv: i64, port: i64, ih: *u8, mypid: *u8, outpath: *u8, donepath: *u8, npcpath: *u8, metapath: *u8, statpath: *u8, ctlpath: *u8, availpath: *u8, inflightpath: *u8, streampath: *u8, pexpath: *u8, peers: i64) -> i64 called by 2: mainmain calls 49: cl_sockaddrsys_socketsys_set_socket_timeoutnx_connect_boundedtg_mse_ontg_dhpriv+43 |
| 574 | func tg_http_one(host: *u8, port: i64, path: *u8, ih: *u8, pid: *u8, ips: *i64, ports: *i64, have: i64, max: i64) -> i64 |
| 592 | func tg_wide_to_pex(selfdir: *u8, outdir: *u8, ih: *u8, pid: *u8) -> i64 called by 1: tg_spawn_wide_announce calls 5: pm_bstrsys_readtl_next_lineht_announce_urltg_pex_append |
| 616 | func tg_spawn_wide_announce(selfdir: *u8, outdir: *u8, ih: *u8, pid: *u8) -> i64 |
| 634 | func tg_announce_all(ih: *u8, pid: *u8, ips: *i64, ports: *i64, max: i64) -> i64 |
| 668 | func tg_announce_bg(ihb: *u8, mypid: *u8, pexpath: *u8, slot: *i64, stbuf: *i64, ticks: i64) -> i64 |
| 699 | func tg_self_dir() -> *u8 |
| 718 | func tg_autoseed(outdir: *u8, ih: *u8, plen: i64, name: *u8, regpath: *u8) -> i64 |
| 748 | func tg_run_extract(outdir: *u8) -> i64 |
| 786 | func main(argc: i64, argv: *i64) -> i64 |