code wiki / _hdl_build / nx_torrent_gateway.nx

nx_torrent_gateway.nx

buildroot/runtime/_hdl_build/nx_torrent_gateway.nx

13995 B206 linesdepth 17pulls 49 transitivereach 1 importersview sourcekind tooltopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_gateway.nx -- R3c: the FRONT GATEWAY that puts /torrent on the hub, GATED. Mirrors the proven nx_gallery_gateway: OPAQUE login (full RFC-9807 aPAKE, no plaintext at rest) + cookie/SW token transport, then per request it resolves the viewer's LEVEL via nx_torrent_authn (tau_level) and reverse-proxies to the lean torrent daemon (127.0.0.1:bport) -- INJECTING the level as the trusted internal header X-Nishi-Level. SECURITY KEYSTONE: the backend request is built FRESH (method + path + OUR X-Nishi-Level + Range + body), so a client-supplied X-Nishi-Level is DROPPED -- the level is authoritative from the validated session, never from client input. No valid session on a gated path -> 401 (no content). The daemon binds localhost behind this gateway (Cardinal 12). The realm keys/store + roles registry are the HUB realm (operator-provisioned). license_tier: ORIGINAL

dependencies 4 imports · 1 importers

nx_torrent_authn.nx nx_opaque_login.nx nx_connect.nx nx_syscalls.nx nx_torrent_gateway.nx nx_torrent_gateway_gate.nx

imports: nx_torrent_authn.nxnx_opaque_login.nxnx_connect.nxnx_syscalls.nx

imported by: nx_torrent_gateway_gate.nx

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

main sys_write sys_exit tg_atoi tg_slen sys_mmap olg_ctx_setup olg_ctx_setup_ttl nx_uas_server_keys_load_or sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close _uas_hex_dec _uas_nib nx_csprng_fill sys_mmap ↻ nx_csprng_urandom_path sys_openat_rd ↻ sys_read ↻ sys_close ↻ nx_opq_derive_keypair sys_mmap ↻ _voprf_load_context_string u256_alloc nx_scratch nx_opq_hash_to_scalar sys_mmap ↻ nx_h2c_expand_message_xmd_ u256_alloc ↻ _opq_reduce_48be_mod_n u256_store_be u256_load_be u256_is_zero p256_point_alloc nx_scratch ↻ u256_alloc ↻

structs

none

consts

14const TGW_MAGIC_1024: i64 = 1024
15const TGW_MAGIC_262144: i64 = 262144
16const TGW_MAGIC_65536: i64 = 65536
17const TGW_MAGIC_131072: i64 = 131072
18const TGW_MAGIC_2048: i64 = 2048
19const TGW_MAGIC_1280: i64 = 1280
111const TGW_LOGIN_HTML: *u8 = "<!doctype html><html><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>Nishi Torrent</title><style>body{font-family:system-ui,sans-serif;max-width:420px;margin:8vh auto;padding:0 18px;color:#cdd7e6;background:#0b1019}h1{font-size:1.2rem;color:#e8eef7}input{width:100%;padding:9px;margin:5px 0;box-sizing:border-box;border:1px solid #2a3550;border-radius:5px;background:#121a28;color:#e8eef7}button{padding:9px 16px;margin:6px 6px 0 0;background:#2d6cdf;color:#fff;border:0;border-radius:5px;cursor:pointer}#m{margin:14px 0;padding:12px;background:#121a28;border-left:3px solid #2d6cdf;word-break:break-all;min-height:1.2em}</style></head><body><h1>Nishi Torrent &mdash; sign in</h1><div id=m>Log in to manage downloads.</div><input id=h placeholder=handle autocomplete=username><input id=p type=password placeholder=passphrase autocomplete=current-password><button onclick=login()>Login</button><script>function $(i){return document.getElementById(i)}function M(t){$('m').textContent=t}async function login(){M('Logging in...');try{var r=await fetch('/torrent/auth/login',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'handle='+encodeURIComponent($('h').value)+'&pw='+encodeURIComponent($('p').value)});var j=await r.json();if(!r.ok){M('Login failed: '+(j.error||r.status));return}M('Logged in. Opening...');location.href='/torrent/'}catch(e){M('error: '+e)}}</script></body></html>" as *u8

functions

21func tg_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c<48 {i=i+1} else { if c>57 {i=i+1} else { v=v*10+(c-48); i=i+1 } } } return v }
called by 1: main
22func tg_cat(dst: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[o+i]=s[i]; i=i+1 } return o+i }
23func tg_catb(dst: *u8, o: i64, s: *u8, n: i64) -> i64 { var i: i64=0; while i<n { dst[o+i]=s[i]; i=i+1 } return o+i }
called by 2: tg_backend_reqmain
24func tg_itoa(dst: *u8, o: i64, v: i64) -> i64
called by 3: tg_backend_reqtg_sendmain calls 1: sys_mmap
33func tg_reqpath(req: *u8, n: i64, out: *u8, cap: i64) -> i64
called by 1: main
42func tg_method(req: *u8, n: i64, out: *u8, cap: i64) -> i64
called by 1: main
50func tg_backend_req(method: *u8, mlen: i64, path: *u8, plen: i64, level: i64, rng: *u8, rngn: i64, body: *u8, blen: i64, out: *u8) -> i64
called by 2: mainmain calls 3: tg_catbtg_cattg_itoa
69func tg_path_public(path: *u8, plen: i64) -> i64
called by 2: tg_gate_decisionmain calls 1: tau_find
75func tg_gate_decision(path: *u8, plen: i64, level: i64) -> i64
called by 2: mainmain calls 1: tg_path_public
82func tg_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64
93func tg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
96func tg_proxy(cfd: i64, bport: i64, breq: *u8, breqn: i64) -> i64
113func main(argc: i64, argv: *i64) -> i64