code wiki / _hdl_build / nx_roku_grid_remote_gate.nx
nx_roku_grid_remote_gate.nx source
↩ module page · 82 lines · 6086 B
1// nx_roku_grid_remote_gate.nx -- SOVEREIGN gate for nx_roku_grid_emit REMOTE mode (R1c). Drives the emitter with
2// `remote <baseurl>`, then re-proves (no python) that the channel is a real server-backed client: GridScene
3// fetches <baseurl>/catalog.json via roUrlTransfer + ParseJson and builds the grid from the live feed -- and is
4// NOT carrying the embedded catalog (no hardcoded titles). GREEN iff 10/10. Requires /tmp/nx_roku_grid_emit.sov.elf.
5// Durable knowledge/status/roku_grid_remote_gate.log. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_gate_emit_lib.nx"
8import "nx_opc.nx"
9
10func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
11func g_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
12func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
13func g_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
14func g_read(path: *u8, buf: *u8, cap: i64) -> i64 {
15 let fd: i64=sys_openat_rd(path); if fd<0 { return 0 }
16 var total: i64=0; var nrd: i64=sys_read(fd, buf, cap)
17 while nrd>0 { total=total+nrd; if total>=cap { nrd=0 } else { nrd=sys_read(fd, ((buf as i64)+total) as *u8, cap-total) } }
18 sys_close(fd); return total
19}
20func g_contains(hay: *u8, n: i64, needle: *u8) -> i64 {
21 let nl: i64=g_strlen(needle); if nl==0 { return 0 }
22 var i: i64=0
23 while i+nl<=n { var j: i64=0; var hit: i64=1; while j<nl { if hay[i+j]!=needle[j] { hit=0; j=nl } else { j=j+1 } } if hit==1 { return 1 } i=i+1 }
24 return 0
25}
26// LOCAL g_check DELETED 2026-09-04: nx_gate_emit_lib.nx already provides it, and carrying a
27// private copy beside the shared one is the duplicate-ruler defect -- here it was also a COMPILE
28// ERROR, so this gate had never built at all. Signatures are compatible ((*u8,i64)->i64, both
29// returning the condition), and there is no live output to preserve because it never ran.
30func g_run(elf: *u8, args: *i64, nargs: i64, out_path: *u8) -> i64 {
31 let pid: i64=sys_fork()
32 if pid==0 {
33 let o: i64=sys_openat_wr(out_path, 0x1a4); if o>=0 { sys_dup3(o,1,0) }
34 let argv: *i64=sys_mmap(8*16) as *i64; argv[0]=elf as i64
35 var i: i64=0; while i<nargs { argv[1+i]=args[i]; i=i+1 } argv[1+nargs]=0
36 let envp: *i64=sys_mmap(16) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0
37 sys_execve(elf, argv, envp); sys_exit(127)
38 }
39 let st: *i64=sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return (st[0]>>8)&0xff
40}
41func part_has(zip: *u8, part: *u8, needle: *u8) -> i64 {
42 let buf: *u8=sys_mmap(262144); let n: i64=opc_read_part(zip, part, buf, 262144)
43 if n<0 { return 0 } return g_contains(buf, n, needle)
44}
45
46func main() -> i64 {
47 g_puts("=== ROKU GRID REMOTE GATE: sovereign re-proof of the server-backed client (no python) ===\n" as *u8)
48 let EMIT: *u8="/tmp/nx_roku_grid_emit.sov.elf" as *u8
49 let BASE: *u8="https://nishifamily.com/roku" as *u8
50 let ZIP: *u8="/tmp/roku_grid_remote.zip" as *u8
51 let scr: *u8="/tmp/roku_grid_remote_scratch.txt" as *u8
52 let a: *i64=sys_mmap(8*8) as *i64
53 a[0]="remote" as *u8 as i64; a[1]=BASE as i64; a[2]=ZIP as i64
54 g_run(EMIT, a, 3, scr)
55
56 let zbuf: *u8=sys_mmap(524288); let zn: i64=g_read(ZIP, zbuf, 524288)
57 var zmagic: i64=0
58 if zn>=4 { if zbuf[0]==(0x50 as u8) { if zbuf[1]==(0x4b as u8) { if zbuf[2]==(0x03 as u8) { if zbuf[3]==(0x04 as u8) { zmagic=1 } } } } }
59 let xbuf: *u8=sys_mmap(64); let xn: i64=opc_read_part(ZIP, "does/not/exist" as *u8, xbuf, 64)
60
61 let GS: *u8="components/GridScene.xml" as *u8
62 var pass: i64=0; let rows: i64=10
63 pass=pass+g_check(" R1 valid ZIP (PK\\x03\\x04)" as *u8, zmagic)
64 pass=pass+g_check(" R2 part: components/GridScene.xml" as *u8, g_contains(zbuf,zn,"components/GridScene.xml" as *u8))
65 pass=pass+g_check(" R3 part: components/PosterItem.xml" as *u8, g_contains(zbuf,zn,"components/PosterItem.xml" as *u8))
66 pass=pass+g_check(" R4 GridScene -> roUrlTransfer (network client)" as *u8, part_has(ZIP,GS,"roUrlTransfer" as *u8))
67 pass=pass+g_check(" R5 GridScene -> fetches /catalog.json" as *u8, part_has(ZIP,GS,"/catalog.json" as *u8))
68 pass=pass+g_check(" R6 GridScene -> ParseJson (parses the feed)" as *u8, part_has(ZIP,GS,"ParseJson" as *u8))
69 pass=pass+g_check(" R7 GridScene -> baseurl baked in" as *u8, part_has(ZIP,GS,"https://nishifamily.com/roku" as *u8))
70 var feedok: i64=0; if part_has(ZIP,GS,"data.items" as *u8)==1 { if part_has(ZIP,GS,"HDPOSTERURL" as *u8)==1 { feedok=1 } }
71 pass=pass+g_check(" R8 GridScene -> iterates data.items into HDPOSTERURL" as *u8, feedok)
72 var noembed: i64=0; if part_has(ZIP,GS,"Sunrise" as *u8)==0 { noembed=1 }
73 pass=pass+g_check(" R9 LIAR-KILL: NO embedded catalog (truly remote)" as *u8, noembed)
74 var neg: i64=0; if xn<0 { neg=1 }
75 pass=pass+g_check(" R10 liar-kill: unknown part returns <0" as *u8, neg)
76
77 g_puts("----\nROKU-GRID-REMOTE rows=" as *u8); g_num(rows); g_puts(" pass=" as *u8); g_num(pass); g_puts(" zipbytes=" as *u8); g_num(zn); g_puts("\n" as *u8)
78 let lg: i64=sys_openat_append("knowledge/status/roku_grid_remote_gate.log" as *u8, 0x1a4)
79 if lg>=0 { g_w(lg, "ROKU-GRID-REMOTE rows=" as *u8); g_wn(lg, rows); g_w(lg, " pass=" as *u8); g_wn(lg, pass); if pass==rows { g_w(lg, " verdict=GREEN\n" as *u8) } else { g_w(lg, " verdict=RED\n" as *u8) } sys_close(lg) }
80 if pass==rows { g_puts("ROKU-GRID-REMOTE GREEN (sovereign server-backed catalog-fetch client proven without python)\n" as *u8); sys_exit(0); return 0 }
81 g_puts("ROKU-GRID-REMOTE RED\n" as *u8); sys_exit(1); return 1
82}