code wiki / _hdl_build / nx_web_crawl_step.nx

nx_web_crawl_step.nx

buildroot/runtime/_hdl_build/nx_web_crawl_step.nx

82847 B1478 linesdepth 21pulls 181 transitivereach 1 importersview sourcekind tooltopic web
docsdependenciesstructsconstsfunctions

about

nx_web_crawl_step.nx -- CRAWL AT SCALE: the frontier-PERSISTED successor to nx_web_ingest's one-shot BFS. The frontier lives IN the web shard itself (seg_store-native, no side files): key fr:<cid(url)> whose value is "P<url>" (pending) or "D<url>" (done) -- append-only, ss_hget last-wins flips state. Each run: 1. enumerate pending frontier rows (keys-index walk, dedup, latest state wins) 2. fetch up to <max_pages> of them (sovereign TLS; seq628 pool: WC_POOL_N forked workers on DISTINCT hosts, parent-enforced WC_FETCH_BUDGET_MS wall clock, dead-host deferral) 3. ingest kept pages (doc:<cid> + url:<cid>, the nx_web_ingest mechanics) 4. bank every NEWLY-DISCOVERED content link as a pending fr: row (filtered: no queries/fragments/ binaries/wiki-meta) and mark fetched urls done (even failures -- a dead url never wedges the loop) So the crawl RESUMES where it stopped: run it any number of times and the index only grows. A seed url is only needed to BOOTSTRAP an empty frontier (or inject a new start). usage: nx_web_crawl_step <max_pages> [seed-url] license_tier: ORIGINAL

dependencies 10 imports · 1 importers

nx_corpus_ingest.nx nx_x509_trust_store.nx nx_trust_store_load_from_certdata. nx_https_fetch_follow.nx nx_simhash.nx nx_crawl_pace.nx nx_feed_extract.nx nx_js_eval.nx nx_outlink_harvest.nx nx_store_seed_lib.nx nx_web_crawl_step.nx nx_web_crawl_step_gate.nx

imports: nx_corpus_ingest.nxnx_x509_trust_store.nxnx_trust_store_load_from_certdata.nxnx_https_fetch_follow.nxnx_simhash.nxnx_crawl_pace.nxnx_feed_extract.nxnx_js_eval.nxnx_outlink_harvest.nxnx_store_seed_lib.nx

imported by: nx_web_crawl_step_gate.nx

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

main wc_puts wc_atoi 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

structs

none

consts

27const WC_JS_HYDRATE: i64 = 0
28const WC_MAGIC_2000: i64 = 2000
29const WC_MAGIC_2048: i64 = 2048
30const WC_MAGIC_8192: i64 = 8192
31const WC_MAGIC_4194304: i64 = 4194304
32const WC_MAGIC_4096: i64 = 4096
33const WC_MAGIC_8388608: i64 = 8388608
34const WC_MAGIC_1048576: i64 = 1048576
35const WC_MAGIC_5381: i64 = 5381
38const WC_MAXPEND: i64 = 2048 // pending urls pulled per run. MEASURED 2026-08-04: at 256 the pull
45const WC_HD_RETIRE: i64 = 3 // R3 host-health: retire (P->D) a skipped row once its host's PERSISTED
48const WC_MAXSEEDS: i64 = 256 // seed-file urls held for the retire EXEMPTION + the R4 canonical lane +
54const WC_SEED_REFRESH: i64 = 8 // R5: already-done seed urls re-marked pending per run. The persisted
58const WC_MAXDISC: i64 = 300 // new frontier rows banked per run (bounds frontier growth per step)
59const WC_CANON_RESERVE: i64 = 384 // R4 CANONICAL LANE (2026-08-05): head slots of each run's work list
64const WC_MAXCANH: i64 = 96 // distinct canonical HOSTS parsed from the seed file (mirrors WC_MAXSEEDS)
65const WC_MAXURL: i64 = 1500 // urls longer than this are skipped (junk/tracking monsters)
66const WC_MININDEX: i64 = 500 // min extracted chars to INDEX a page (not to harvest its links). Measured
69const WC_HOSTCAP_CANON: i64 = 40 // R4b DEPTH CAP FOR CURATED HOSTS (2026-08-05). WC_HOSTCAP below exists to
76const WC_HOSTCAP: i64 = 6 // max pages INDEXED per host per crawl step (diversity). Measured 2026-07-06:
90const WC_POOL_N: i64 = 8 // in-flight fetch children per batch. Bounded by spool RAM (8 x 8MiB
93const WC_FETCH_BUDGET_MS: i64 = 20000 // per-fetch wall clock. Healthy fetches measure <1s recv with
96const WC_POLL_MS: i64 = 100 // parent reap-poll quantum while children are in flight
97const WC_US_PER_MS: i64 = 1000
98const WC_WNOHANG: i64 = 1
99const WC_SIGKILL: i64 = 9
100const WC_SPOOL_HDRB: i64 = 16 // spool header: [i64 http-status][i64 body-bytes]
101const WC_SPOOLPATH_B: i64 = 128
102const WC_MODE_RW: i64 = 420 // 0644 spool file mode
103const WC_DEADHOSTS: i64 = 128 // dead-host slots per run (frontier pull is 256 urls; hosts <= urls)
104const WC_HASH_MASK: i64 = 0x7fffffffffffffff
335const WC_URLPOL_PLANE: *u8 = "knowledge/store/urlpolicy-"
336const WC_QSLOT: i64 = 32
337const WC_QMAXDENY: i64 = 192
338const WC_QPLANECAP: i64 = 65536
339const WC_QDEF_MAXP: i64 = 4 // default param budget for an UNCURATED host
340const WC_QDEF_MAXL: i64 = 120 // default max query length in bytes
341const WC_QCAN_BOOST: i64 = 4 // curated hosts get this many EXTRA params (trust boost, not a gate)

functions

106func wc_puts(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
107func wc_num(v: i64) -> i64
called by 1: main
116func wc_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
118func wc_resolve(base: *u8, href: *u8, out: *u8) -> i64
called by 1: main
133func wc_host(url: *u8, out: *u8) -> i64
141func wc_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } } i = i + 1 } return v }
called by 1: main
142func wc_hassub(u: *u8, ul: i64, lit: *u8) -> i64
called by 2: wc_harvestmain calls 1: wc_len
155func wc_endswith(u: *u8, ul: i64, lit: *u8) -> i64
calls 1: wc_len
167func wc_frkey(u: *u8, ul: i64, out: *u8) -> i64
186func wc_outkey(cid: i64, out: *u8) -> i64 { return olh_outkey(cid, out) }
called by 1: wc_harvest
188func wc_frstate(h: *i64, u: *u8, ul: i64) -> i64
202func wc_frmark(w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, u: *u8, ul: i64, state: i64) -> i64
241func wc_streq(a: *u8, b: *u8) -> i64
249func wc_canon_hosts(seedstore: *u8, nseeds: i64, out: *u8) -> i64
called by 2: mainmain calls 2: wc_hostwc_streq
285func wc_host_str_is_canon(canh: *u8, ncan: i64, hb: *u8, hl: i64) -> i64
306func wc_host_is_canon(canh: *u8, ncan: i64, u: *u8, hb: *u8) -> i64
346func wc_qeq(a: *u8, b: *u8, bl: i64) -> i64
called by 1: wc_load_urlpolicy
352func wc_qnum(b: *u8, s: i64, e: i64) -> i64
called by 1: wc_load_urlpolicy
362func wc_load_urlpolicy() -> i64
called by 1: main calls 3: sts_loadwc_qeqwc_qnum
405func wc_qparam_denied(u: *u8, s: i64, e: i64) -> i64
called by 1: wc_query_ok
426func wc_query_ok(u: *u8, ul: i64, canon: i64) -> i64
called by 1: wc_urlok calls 1: wc_qparam_denied
462func wc_urlok(u: *u8, ul: i64) -> i64
477func wc_pending(h: *i64, prefix: *u8, urlsout: *u8, maxout: i64, canh: *u8, ncan: i64, canonly: i64) -> i64
554func wc_runseen(runseen: *u8, nrs: *i64, frk: *u8) -> i64
called by 2: wc_harvestmain
581func wc_harvest(hh: *u8, hlen: i64, base: *u8, blen: i64, h: *i64, w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, discbox: *i64, runseen: *u8, nrs: *i64) -> i64
684func wc_seed_add(h: *i64, w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, urls: *u8, npendbox: *i64, seed: *u8, sl: i64) -> i64
708func wc_hosthash(hostp: *u8, hl: i64) -> i64
714func wc_deadhost_has(dh: *i64, ndh: i64, hh: i64) -> i64
719func wc_deadhost_add(dh: *i64, ndhbox: *i64, hh: i64) -> i64
731func wc_hdkey(hh: i64, out: *u8) -> i64
746func wc_hd_streak(h: *i64, hh: i64) -> i64
764func wc_hd_put(w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, hh: i64, v: i64) -> i64
795func wc_srkey(out: *u8) -> i64
801func wc_sr_cursor(h: *i64) -> i64
818func wc_sr_put(w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, v: i64) -> i64
842func wc_seed_refresh(h: *i64, w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, seedstore: *u8, nseeds: i64, dst: *u8, dstbox: *i64) -> i64
872func wc_is_seed(seedstore: *u8, nseeds: i64, u: *u8, ul: i64) -> i64
886func wc_retire_if_rotten(h: *i64, w: *i64, prefix: *u8, segidbox: *i64, segsbox: *i64, u: *u8, ul: i64, hh: i64) -> i64
894func wc_spool_path(slot: i64, out: *u8) -> i64
914func wc_fetch_child(url: *u8, store: *TrustStore, spath: *u8) -> i64
933func main(argc: i64, argv: *i64) -> i64