nx_torrent_daemon.nx
buildroot/runtime/nx_torrent_daemon.nx
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
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
structs
| none |
consts
| 25 | const TORRENT_MAGIC_131072: i64 = 131072 |
| 26 | const TORRENT_MAGIC_1024: i64 = 1024 |
| 27 | const TORRENT_MAGIC_8192: i64 = 8192 |
| 28 | const TORRENT_MAGIC_262144: i64 = 262144 |
| 29 | const TORRENT_MAGIC_4000: i64 = 4000 |
| 30 | const TORRENT_MAGIC_2000: i64 = 2000 |
| 31 | const TORRENT_MAGIC_1048576: i64 = 1048576 |
| 32 | const TORRENT_MAGIC_4096: i64 = 4096 |
| 33 | const TORRENT_MAGIC_4095: i64 = 4095 |
| 34 | const TORRENT_MAGIC_16384: i64 = 16384 |
| 35 | const TORRENT_MAGIC_4200: i64 = 4200 |
| 36 | const TORRENT_MAGIC_8097: i64 = 8097 |
| 37 | const TORRENT_MAGIC_1000000000: i64 = 1000000000 |
| 44 | const TORRENT_LOCAL_MARKER: *u8 = "/mnt/c/Users/elder/Downloads/nishi-torrents/.local_operator" |
| 49 | const D_RETRY_INTERVAL_MS: i64 = 600000 |
| 67 | const D_ADMIT_CONF: *u8 = "/torrent_admit.conf" |
| 68 | const D_ADMIT_CONF_CAP: i64 = 4096 // a few `key value` rows; rm_read reports a full cap as its length |
| 69 | const D_ADMIT_KEY_MAXW: *u8 = "max_workers" |
| 70 | const D_WORKER_COMM: *u8 = "nx_torrent_get.sov.elf" // matched on its first IOA_COMM_MAX bytes, as the kernel truncates comm |
| 71 | const D_UNOBS_SPAWNS: i64 = 1 |
| 72 | const D_QUEUED_STATUS: *u8 = "state=queued-io\n" // written ONLY when no status file exists yet (a first add that was deferred) |
| 75 | const D_BUD_LEFT: i64 = 0 |
| 76 | const D_BUD_NCPU: i64 = 1 |
| 77 | const D_BUD_BLK: i64 = 2 |
| 78 | const D_BUD_LIVE: i64 = 3 |
| 79 | const D_BUD_MAXW: i64 = 4 |
| 80 | const D_BUD_SPAWNED: i64 = 5 |
| 81 | const D_BUD_DEFERRED: i64 = 6 |
| 82 | const D_BUD_CELLS: i64 = 8 |
| 83 | const D_BUD_BYTES: i64 = 64 // D_BUD_CELLS x 8 |
| 126 | const D_STAT_SIZE_OFF: i64 = 48 |
functions
| 86 | func d_strlen(s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){i=i+1} return i } |
| 88 | func d_puts(dst: *u8, off: i64, s: *u8) -> i64 |
| 98 | func d_putn(dst: *u8, off: i64, v: i64) -> i64 { return nxi_buf(dst, off, v) } |
| 101 | func d_read_file(path: *u8, buf: *u8, cap: i64) -> i64 called by 11: d_serve_filed_statusd_discover_resultd_status_oned_contig_bytesd_have_npc+5 calls 3: sys_openat_rdsys_readsys_close |
| 127 | func d_idx_load(idxpath: *u8, lenout: *i64) -> *u8 |
| 137 | func d_idx_free(b: *u8, n: i64) -> i64 { if (b as i64) != 0 { sys_free_file(b, n) } return 0 } |
| 140 | func d_path(outdir: *u8, suf: *u8, out: *u8) -> *u8 called by 14: d_admit_budgetd_spawn_workerd_spawn_discoverd_spawn_videod_spawn_hlsd_status_one+8 calls 1: d_puts |
| 147 | func d_write_file(path: *u8, s: *u8, n: i64) -> i64 |
| 156 | func d_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64 |
| 168 | func d_send_str(cfd: i64, status: *u8, ctype: *u8, s: *u8) -> i64 |
| 171 | func d_serve_file(cfd: i64, path: *u8, ctype: *u8) -> i64 |
| 180 | func d_streq(buf: *u8, off: i64, len: i64, s: *u8) -> i64 |
| 190 | func d_starts(buf: *u8, off: i64, len: i64, s: *u8) -> i64 called by 1: d_route |
| 203 | func d_extract_magnet(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64 called by 1: d_route |
| 227 | func d_has_progress(outdir: *u8) -> i64 |
| 240 | func d_close_inherited() -> i64 |
| 249 | func d_self_dir() -> *u8 |
| 263 | func d_admit_budget(owner_root: *u8, bud: *i64) -> i64 called by 1: d_spawn_admitted calls 6: sys_mmapioa_measureioa_spawn_budgetd_pathrm_confioa_count_comm_roots |
| 289 | func d_admit_log(tag: *u8, bud: *i64) -> i64 |
| 306 | func d_spawn_worker(magnet: *u8, outdir: *u8, resume: i64, bud: *i64) -> i64 called by 2: d_spawn_admittedd_autoresume calls 12: d_pathsys_mmapsys_openat_rdd_write_filed_strlensys_close+6 |
| 332 | func d_spawn_admitted(magnet: *u8, outdir: *u8, resume: i64, owner_root: *u8, tag: *u8) -> i64 |
| 341 | func d_find_val(buf: *u8, n: i64, key: *u8) -> i64 |
| 352 | func d_int_at(buf: *u8, n: i64, pos: i64) -> i64 |
| 363 | func d_copy_line(buf: *u8, n: i64, pos: i64, out: *u8, ocap: i64) -> i64 |
| 378 | func d_status(cfd: i64, statpath: *u8, ctlpath: *u8) -> i64 |
| 420 | func d_extract_url(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64 called by 1: d_route |
| 444 | func d_spawn_discover(url: *u8, dpath: *u8) -> i64 |
| 463 | func d_url_referer(url: *u8, out: *u8) -> *u8 called by 1: d_route |
| 478 | func d_spawn_video(url: *u8, outpath: *u8, referer: *u8) -> i64 |
| 489 | func d_spawn_hls(url: *u8, outpath: *u8, referer: *u8) -> i64 |
| 500 | func d_is_hls(url: *u8) -> i64 called by 1: d_route |
| 518 | func d_hls_outname(url: *u8, outdir: *u8, out: *u8) -> *u8 |
| 534 | func d_vidname(url: *u8, outdir: *u8, out: *u8) -> *u8 |
| 546 | func d_scan_to(buf: *u8, n: i64, from: i64, delim: i64) -> i64 |
| 551 | func d_json_buf(dst: *u8, off: i64, src: *u8, from: i64, to: i64) -> i64 |
| 562 | func d_raw_buf(dst: *u8, off: i64, src: *u8, from: i64, to: i64) -> i64 called by 1: d_discover_result |
| 568 | func d_discover_result(cfd: i64, dpath: *u8) -> i64 |
| 616 | func d_extract_btih(mag: *u8, n: i64, out: *u8, ocap: i64) -> i64 |
| 636 | func d_hexv(c: i64) -> i64 |
| 645 | func d_extract_name(mag: *u8, n: i64, out: *u8, ocap: i64) -> i64 |
| 676 | func d_subdir(outdir: *u8, id: *u8, dir: *u8) -> *u8 called by 6: d_status_alld_find_by_btihd_autoresumed_resolve_dird_status_rootd_route calls 1: d_puts |
| 680 | func d_ends(buf: *u8, off: i64, len: i64, suf: *u8) -> i64 |
| 688 | func d_idx_has(buf: *u8, n: i64, id: *u8) -> i64 |
| 699 | func d_idx_add(idxpath: *u8, id: *u8) -> i64 |
| 713 | func d_idx_remove(idxpath: *u8, id: *u8) -> i64 |
| 730 | func d_status_one(out: *u8, o0: i64, id: *u8, dir: *u8) -> i64 called by 2: d_status_alld_status_root calls 10: d_pathsys_mmapd_read_filed_int_atd_find_vald_copy_line+4 |
| 761 | func d_status_all(cfd: i64, outdir: *u8, idxpath: *u8) -> i64 |
| 796 | func d_video_extent(meta: *u8, msize: i64, out: *i64) -> i64 |
| 815 | func d_contig_bytes(dir: *u8) -> i64 |
| 833 | func d_form_magnet(body: *u8, blen: i64, out: *u8, ocap: i64) -> i64 |
| 862 | func d_filesize(path: *u8) -> i64 |
| 869 | func d_have_npc(dir: *u8, out: *i64) -> i64 |
| 883 | func d_parse_range(req: *u8, rn: i64, out: *i64) -> i64 |
| 900 | func d_stream(cfd: i64, req: *u8, rn: i64, dir: *u8) -> i64 |
| 992 | func d_find_by_btih(outdir: *u8, idxpath: *u8, btih: *u8, btn: i64, out_id: *u8, ocap: i64) -> i64 |
| 1031 | func d_autoresume(outdir: *u8, idxpath: *u8, bud: *i64, rot: i64) -> i64 |
| 1098 | func d_buf_find(buf: *u8, n: i64, pat: *u8) -> i64 |
| 1112 | func d_parse_area(req: *u8, n: i64) -> i64 |
| 1118 | func d_marker_present(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } |
| 1120 | func d_trusted_level(req: *u8, n: i64) -> i64 called by 1: d_viewer_level |
| 1137 | func d_viewer_level(req: *u8, n: i64) -> i64 |
| 1146 | func 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 |
| 1156 | func d_status_root(out: *u8, o0: i64, first_p: *i64, root: *u8, idxpath: *u8) -> i64 |
| 1182 | func d_status_two(cfd: i64, level: i64, sfw_root: *u8, sfw_idx: *u8, nsfw_root: *u8, nsfw_idx: *u8) -> i64 |
| 1194 | func d_route(cfd: i64, req: *u8, method: i64, po: i64, pl: i64, cl_: i64, bo: i64, rn: i64, |
| 1354 | func main(argc: i64, argv: *i64) -> i64 |