nx_torrent_competitor_census.nx source
↩ module page · 120 lines · 7849 B
1// nx_torrent_competitor_census.nx -- the TORRENT lane's COMPETITOR-FEATURE census: how much of the qBittorrent/
2// libtorrent/Transmission/BEP capability UNION does the Nishi sovereign stack already have? Data-driven over
3// knowledge/registry/torrent_competitor_features.conf (add a row = a graded feature, ZERO rebuild). LIAR-KILL
4// (the anti-cheat law, mirrors nx_search_competitor_census): a HAVE/PARTIAL row names its implementing organ;
5// this census OPENS runtime/<organ> -- a MISSING file flips the claim to UNGROUNDED (counted as a GAP + flagged),
6// so "we have X" can never be asserted without a real artifact on disk. Prints per-TIER rollup (core->advanced),
7// an overall ‰ score, the ungrounded flags, and the GAP ROADMAP grouped by tier. Durable ->
8// knowledge/status/torrent_competitor_census.log. license_tier: ORIGINAL
9import "nx_str.nx"
10import "nx_syscalls.nx"
11const TC_MAGIC_131072: i64 = 131072
12const TC_MAGIC_131000: i64 = 131000
13const TC_MAGIC_200000: i64 = 200000
14const TC_MAGIC_65536: i64 = 65536
15
16const TC_CONF: *u8 = "knowledge/registry/torrent_competitor_features.conf"
17const TC_LOG: *u8 = "knowledge/status/torrent_competitor_census.log"
18
19func tp(s: *u8) -> i64 { sys_write(1, s, nx_str_len(s)); return 0 }
20func tn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 }
21func tw(fd: i64, s: *u8) -> i64 { if fd>=0 { sys_write(fd, s, nx_str_len(s)) } return 0 }
22
23func tc_read(path: *u8, buf: *u8, cap: i64) -> i64 {
24 let fd: i64 = sys_openat_rd(path); if fd<0 { return 0-1 }
25 var tot: i64=0; var r: i64=1
26 while r>0 { let dst: *u8=((buf as i64)+tot) as *u8; r=sys_read(fd,dst,cap-tot); if r>0 { tot=tot+r } }
27 sys_close(fd); return tot
28}
29func tc_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 }
30func tc_app(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { dst[off+i]=s[i]; i=i+1 } return off+i }
31// extract the n-th TAB-field of line [ls,le) into out (NUL-terminated). returns 1 if the field exists.
32func tc_field(buf: *u8, ls: i64, le: i64, n: i64, out: *u8) -> i64 {
33 var fi: i64=0; var i: i64=ls; var o: i64=0
34 while i<le {
35 if buf[i]==(9 as u8) { if fi==n { out[o]=0 as u8; return 1 } fi=fi+1 } else { if fi==n { out[o]=buf[i]; o=o+1 } }
36 i=i+1
37 }
38 if fi==n { out[o]=0 as u8; return 1 }
39 return 0
40}
41func tc_organ_exists(organ: *u8) -> i64 {
42 if tc_streq(organ, "-" as *u8)==1 { return 0 }
43 let p: *u8=sys_mmap(512); var o: i64=0; let pre: *u8="runtime/" as *u8
44 var j: i64=0; while pre[j]!=(0 as u8) { p[o]=pre[j]; o=o+1; j=j+1 }
45 j=0; while organ[j]!=(0 as u8) { p[o]=organ[j]; o=o+1; j=j+1 } p[o]=0 as u8
46 let fd: i64=sys_openat_rd(p); if fd<0 { return 0 } sys_close(fd); return 1
47}
48func tc_tier_idx(t: *u8) -> i64 {
49 if tc_streq(t,"core" as *u8)==1 { return 0 }
50 if tc_streq(t,"discovery" as *u8)==1 { return 1 }
51 if tc_streq(t,"privacy" as *u8)==1 { return 2 }
52 if tc_streq(t,"seeding" as *u8)==1 { return 3 }
53 if tc_streq(t,"content" as *u8)==1 { return 4 }
54 if tc_streq(t,"automation" as *u8)==1 { return 5 }
55 return 6
56}
57func tc_tier_name(i: i64) -> *u8 {
58 if i==0 { return "CORE protocol (BEP-3/9)" as *u8 }
59 if i==1 { return "DISCOVERY (trackers/DHT/PEX/webseed)" as *u8 }
60 if i==2 { return "PRIVACY/SECURITY (encryption/proxy/ipfilter)" as *u8 }
61 if i==3 { return "SEEDING/SHARING" as *u8 }
62 if i==4 { return "CONTENT MGMT (selective/trim/priorities)" as *u8 }
63 if i==5 { return "AUTOMATION/UX (webui/rss/bandwidth/queue)" as *u8 }
64 return "ADVANCED (v2/uTP/portmap/holepunch)" as *u8
65}
66
67func main() -> i64 {
68 tp("=== nx_torrent_competitor_census: qBittorrent/libtorrent/BEP feature-UNION coverage (organ-grounded) ===\n" as *u8)
69 let cb: *u8 = sys_mmap(TC_MAGIC_131072); let cn: i64 = tc_read(TC_CONF, cb, TC_MAGIC_131000)
70 if cn<=0 { tp(" conf unreadable: " as *u8); tp(TC_CONF); tp("\n" as *u8); sys_exit(1); return 1 }
71 let have: *i64 = sys_mmap(8*7) as *i64; let part: *i64 = sys_mmap(8*7) as *i64; let gap: *i64 = sys_mmap(8*7) as *i64
72 var t: i64=0; while t<7 { have[t]=0; part[t]=0; gap[t]=0; t=t+1 }
73 var H: i64=0; var P: i64=0; var G: i64=0; var UNG: i64=0
74 let feat: *u8=sys_mmap(256); let tier: *u8=sys_mmap(64); let stat: *u8=sys_mmap(32); let organ: *u8=sys_mmap(256)
75 // gap list buffer (roadmap)
76 let gapbuf: *u8=sys_mmap(TC_MAGIC_200000); var go: i64=0
77 let ungbuf: *u8=sys_mmap(TC_MAGIC_65536); var uo: i64=0
78 var ls: i64=0
79 while ls<cn {
80 var le: i64=ls; var eol: i64=0
81 while eol==0 { if le>=cn { eol=1 } else { if cb[le]==(10 as u8) { eol=1 } else { le=le+1 } } }
82 if le>ls { if cb[ls]!=(35 as u8) { // skip '#' comments
83 if tc_field(cb,ls,le,0,feat)==1 { if tc_field(cb,ls,le,1,tier)==1 { if tc_field(cb,ls,le,2,stat)==1 {
84 tc_field(cb,ls,le,3,organ)
85 let ti: i64=tc_tier_idx(tier)
86 var st: i64=2 // 0=gap 1=partial 2=have
87 if tc_streq(stat,"HAVE" as *u8)==1 { st=2 } else { if tc_streq(stat,"PARTIAL" as *u8)==1 { st=1 } else { st=0 } }
88 if st>0 { // HAVE/PARTIAL must be organ-grounded
89 if tc_organ_exists(organ)==0 {
90 UNG=UNG+1; st=0 // UNGROUNDED -> caught -> counts as GAP
91 uo=tc_app(ungbuf,uo," !! UNGROUNDED " as *u8); uo=tc_app(ungbuf,uo,feat); uo=tc_app(ungbuf,uo," (organ " as *u8); uo=tc_app(ungbuf,uo,organ); uo=tc_app(ungbuf,uo," MISSING)\n" as *u8)
92 }
93 }
94 if st==2 { have[ti]=have[ti]+1; H=H+1 }
95 if st==1 { part[ti]=part[ti]+1; P=P+1 }
96 if st==0 { gap[ti]=gap[ti]+1; G=G+1
97 go=tc_app(gapbuf,go,"[" as *u8); go=tc_app(gapbuf,go,tier); go=tc_app(gapbuf,go,"] " as *u8); go=tc_app(gapbuf,go,feat); go=tc_app(gapbuf,go,"\n" as *u8)
98 }
99 } } }
100 } }
101 ls=le+1
102 }
103 let TOT: i64=H+P+G
104 // per-tier rollup
105 tp("\n-- per-tier coverage (HAVE / PARTIAL / GAP) --\n" as *u8)
106 t=0; while t<7 { let tt: i64=have[t]+part[t]+gap[t]; if tt>0 {
107 tp(" "); tp(tc_tier_name(t)); tp(": "); tn(have[t]); tp(" / "); tn(part[t]); tp(" / "); tn(gap[t]); tp("\n" as *u8)
108 } t=t+1 }
109 let score: i64 = (H*2 + P) * 1000 / (TOT*2)
110 tp("\n-- OVERALL: HAVE="); tn(H); tp(" PARTIAL="); tn(P); tp(" GAP="); tn(G); tp(" of "); tn(TOT)
111 tp(" score="); tn(score); tp("/1000 (HAVE=2,PARTIAL=1)\n" as *u8)
112 if UNG>0 { tp("\n-- LIAR-KILL: "); tn(UNG); tp(" claim(s) UNGROUNDED (organ missing) --\n" as *u8); sys_write(1, ungbuf, uo) }
113 else { tp("\n-- LIAR-KILL: 0 ungrounded (every HAVE/PARTIAL has a real organ on disk) --\n" as *u8) }
114 tp("\n-- GAP ROADMAP (what's left, "); tn(G); tp(" items) --\n" as *u8); sys_write(1, gapbuf, go)
115 // durable log
116 let lfd: i64 = sys_openat_wr(TC_LOG, 420)
117 if lfd>=0 { tw(lfd,"torrent_competitor_census H="); let b: *u8=sys_mmap(16); var m: i64=H; var k: i64=0; if m==0{b[0]=48;k=1} while m>0{b[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{sys_write(lfd,(((b as i64)+k-1-i)) as *u8,1);i=i+1}
118 tw(lfd," score="); m=score; k=0; if m==0{b[0]=48;k=1} while m>0{b[k]=(48+(m%10)) as u8;m=m/10;k=k+1} i=0; while i<k{sys_write(lfd,(((b as i64)+k-1-i)) as *u8,1);i=i+1} tw(lfd,"/1000\n"); sys_close(lfd) }
119 sys_exit(0); return 0
120}