code wiki / (root) / nx_tool_http_backend_candidate_t314.nx

nx_tool_http_backend_candidate_t314.nx

buildroot/runtime/nx_tool_http_backend_candidate_t314.nx

13736 B284 linesdepth 5pulls 8 transitivereach 1 importersview sourcekind librarytopic tool
docsdependenciesstructsconstsfunctions

about

nx_tool_http_backend.nx -- HTTP-BACKEND execution mode for the sovereign agent tools API. A tools/call whose tool name is declared in tool_backends.conf is an ALREADY-RUNNING sovereign HTTP service (search on :18456, doc, ...), reached IN-PROCESS over LOOPBACK -- ONE general, data-driven mechanism, NOT a per-tool shim binary. This is the second execution kind alongside fork-exec (nx_tool_exec_allow): a tool is EITHER a vetted ELF OR a registered HTTP backend. SECURITY: host/port/path are fixed in the operator-curated registry; the caller supplies ONLY the url-encoded param value (argv[1]) -> no SSRF, no path/header injection. FAIL-CLOSED: no row -> THB_NOROUTE (the caller then falls back to fork-exec, which also fail-closes). Self-contained loopback client (only nx_syscalls; sockaddr/parse-ip/read-loop replicate the proven nx_tool_run / nx_http_proxy patterns) -> minimal blast radius in the crown-jewel daemon. Row (TAB): <name>\t<method>\t<host>\t<port>\t<path>\t<param> license_tier: ORIGINAL

dependencies 5 imports · 1 importers

nx_syscalls.nx nx_fetch_deadline_candidate_t314.n nx_http_response_complete_candidat nx_deadline_lib.nx nx_connect.nx nx_tool_http_backend_candidate nx_http_backend_gate_t314.nx

imports: nx_syscalls.nxnx_fetch_deadline_candidate_t314.nxnx_http_response_complete_candidate_t314.nxnx_deadline_lib.nxnx_connect.nx

imported by: nx_http_backend_gate_t314.nx

structs

92struct NxHttpBackendEvidence

consts

16const TB_MAGIC_262144: i64 = 262144
17const TB_MAGIC_8192: i64 = 8192
18const TB_MAGIC_16384: i64 = 16384
19const TB_MAGIC_1048576: i64 = 1048576
21const TB_CONF: *u8 = "knowledge/tool_backends.conf" as *u8 // server CWD-relative (like tool_allowlist.conf)
22const THB_OK: i64 = 1 // fetched -> body in out[0..outlen)
23const THB_NOROUTE: i64 = 0 // tool not an HTTP backend -> caller falls back to fork-exec
24const THB_ERR: i64 = 0 - 1 // declared but malformed/unreachable
104const THB_STAGE_CONNECT:i64=1
105const THB_STAGE_SEND:i64=2
106const THB_STAGE_READ:i64=3
107const THB_STAGE_FRAME:i64=4
108const THB_STAGE_STATUS:i64=5
109const THB_TIMEOUT:i64=0-2
110const THB_CAPACITY:i64=0-3
111const THB_FRAMING:i64=0-4
112const THB_UPSTREAM:i64=0-5

functions

26func thb_hex(v: i64) -> i64 { if v < 10 { return 48 + v } return 55 + v } // 0-9 then A-F
called by 1: thb_urlenc
27func thb_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
28func thb_catb(d: *u8, o: i64, s: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { d[o + i] = s[i]; i = i + 1 } return o + n }
29func thb_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o + i] = s[i]; i = i + 1 } return o + i }
32func thb_field(buf: *u8, ls: i64, le: i64, idx: i64, out2: *i64) -> i64
42func thb_atoi(buf: *u8, off: i64, len: i64) -> i64
48func thb_urlenc(src: *u8, slen: i64, dst: *u8) -> i64
called by 1: thb_dispatch_from_result calls 1: thb_hex
73func thb_sockaddr(addr: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64
81func thb_parse_ip(s:*u8,n:i64,out4:*i64)->i64
called by 1: thb_fetch_result
113func thb_evidence_init(e:*NxHttpBackendEvidence,deadline:i64)->i64
117func thb_fetch_result(host:*u8,hostlen:i64,port:i64,req:*u8,reqn:i64,out:*u8,cap:i64,deadline:i64,e:*NxHttpBackendEvidence)->i64
158func thb_fetch(host:*u8,hostlen:i64,port:i64,req:*u8,reqn:i64,out:*u8,cap:i64)->i64
166func thb_body_result(raw:*u8,n:i64,out:*u8,cap:i64,e:*NxHttpBackendEvidence)->i64
181func thb_read_conf(path: *u8, out_len: *i64) -> *u8
202func thb_dispatch_from_result(conf: *u8, name: *u8, nlen: i64, argv: *i64, argc: i64, out: *u8, cap: i64, outlen: *i64, deadline:i64, wire_cap:i64, ev:*NxHttpBackendEvidence) -> i64
275func thb_dispatch(name: *u8, nlen: i64, argv: *i64, argc: i64, out: *u8, cap: i64, outlen: *i64) -> i64
279func thb_dispatch_from(conf:*u8,name:*u8,nlen:i64,argv:*i64,argc:i64,out:*u8,cap:i64,outlen:*i64)->i64