code wiki / _hdl_build / nx_torrent_gateway.nx
nx_torrent_gateway.nx
buildroot/runtime/_hdl_build/nx_torrent_gateway.nx
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
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
structs
| none |
consts
| 14 | const TGW_MAGIC_1024: i64 = 1024 |
| 15 | const TGW_MAGIC_262144: i64 = 262144 |
| 16 | const TGW_MAGIC_65536: i64 = 65536 |
| 17 | const TGW_MAGIC_131072: i64 = 131072 |
| 18 | const TGW_MAGIC_2048: i64 = 2048 |
| 19 | const TGW_MAGIC_1280: i64 = 1280 |
| 111 | const 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 — 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
| 21 | func 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 |
| 22 | func 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 } |
| 23 | func 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 } |
| 24 | func tg_itoa(dst: *u8, o: i64, v: i64) -> i64 |
| 33 | func tg_reqpath(req: *u8, n: i64, out: *u8, cap: i64) -> i64 called by 1: main |
| 42 | func tg_method(req: *u8, n: i64, out: *u8, cap: i64) -> i64 called by 1: main |
| 50 | func tg_backend_req(method: *u8, mlen: i64, path: *u8, plen: i64, level: i64, rng: *u8, rngn: i64, body: *u8, blen: i64, out: *u8) -> i64 |
| 69 | func tg_path_public(path: *u8, plen: i64) -> i64 |
| 75 | func tg_gate_decision(path: *u8, plen: i64, level: i64) -> i64 |
| 82 | func tg_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64 |
| 93 | func tg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 96 | func tg_proxy(cfd: i64, bport: i64, breq: *u8, breqn: i64) -> i64 called by 1: main calls 7: sys_socketsys_set_socket_timeoutsys_mmapnx_connect_boundedsys_closesys_write+1 |
| 113 | func main(argc: i64, argv: *i64) -> i64 |