code wiki / (root) / nx_torrent_sota_fetch.nx

nx_torrent_sota_fetch.nx source

↩ module page · 81 lines · 6227 B

1// nx_torrent_sota_fetch.nx -- SOVEREIGN multi-source fetch of the REAL torrent-client STATE OF THE ART, so the 2// competitor census is grounded in FETCHED FACTS, not my memory (doctrine: research honestly, not memory-toss). 3// Sources = the AUTHORITATIVE references: libtorrent's feature list (the reference impl qBittorrent/Deluge are 4// built on), the BEP index (every standardized BitTorrent extension + its status), and the key individual BEPs 5// that map to our census gaps. Reuses the proven sovereign TLS-1.3 stack (nx_https_fetch_follow + Mozilla CA), 6// saves each to knowledge/fetched/ts_*.raw so research COMPOUNDS + can be grepped to VALIDATE the census conf. 7// 100% sovereign (own TLS, nx_cc->nxasm, no curl/wget/gcc). expect_exit: 0 license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "nx_x509_trust_store.nx" 10import "nx_trust_store_load_from_certdata.nx" 11import "nx_https_fetch_follow.nx" 12const K_MAGIC_4194304: i64 = 4194304 13const K_MAGIC_8388608: i64 = 8388608 14 15func sf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 16func sf_putn(v: i64) -> i64 { 17 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 18 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 19 let d: *u8 = sys_mmap(24); var k: i64 = 0 20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 21 var j: i64 = k - 1 22 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 23 return 0 24} 25// idempotent (rule #10): a source already on disk is skipped -> re-runs only fill gaps. Also the LEAK 26// WORKAROUND -- the TLS stack leaks mmap/fetch, so the set completes over a few resumable passes instead 27// of one OOM. Re-run the same arg-free command until every line says SAVED or [have-skip]. 28func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 29 30func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 31 if have_file(opath) == 1 { sf_puts(opath); sf_puts(" [have-skip]\n" as *u8); return 1 } 32 let status: *i64 = sys_mmap(8) as *i64 33 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 34 sf_puts(url); sf_puts(" status="); sf_putn(status[0]); sf_puts(" bytes="); sf_putn(n) 35 if n <= 0 { sf_puts(" FETCH-FAIL\n" as *u8); return 0 } 36 var gz: i64 = 0 37 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 38 if gz == 1 { sf_puts(" [GZIP-skip]\n" as *u8); return 0 } 39 let fd: i64 = sys_openat_wr(opath, 0x1a4) 40 if fd < 0 { sf_puts(" SAVE-FAIL\n" as *u8); return 0 } 41 sys_write(fd, out, n); sys_close(fd) 42 sf_puts(" SAVED\n" as *u8); return 1 43} 44 45func main() -> i64 { 46 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 47 if r <= 0 { sf_puts("TS-SOTA: certdata load failed\n" as *u8); return 1 } 48 let store: *TrustStore = r as *TrustStore 49 sf_puts("CA roots="); sf_putn(trust_store_count(store)); sf_puts("\n" as *u8) 50 let cap: i64 = K_MAGIC_8388608 51 let out: *u8 = sys_mmap(cap) 52 var ok: i64 = 0 53 54 sf_puts("== REFERENCE IMPLEMENTATION FEATURE LISTS (the de-facto SOTA every client tracks) ==\n" as *u8) 55 ok = ok + fetch_save("https://www.libtorrent.org/features.html" as *u8, "knowledge/fetched/ts_ref_libtorrent_features.raw" as *u8, store, out, cap) 56 ok = ok + fetch_save("https://www.libtorrent.org/manual-ref.html" as *u8, "knowledge/fetched/ts_ref_libtorrent_manual.raw" as *u8, store, out, cap) 57 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Comparison_of_BitTorrent_clients" as *u8, "knowledge/fetched/ts_ref_client_comparison.raw" as *u8, store, out, cap) 58 ok = ok + fetch_save("https://en.wikipedia.org/wiki/BitTorrent" as *u8, "knowledge/fetched/ts_ref_bittorrent.raw" as *u8, store, out, cap) 59 60 sf_puts("== BEP INDEX (every standardized extension + Final/Draft status = the protocol SOTA) ==\n" as *u8) 61 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0000.html" as *u8, "knowledge/fetched/ts_bep_index.raw" as *u8, store, out, cap) 62 63 sf_puts("== KEY BEPs mapping to our census GAPS (confirm what SOTA actually specifies) ==\n" as *u8) 64 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0019.html" as *u8, "knowledge/fetched/ts_bep19_webseed.raw" as *u8, store, out, cap) 65 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0029.html" as *u8, "knowledge/fetched/ts_bep29_utp.raw" as *u8, store, out, cap) 66 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0052.html" as *u8, "knowledge/fetched/ts_bep52_v2.raw" as *u8, store, out, cap) 67 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0055.html" as *u8, "knowledge/fetched/ts_bep55_holepunch.raw" as *u8, store, out, cap) 68 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0014.html" as *u8, "knowledge/fetched/ts_bep14_lsd.raw" as *u8, store, out, cap) 69 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0016.html" as *u8, "knowledge/fetched/ts_bep16_superseed.raw" as *u8, store, out, cap) 70 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0027.html" as *u8, "knowledge/fetched/ts_bep27_private.raw" as *u8, store, out, cap) 71 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0010.html" as *u8, "knowledge/fetched/ts_bep10_extension.raw" as *u8, store, out, cap) 72 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0040.html" as *u8, "knowledge/fetched/ts_bep40_peerprio.raw" as *u8, store, out, cap) 73 ok = ok + fetch_save("https://www.bittorrent.org/beps/bep_0021.html" as *u8, "knowledge/fetched/ts_bep21_partialseed.raw" as *u8, store, out, cap) 74 75 sf_puts("== NAT traversal / port mapping (WAN reach = the R4 gap) ==\n" as *u8) 76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol" as *u8, "knowledge/fetched/ts_nat_pmp.raw" as *u8, store, out, cap) 77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Internet_Gateway_Device_Protocol" as *u8, "knowledge/fetched/ts_upnp_igd.raw" as *u8, store, out, cap) 78 79 sf_puts("TS-SOTA fetched_ok="); sf_putn(ok); sf_puts(" (re-run until all SAVED/[have-skip]; leak = resumable)\n" as *u8) 80 return 0 81}