code wiki / (root) / nx_torrent_daemon.nx

nx_torrent_daemon.nx

buildroot/runtime/nx_torrent_daemon.nx

88825 B1473 linesdepth 5pulls 10 transitivereach 2 importersview sourcekind servicetopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_daemon.nx -- the UI enabler (X-TORRENT-UI-001): an HTTP daemon that serves the operator's torrent page and wires it to the LIVE download worker. GET /torrent -> sites/nishifamily/torrent/index.html GET /torrent/app.js -> the page's last-mile JS (renders REAL state only) GET /torrent/api/me -> {"user":"local"} (local single-operator) POST /torrent/api/login -> {"ok":true} POST /torrent/api/add {magnet} -> fork+execve the worker elf -> {"id":"1"} GET /torrent/api/status -> reads outdir/download.status -> {downloads:[...]} POST /torrent/api/<id>/<action> -> {"ok":true} (pause/resume/remove noop) Sovereign: composes nx_http_server (bind/listen/accept) + the worker elf the team already built. NO mocked numbers -- /status emits exactly what the worker wrote to disk; before any download the worker file is absent -> {downloads:[]} (honest empty). license_tier: ORIGINAL kind: last-mile-ui-bridge layer: L6 (over L4 http + L5 worker) module: nishi-core.torrent.daemon depends: nishi-core.http_server, nishi-core.syscalls

dependencies 6 imports · 2 importers

nx_http_server.nx nx_syscalls.nx nx_itoa_lib.nx nx_bencode.nx nx_torrent_access.nx nx_ioadmit_lib.nx nx_torrent_daemon.nx nx_torrent_area_gate.nx nx_torrent_stream_gate.nx

imports: nx_http_server.nxnx_syscalls.nxnx_itoa_lib.nxnx_bencode.nxnx_torrent_access.nxnx_ioadmit_lib.nx

imported by: nx_torrent_area_gate.nxnx_torrent_stream_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main d_path d_puts sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_mkdir nx_http_server_addr_any nx_http_server_make_sockad d_streq sys_write ↻ d_strlen nx_http_server_listen sys_ignore_sigpipe sys_mmap ↻ sys_socket sys_mmap ↻ sys_setsockopt sys_bind sys_close sys_listen sys_exit ↻

structs

none

consts

25const TORRENT_MAGIC_131072: i64 = 131072
26const TORRENT_MAGIC_1024: i64 = 1024
27const TORRENT_MAGIC_8192: i64 = 8192
28const TORRENT_MAGIC_262144: i64 = 262144
29const TORRENT_MAGIC_4000: i64 = 4000
30const TORRENT_MAGIC_2000: i64 = 2000
31const TORRENT_MAGIC_1048576: i64 = 1048576
32const TORRENT_MAGIC_4096: i64 = 4096
33const TORRENT_MAGIC_4095: i64 = 4095
34const TORRENT_MAGIC_16384: i64 = 16384
35const TORRENT_MAGIC_4200: i64 = 4200
36const TORRENT_MAGIC_8097: i64 = 8097
37const TORRENT_MAGIC_1000000000: i64 = 1000000000
44const TORRENT_LOCAL_MARKER: *u8 = "/mnt/c/Users/elder/Downloads/nishi-torrents/.local_operator"
49const D_RETRY_INTERVAL_MS: i64 = 600000
67const D_ADMIT_CONF: *u8 = "/torrent_admit.conf"
68const D_ADMIT_CONF_CAP: i64 = 4096 // a few `key value` rows; rm_read reports a full cap as its length
69const D_ADMIT_KEY_MAXW: *u8 = "max_workers"
70const D_WORKER_COMM: *u8 = "nx_torrent_get.sov.elf" // matched on its first IOA_COMM_MAX bytes, as the kernel truncates comm
71const D_UNOBS_SPAWNS: i64 = 1
72const D_QUEUED_STATUS: *u8 = "state=queued-io\n" // written ONLY when no status file exists yet (a first add that was deferred)
75const D_BUD_LEFT: i64 = 0
76const D_BUD_NCPU: i64 = 1
77const D_BUD_BLK: i64 = 2
78const D_BUD_LIVE: i64 = 3
79const D_BUD_MAXW: i64 = 4
80const D_BUD_SPAWNED: i64 = 5
81const D_BUD_DEFERRED: i64 = 6
82const D_BUD_CELLS: i64 = 8
83const D_BUD_BYTES: i64 = 64 // D_BUD_CELLS x 8
126const D_STAT_SIZE_OFF: i64 = 48

functions

86func d_strlen(s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){i=i+1} return i }
88func d_puts(dst: *u8, off: i64, s: *u8) -> i64
98func d_putn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) }
101func d_read_file(path: *u8, buf: *u8, cap: i64) -> i64
127func d_idx_load(idxpath: *u8, lenout: *i64) -> *u8
137func d_idx_free(b: *u8, n: i64) -> i64 { if (b as i64) != 0 { sys_free_file(b, n) } return 0 }
called by 2: d_idx_addd_autoresume calls 1: sys_free_file
140func d_path(outdir: *u8, suf: *u8, out: *u8) -> *u8
147func d_write_file(path: *u8, s: *u8, n: i64) -> i64
156func d_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64
168func d_send_str(cfd: i64, status: *u8, ctype: *u8, s: *u8) -> i64
171func d_serve_file(cfd: i64, path: *u8, ctype: *u8) -> i64
180func d_streq(buf: *u8, off: i64, len: i64, s: *u8) -> i64
called by 2: d_routemain
190func d_starts(buf: *u8, off: i64, len: i64, s: *u8) -> i64
called by 1: d_route
203func d_extract_magnet(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64
called by 1: d_route
227func d_has_progress(outdir: *u8) -> i64
240func d_close_inherited() -> i64
249func d_self_dir() -> *u8
263func d_admit_budget(owner_root: *u8, bud: *i64) -> i64
289func d_admit_log(tag: *u8, bud: *i64) -> i64
306func d_spawn_worker(magnet: *u8, outdir: *u8, resume: i64, bud: *i64) -> i64
332func d_spawn_admitted(magnet: *u8, outdir: *u8, resume: i64, owner_root: *u8, tag: *u8) -> i64
341func d_find_val(buf: *u8, n: i64, key: *u8) -> i64
352func d_int_at(buf: *u8, n: i64, pos: i64) -> i64
363func d_copy_line(buf: *u8, n: i64, pos: i64, out: *u8, ocap: i64) -> i64
378func d_status(cfd: i64, statpath: *u8, ctlpath: *u8) -> i64
420func d_extract_url(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64
called by 1: d_route
444func d_spawn_discover(url: *u8, dpath: *u8) -> i64
463func d_url_referer(url: *u8, out: *u8) -> *u8
called by 1: d_route
478func d_spawn_video(url: *u8, outpath: *u8, referer: *u8) -> i64
489func d_spawn_hls(url: *u8, outpath: *u8, referer: *u8) -> i64
500func d_is_hls(url: *u8) -> i64
called by 1: d_route
518func d_hls_outname(url: *u8, outdir: *u8, out: *u8) -> *u8
called by 1: d_route calls 1: d_puts
534func d_vidname(url: *u8, outdir: *u8, out: *u8) -> *u8
called by 1: d_route calls 1: d_puts
546func d_scan_to(buf: *u8, n: i64, from: i64, delim: i64) -> i64
551func d_json_buf(dst: *u8, off: i64, src: *u8, from: i64, to: i64) -> i64
562func d_raw_buf(dst: *u8, off: i64, src: *u8, from: i64, to: i64) -> i64
called by 1: d_discover_result
568func d_discover_result(cfd: i64, dpath: *u8) -> i64
616func d_extract_btih(mag: *u8, n: i64, out: *u8, ocap: i64) -> i64
636func d_hexv(c: i64) -> i64
645func d_extract_name(mag: *u8, n: i64, out: *u8, ocap: i64) -> i64
called by 1: d_route calls 1: d_hexv
676func d_subdir(outdir: *u8, id: *u8, dir: *u8) -> *u8
680func d_ends(buf: *u8, off: i64, len: i64, suf: *u8) -> i64
called by 1: d_route calls 1: d_strlen
688func d_idx_has(buf: *u8, n: i64, id: *u8) -> i64
699func d_idx_add(idxpath: *u8, id: *u8) -> i64
713func d_idx_remove(idxpath: *u8, id: *u8) -> i64
730func d_status_one(out: *u8, o0: i64, id: *u8, dir: *u8) -> i64
761func d_status_all(cfd: i64, outdir: *u8, idxpath: *u8) -> i64
796func d_video_extent(meta: *u8, msize: i64, out: *i64) -> i64
815func d_contig_bytes(dir: *u8) -> i64
833func d_form_magnet(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64
called by 1: d_route calls 1: d_hexv
862func d_filesize(path: *u8) -> i64
called by 1: d_stream calls 2: sys_mmapsys_fstatat
869func d_have_npc(dir: *u8, out: *i64) -> i64
883func d_parse_range(req: *u8, rn: i64, out: *i64) -> i64
called by 2: d_streammain
900func d_stream(cfd: i64, req: *u8, rn: i64, dir: *u8) -> i64
992func d_find_by_btih(outdir: *u8, idxpath: *u8, btih: *u8, btn: i64, out_id: *u8, ocap: i64) -> i64
1031func d_autoresume(outdir: *u8, idxpath: *u8, bud: *i64, rot: i64) -> i64
1098func d_buf_find(buf: *u8, n: i64, pat: *u8) -> i64
called by 1: d_parse_area calls 1: d_strlen
1112func d_parse_area(req: *u8, n: i64) -> i64
called by 2: maind_route calls 1: d_buf_find
1118func d_marker_present(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
1120func d_trusted_level(req: *u8, n: i64) -> i64
called by 1: d_viewer_level
1137func d_viewer_level(req: *u8, n: i64) -> i64
1146func d_resolve_dir(id: *u8, level: i64, sfw_root: *u8, sfw_idx: *u8, nsfw_root: *u8, nsfw_idx: *u8, out_dir: *u8, out_area: *i64) -> i64
1156func d_status_root(out: *u8, o0: i64, first_p: *i64, root: *u8, idxpath: *u8) -> i64
1182func d_status_two(cfd: i64, level: i64, sfw_root: *u8, sfw_idx: *u8, nsfw_root: *u8, nsfw_idx: *u8) -> i64
1194func d_route(cfd: i64, req: *u8, method: i64, po: i64, pl: i64, cl_: i64, bo: i64, rn: i64,
1354func main(argc: i64, argv: *i64) -> i64