code wiki / (root) / nx_mirrorintegrity.nx

nx_mirrorintegrity.nx source

↩ module page · 117 lines · 7170 B

1// nx_mirrorintegrity.nx -- THIN MAIN over nx_mirrorintegrity_lib.nx. All judgement lives in the lib so the 2// gate can exercise the SAME code in-process rather than parsing this program's stdout. 3// nx_mirrorintegrity [dir] default dir=knowledge/fetched 4// license_tier: ORIGINAL expect_exit: 0 5import "nx_mirrorintegrity_lib.nx" 6 7func main(argc: i64, argv: *i64) -> i64 { 8 var dir: *u8 = MI_DEF_DIR as *u8 9 if argc>=2 { dir = argv[1] as *u8 } 10 let counts: *i64=sys_mmap(128) as *i64 11 var z: i64=0 12 while z<8 { counts[z]=0; z=z+1 } 13 let hbuf: *u8=sys_mmap(MI_HEAD+16) 14 let tbuf: *u8=sys_mmap(MI_TAIL+16) 15 let work: *u8=sys_mmap(MI_WORKCAP) 16 let wo: *i64=sys_mmap(16) as *i64 17 wo[0]=0 18 let pbuf: *u8=sys_mmap(MI_PATHCAP) 19 var dn: i64=0 20 while dir[dn]!=(0 as u8) { pbuf[dn]=dir[dn]; dn=dn+1 } 21 22 mi_w("=== NX-MIRRORINTEGRITY -- a pin proves the bytes are UNCHANGED, never that they are COMPLETE ===\n" as *u8) 23 mi_w(" subject dir: " as *u8); mi_w(dir); mi_w("\n" as *u8) 24 mi_walk(pbuf, dn, 0, hbuf, tbuf, counts, work, wo) 25 26 let files: i64=counts[4] 27 let sum: i64=counts[0]+counts[1]+counts[2]+counts[3] 28 mi_w("\n-- WORKLIST (every non-complete body, with the reason that decided it) --\n" as *u8) 29 if wo[0]==0 { mi_w(" (none -- no body failed its own completeness test)\n" as *u8) } 30 else { work[wo[0]]=0 as u8; mi_w(work) } 31 if wo[0]>=MI_WORKFLUSH { mi_w(" <== THIS LIST IS A PREFIX OF ITS OWN COUNT (worklist buffer filled)\n" as *u8) } 32 33 let ob: *u8=sys_mmap(8192) 34 var a: i64=0 35 a=mi_cat(ob, a, "\n-- PARTITION (must sum to files) --\n TRUNCATED-PROVEN=" as *u8) 36 a=mi_catn(ob, a, counts[0]) 37 a=mi_cat(ob, a, " TRUNCATED-SUSPECT=" as *u8); a=mi_catn(ob, a, counts[1]) 38 a=mi_cat(ob, a, " COMPLETE-PROVEN=" as *u8); a=mi_catn(ob, a, counts[2]) 39 a=mi_cat(ob, a, " UNKNOWN=" as *u8); a=mi_catn(ob, a, counts[3]) 40 a=mi_cat(ob, a, "\n files=" as *u8); a=mi_catn(ob, a, files) 41 a=mi_cat(ob, a, " sum=" as *u8); a=mi_catn(ob, a, sum) 42 if sum==files { a=mi_cat(ob, a, " partition=RECONCILES\n" as *u8) } else { a=mi_cat(ob, a, " partition=LEAK\n" as *u8) } 43 a=mi_cat(ob, a, "\n-- SEPARATE AXIS (NOT a partition member: a complete body can land on a power of two) --\n size-is-exact-power-of-two(>=65536)=" as *u8) 44 a=mi_catn(ob, a, counts[5]) 45 a=mi_cat(ob, a, "\n worst declared-vs-stored shortfall (bytes)=" as *u8); a=mi_catn(ob, a, counts[6]) 46 a=mi_cat(ob, a, "\n\n-- SCOPE, STATED SO NOBODY READS THIS AS A CLEAN BILL --\n" as *u8) 47 a=mi_cat(ob, a, " UNKNOWN is NOT complete. Only PDF (declared length or EOF marker), HTML, JSON, PNG and JPEG\n" as *u8) 48 a=mi_cat(ob, a, " describe their own completeness here. A body whose format declares no length and carries no\n" as *u8) 49 a=mi_cat(ob, a, " terminator CANNOT BE JUDGED and is counted apart. COMPLETE-PROVEN is therefore a FLOOR on\n" as *u8) 50 a=mi_cat(ob, a, " completeness and TRUNCATED-PROVEN is a FLOOR on damage -- both bound upward with more decoders.\n" as *u8) 51 a=mi_cat(ob, a, " Head and tail reads are " as *u8); a=mi_catn(ob, a, MI_HEAD) 52 a=mi_cat(ob, a, " bytes each and are DECLARED: a terminator further inside a very long tail would be missed.\n" as *u8) 53 ob[a]=0 as u8 54 mi_w(ob) 55 56 // ---- CONTENT AXIS: is the whole body actually the DOCUMENT? Declared separate, never folded in. 57 // mi_pc_floor was the content-axis floor reader's ORIGINAL name; the lib renamed it mi_prose_floor 58 // and this consumer was never updated, so nx_mirrorintegrity.nx has not compiled since. The promoted 59 // binary came from the source as it stood BEFORE the rename, which is why the catalogue reads 60 // BUILT=NO beside a live PROMOTED artifact and nothing looked wrong. 61 // A RENAME THAT LANDS IN THE LIBRARY AND NOT IN ITS CALLER IS HALF A RENAME, AND THE HALF LEFT 62 // UNDONE IS INVISIBLE UNTIL SOMEBODY TRIES TO REBUILD. 63 var cfloor: i64 = mi_prose_floor() 64 if argc>=3 { cfloor = mi_atoi_arg(argv[2] as *u8) } 65 let ccounts: *i64=sys_mmap(MI_COUNTS_BYTES) as *i64 66 var y: i64=0 67 while y<MI_COUNTS_SLOTS { ccounts[y]=0; y=y+1 } 68 let cwork: *u8=sys_mmap(MI_WORKCAP) 69 let cwo: *i64=sys_mmap(16) as *i64 70 cwo[0]=0 71 let cpbuf: *u8=sys_mmap(MI_PATHCAP) 72 var cdn: i64=0 73 while dir[cdn]!=(0 as u8) { cpbuf[cdn]=dir[cdn]; cdn=cdn+1 } 74 mi_content_walk(cpbuf, cdn, 0, cfloor, ccounts, cwork, cwo) 75 76 mi_w("\n-- CONTENT-AXIS WORKLIST (a WHOLE body is not the same claim as the RIGHT body) --\n" as *u8) 77 if cwo[0]==0 { mi_w(" (none)\n" as *u8) } 78 else { cwork[cwo[0]]=0 as u8; mi_w(cwork) } 79 if cwo[0]>=MI_WORKFLUSH { mi_w(" <== THIS LIST IS A PREFIX OF ITS OWN COUNT (worklist buffer filled)\n" as *u8) } 80 81 let cb2: *u8=sys_mmap(MI_AXISBUF) 82 var q: i64=0 83 q=mi_cat(cb2, q, "\n-- CONTENT AXIS (SEPARATE AXIS: a body can be COMPLETE and content-empty AT ONCE) --\n content-present=" as *u8) 84 q=mi_catn(cb2, q, ccounts[MC_OK]) 85 q=mi_cat(cb2, q, " js-shell=" as *u8); q=mi_catn(cb2, q, ccounts[MC_JS_SHELL]) 86 q=mi_cat(cb2, q, " bot-challenge=" as *u8); q=mi_catn(cb2, q, ccounts[MC_BOT_CHALLENGE]) 87 q=mi_cat(cb2, q, " login-wall=" as *u8); q=mi_catn(cb2, q, ccounts[MC_LOGIN_WALL]) 88 q=mi_cat(cb2, q, " http-error-page=" as *u8); q=mi_catn(cb2, q, ccounts[MC_HTTP_ERROR]) 89 q=mi_cat(cb2, q, " prose-empty-unknown=" as *u8); q=mi_catn(cb2, q, ccounts[MC_PROSE_EMPTY]) 90 q=mi_cat(cb2, q, " not-html-abstained=" as *u8); q=mi_catn(cb2, q, ccounts[MC_NOT_HTML]) 91 let csum: i64=ccounts[0]+ccounts[1]+ccounts[2]+ccounts[3]+ccounts[4]+ccounts[5]+ccounts[6] 92 q=mi_cat(cb2, q, "\n files=" as *u8); q=mi_catn(cb2, q, ccounts[7]) 93 q=mi_cat(cb2, q, " sum=" as *u8); q=mi_catn(cb2, q, csum) 94 if csum==ccounts[7] { q=mi_cat(cb2, q, " partition=RECONCILES\n" as *u8) } else { q=mi_cat(cb2, q, " partition=LEAK\n" as *u8) } 95 q=mi_cat(cb2, q, " html_bodies_judged=" as *u8); q=mi_catn(cb2, q, ccounts[8]) 96 q=mi_cat(cb2, q, " prose_floor_bytes=" as *u8); q=mi_catn(cb2, q, cfloor) 97 q=mi_cat(cb2, q, "\n NOT-HTML is an ABSTENTION, not a pass: only HTML declares its own prose here.\n" as *u8) 98 q=mi_cat(cb2, q, " A negative floor selects CALIBRATION mode, which prints the prose number for EVERY\n" as *u8) 99 q=mi_cat(cb2, q, " HTML body so the bar is READ OFF THE DISTRIBUTION instead of invented.\n" as *u8) 100 cb2[q]=0 as u8 101 mi_w(cb2) 102 103 let vb: *u8=sys_mmap(512) 104 var v: i64=0 105 v=mi_cat(vb, v, "\nNX-MIRRORINTEGRITY files=" as *u8); v=mi_catn(vb, v, files) 106 v=mi_cat(vb, v, " proven=" as *u8); v=mi_catn(vb, v, counts[0]) 107 v=mi_cat(vb, v, " suspect=" as *u8); v=mi_catn(vb, v, counts[1]) 108 v=mi_cat(vb, v, " complete=" as *u8); v=mi_catn(vb, v, counts[2]) 109 v=mi_cat(vb, v, " unknown=" as *u8); v=mi_catn(vb, v, counts[3]) 110 v=mi_cat(vb, v, " capexact=" as *u8); v=mi_catn(vb, v, counts[5]) 111 if counts[0]>0 { v=mi_cat(vb, v, " verdict=RED\n" as *u8) } else { v=mi_cat(vb, v, " verdict=GREEN\n" as *u8) } 112 vb[v]=0 as u8 113 mi_w(vb) 114 if counts[0]>0 { sys_exit(1); return 1 } 115 sys_exit(0) 116 return 0 117}