code wiki / (root) / nx_torrent_get.nx

nx_torrent_get.nx

buildroot/runtime/nx_torrent_get.nx

83401 B1016 linesdepth 8pulls 39 transitivereach 5 importersview sourcekind tooltopic torrent
docsdependenciesstructsconstsfunctions

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

nx_connect.nx nx_peer_piece_live.nx nx_magnet.nx nx_http_tracker.nx nx_dht_get_peers.nx nx_endgame.nx nx_pex.nx nx_tracker_list.nx nx_mse_wire.nx nx_ipfilter.nx nx_torrent_get.nx nx_pex_harvest_gate.nx nx_tg_autoseed_gate.nx nx_tg_mftotal_gate.nx nx_tg_wanted_gate.nx nx_unchoke_gate.nx

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

main sys_mkdir pm_bstr sys_openat_wr sys_flock mg_parse mg_len mg_starts mg_len ↻ mg_keyeq mg_len ↻ mg_decode_btih mg_hexval mg_b32val sys_mmap mg_urldecode mg_hexval ↻ tg_status sys_openat_wr ↻ tg_announce_all cl_announce nx_dns_a_resolve sys_socket sys_set_socket_timeout sys_mmap ↻ sys_setsockopt sys_munmap sys_mmap ↻ da_sockaddr da_build_query da_qname sys_sendto sys_close sys_recvfrom da_parse da_u16 da_skip_name sys_socket ↻ sys_set_socket_timeout ↻ cl_sockaddr

structs

none

consts

22const TG_MAGIC_1410: i64 = 1410
23const TG_MAGIC_1450: i64 = 1450
24const TG_MAGIC_1024: i64 = 1024
25const TG_MAGIC_15728640: i64 = 15728640
26const TG_MAGIC_65536: i64 = 65536
27const TG_MAGIC_262144: i64 = 262144
28const TG_MAGIC_40000: i64 = 40000
32const TG_SLOT_COOLDOWN: i64 = 2
36const TG_CONNECT_MS: i64 = 6000
41const TG_ANN_MAX_TICKS: i64 = 45
42const TG_MAGIC_2000000: i64 = 2000000
43const TG_MAGIC_2000000: i64 = 2000000
44const TG_MAGIC_16383: i64 = 16383
45const TG_MAGIC_16384: i64 = 16384
46const TG_MAGIC_1000000000: i64 = 1000000000
47const TG_MAGIC_65535: i64 = 65535
48const TG_MAGIC_1337: i64 = 1337
49const TG_MAGIC_262143: i64 = 262143
50const TG_MAGIC_80000: i64 = 80000
51const TG_MAGIC_2000: i64 = 2000
57const TG_ENDGAME_THRESHOLD: i64 = 16
63const TG_UNCHOKE_WAIT: i64 = 90
71const TG_DATA_TIMEOUT: i64 = 30

functions

74func tg_dhpriv(x: *i64) -> i64 { return mse_gen_priv(x) } // CSPRNG per-connection key (nx_mse_wire)
called by 1: tg_from_peer calls 1: mse_gen_priv
77func 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
82func tg_multifile_total(meta: *u8, msize: i64, npc: i64, plen: i64) -> i64
112func tg_meta_total_of(metapath: *u8, npc: i64, plen: i64) -> i64
127func tg_build_wanted(meta: *u8, msize: i64, npc: i64, plen: i64, wanted: *u8, min_bytes: i64) -> i64
151func tg_wanted_min() -> i64
160func tg_read_msg(ctx: *MseCtx, fd: i64, mb: *u8, cap: i64) -> i64
170func tg_open_rw(path: *u8) -> i64 { return __syscall(SYS_OPENAT, AT_FDCWD, path as i64, 0x42, 0x1a4, 0, 0) }
177func tg_pex_append(pexpath: *u8, ips: *i64, ports: *i64, cnt: i64) -> i64
199func tg_pex_merge(pexpath: *u8, ips: *i64, ports: *i64, have: i64, max: i64) -> i64
called by 2: mainmain calls 1: sys_read
221func tg_ipf_filter(ips: *i64, ports: *i64, np: i64, arr: *i64, cnt: i64) -> i64
called by 1: main calls 1: ipf_blocked
230func tg_stop(ctlpath: *u8) -> i64
called by 2: tg_from_peermain calls 1: sys_read
241func tg_status(path: *u8, name: *u8, total: i64, done: i64, have: i64, npc: i64, peers: i64, state: *u8) -> i64
called by 2: tg_from_peermain calls 1: sys_openat_wr
261func 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
266func tg_seq_pick(donebits: *u8, peerbits: *u8, byte_len: i64, havebits: i64, inf: *i64, npc: i64) -> i64
called by 1: tg_from_peer calls 1: nx_pw_bitfield_has
293func tg_ppart_get(ppath: *u8, piece: i64) -> i64
called by 1: tg_from_peer calls 1: sys_read
301func tg_ppart_set(ppath: *u8, piece: i64, val: i64) -> i64
308func tg_ppart_flush(spath: *u8, ppath: *u8, piece: i64, plen: i64, pbuf: *u8, cprefix: i64) -> i64
316func tg_ppart_load(spath: *u8, piece: i64, plen: i64, pbuf: *u8, cprefix: i64) -> i64
called by 1: tg_from_peer calls 1: sys_read
324func tg_seed_hello(ctx: *MseCtx, fd: i64, lbits: *u8, npc: i64) -> i64
333func 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
574func tg_http_one(host: *u8, port: i64, path: *u8, ih: *u8, pid: *u8, ips: *i64, ports: *i64, have: i64, max: i64) -> i64
called by 1: tg_announce_all calls 1: ht_announce
592func tg_wide_to_pex(selfdir: *u8, outdir: *u8, ih: *u8, pid: *u8) -> i64
616func tg_spawn_wide_announce(selfdir: *u8, outdir: *u8, ih: *u8, pid: *u8) -> i64
634func tg_announce_all(ih: *u8, pid: *u8, ips: *i64, ports: *i64, max: i64) -> i64
668func tg_announce_bg(ihb: *u8, mypid: *u8, pexpath: *u8, slot: *i64, stbuf: *i64, ticks: i64) -> i64
699func tg_self_dir() -> *u8
718func tg_autoseed(outdir: *u8, ih: *u8, plen: i64, name: *u8, regpath: *u8) -> i64
748func tg_run_extract(outdir: *u8) -> i64
786func main(argc: i64, argv: *i64) -> i64