code wiki / (root) / nx_research_ka.nx

nx_research_ka.nx

buildroot/runtime/nx_research_ka.nx

12732 B211 linesdepth 21pulls 146 transitivereach 76 importersview sourcekind tooltopic research
docsdependenciesstructsconstsfunctions

about

nx_research_ka.nx -- R4 FULL: per-host connection POOL + keep-alive fetch, with a PROVEN-path fallback. Operator 2026-07-01 chose R4. nx_https_get_complete has 30 callers (untouchable) so this is a SELF-CONTAINED module: * caches ONE (host, fd, session) across calls (module static globals) -> a researcher hitting ONE host repeatedly pays the ~300ms cert-verify (certloop) ONCE, then reuses the TLS session for every subsequent GET. * SAFE by construction: only the clean case (fresh/reused -> HTTP 200, Content-Length body) uses the fast path; ANYTHING else (redirect/non-200/stale/parse-miss) closes the pooled conn and FALLS BACK to the proven nx_https_fetch_follow (fresh connect, full redirect+chunk handling). Worst case == today's behavior. Proven mechanism: nx_https_ka_probe (2 GETs / 1 handshake, GREEN). license_tier: ORIGINAL expect_exit: 0

dependencies 14 imports · 2 importers

nx_syscalls.nx nx_tls13.nx nx_tls13_record.nx nx_tls13_read_record_from_fd.nx nx_tls13_client_session.nx nx_x509_trust_store.nx nx_trust_store_load_from_certdata. nx_tls13_client_validate_certifica nx_tls13_client_session_run.nx nx_url.nx nx_research_ka.nx nx_ka_engine_test.nx nx_research_engine.nx

diagram shows first 10 each side; +4 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tls13.nxnx_tls13_record.nxnx_tls13_read_record_from_fd.nxnx_tls13_client_session.nxnx_x509_trust_store.nxnx_trust_store_load_from_certdata.nxnx_tls13_client_validate_certificate.nxnx_tls13_client_session_run.nxnx_url.nxnx_https_url_for_fetch.nxnx_https_url_connect.nxnx_http_response_parse.nxnx_https_fetch_follow.nx

imported by: nx_ka_engine_test.nxnx_research_engine.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_trust_store_load_from_c sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close nx_nss_certdata_parse sys_mmap ↻ _pat_class_cert _pat_value_octal _pat_end _find_newline _starts_with _parse_octal_line sys_mmap ↻ _is_space _decode_octal_escape _is_octal trust_store_alloc sys_mmap ↻ nx_x509_trust_store_load sys_mmap ↻ x509_parse sys_mmap ↻ asn1_cursor_init asn1_expect_tag sys_mmap ↻ asn1_read_tlv_header asn1_read_tag asn1_read_length asn1_read_length ↻ x509_read_tlv sys_mmap ↻ asn1_expect_tag ↻ x509_read_alg_id sys_mmap ↻ asn1_expect_tag ↻

structs

none

consts

23const K_MAGIC_4096: i64 = 4096
24const K_MAGIC_16645: i64 = 16645
25const K_MAGIC_2048: i64 = 2048
26const K_MAGIC_4194304: i64 = 4194304

functions

36func rka_handshakes() -> i64 { return G_KA_HANDSHAKES }
37func rka_reuses() -> i64 { return G_KA_REUSES }
39func rp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
40func rn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0} 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{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
41func rka_write_n(fd: i64, buf: *u8, n: i64) -> i64 { var off: i64=0; while off<n { let w: i64=sys_write(fd,(buf as i64+off) as *u8,n-off); if w<=0 {return 0-1} off=off+w } return 0 }
called by 1: rka_get calls 1: sys_write
42func rka_cat(out: *u8, o: i64, s: *u8) -> i64 { var j: i64=0; while s[j]!=(0 as u8) { out[o]=s[j]; o=o+1; j=j+1 } return o }
called by 1: rka_build_req
44func rka_build_req(path: *u8, path_len: i64, host: *u8, host_len: i64, out: *u8) -> i64
called by 1: rka_get calls 1: rka_cat
53func rka_hdr_end(buf: *u8, n: i64) -> i64 { var i: i64=0; while i+4<=n { if buf[i]==(13 as u8){if buf[i+1]==(10 as u8){if buf[i+2]==(13 as u8){if buf[i+3]==(10 as u8){return i}}}} i=i+1 } return 0-1 }
called by 1: rka_get
54func rka_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
called by 1: rka_clen
55func rka_clen(buf: *u8, hdr_end: i64) -> i64
called by 1: rka_get calls 1: rka_lc
79func rka_get(s: *Tls13ClientSession, fd: i64, path: *u8, path_len: i64, host: *u8, host_len: i64, out_buf: *u8, out_cap: i64) -> i64
120func rka_path(urlbuf: *u8, target: *NxHttpsTarget, path_out: *u8) -> i64
called by 1: rf_fetch_ka
132func rka_host_match(host: *u8, hlen: i64) -> i64
called by 1: rf_fetch_ka
141func rka_host_cache(host: *u8, hlen: i64) -> i64
called by 1: rf_fetch_ka calls 1: sys_mmap
151func rf_fetch_ka(url0: *u8, store: *TrustStore, out: *u8, out_cap: i64, out_status: *i64) -> i64
192func main() -> i64