code wiki / _hdl_build / nx_roku_grid_remote_gate.nx

nx_roku_grid_remote_gate.nx source

↩ module page · 79 lines · 5852 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} 26func g_check(label: *u8, ok: i64) -> i64 { g_puts(label); if ok==1 { g_puts(" PASS\n" as *u8); return 1 } g_puts(" FAIL\n" as *u8); return 0 } 27func g_run(elf: *u8, args: *i64, nargs: i64, out_path: *u8) -> i64 { 28 let pid: i64=sys_fork() 29 if pid==0 { 30 let o: i64=sys_openat_wr(out_path, 0x1a4); if o>=0 { sys_dup3(o,1,0) } 31 let argv: *i64=sys_mmap(8*16) as *i64; argv[0]=elf as i64 32 var i: i64=0; while i<nargs { argv[1+i]=args[i]; i=i+1 } argv[1+nargs]=0 33 let envp: *i64=sys_mmap(16) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0 34 sys_execve(elf, argv, envp); sys_exit(127) 35 } 36 let st: *i64=sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return (st[0]>>8)&0xff 37} 38func part_has(zip: *u8, part: *u8, needle: *u8) -> i64 { 39 let buf: *u8=sys_mmap(262144); let n: i64=opc_read_part(zip, part, buf, 262144) 40 if n<0 { return 0 } return g_contains(buf, n, needle) 41} 42 43func main() -> i64 { 44 g_puts("=== ROKU GRID REMOTE GATE: sovereign re-proof of the server-backed client (no python) ===\n" as *u8) 45 let EMIT: *u8="/tmp/nx_roku_grid_emit.sov.elf" as *u8 46 let BASE: *u8="https://nishifamily.com/roku" as *u8 47 let ZIP: *u8="/tmp/roku_grid_remote.zip" as *u8 48 let scr: *u8="/tmp/roku_grid_remote_scratch.txt" as *u8 49 let a: *i64=sys_mmap(8*8) as *i64 50 a[0]="remote" as *u8 as i64; a[1]=BASE as i64; a[2]=ZIP as i64 51 g_run(EMIT, a, 3, scr) 52 53 let zbuf: *u8=sys_mmap(524288); let zn: i64=g_read(ZIP, zbuf, 524288) 54 var zmagic: i64=0 55 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 } } } } } 56 let xbuf: *u8=sys_mmap(64); let xn: i64=opc_read_part(ZIP, "does/not/exist" as *u8, xbuf, 64) 57 58 let GS: *u8="components/GridScene.xml" as *u8 59 var pass: i64=0; let rows: i64=10 60 pass=pass+g_check(" R1 valid ZIP (PK\\x03\\x04)" as *u8, zmagic) 61 pass=pass+g_check(" R2 part: components/GridScene.xml" as *u8, g_contains(zbuf,zn,"components/GridScene.xml" as *u8)) 62 pass=pass+g_check(" R3 part: components/PosterItem.xml" as *u8, g_contains(zbuf,zn,"components/PosterItem.xml" as *u8)) 63 pass=pass+g_check(" R4 GridScene -> roUrlTransfer (network client)" as *u8, part_has(ZIP,GS,"roUrlTransfer" as *u8)) 64 pass=pass+g_check(" R5 GridScene -> fetches /catalog.json" as *u8, part_has(ZIP,GS,"/catalog.json" as *u8)) 65 pass=pass+g_check(" R6 GridScene -> ParseJson (parses the feed)" as *u8, part_has(ZIP,GS,"ParseJson" as *u8)) 66 pass=pass+g_check(" R7 GridScene -> baseurl baked in" as *u8, part_has(ZIP,GS,"https://nishifamily.com/roku" as *u8)) 67 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 } } 68 pass=pass+g_check(" R8 GridScene -> iterates data.items into HDPOSTERURL" as *u8, feedok) 69 var noembed: i64=0; if part_has(ZIP,GS,"Sunrise" as *u8)==0 { noembed=1 } 70 pass=pass+g_check(" R9 LIAR-KILL: NO embedded catalog (truly remote)" as *u8, noembed) 71 var neg: i64=0; if xn<0 { neg=1 } 72 pass=pass+g_check(" R10 liar-kill: unknown part returns <0" as *u8, neg) 73 74 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) 75 let lg: i64=sys_openat_append("knowledge/status/roku_grid_remote_gate.log" as *u8, 0x1a4) 76 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) } 77 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 } 78 g_puts("ROKU-GRID-REMOTE RED\n" as *u8); sys_exit(1); return 1 79}