code wiki / (root) / nx_tool_http_backend.nx

nx_tool_http_backend.nx

buildroot/runtime/nx_tool_http_backend.nx

10233 B204 linesdepth 5pulls 5 transitivereach 12 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 2 imports · 3 importers

nx_syscalls.nx nx_connect.nx nx_tool_http_backend.nx nx_mgmt_call.nx nx_tool_http_backend_gate.nx nx_tools_api.nx

imports: nx_syscalls.nxnx_connect.nx

imported by: nx_mgmt_call.nxnx_tool_http_backend_gate.nxnx_tools_api.nx

structs

none

consts

13const TB_MAGIC_262144: i64 = 262144
14const TB_MAGIC_8192: i64 = 8192
15const TB_MAGIC_16384: i64 = 16384
16const TB_MAGIC_1048576: i64 = 1048576
18const TB_CONF: *u8 = "knowledge/tool_backends.conf" as *u8 // server CWD-relative (like tool_allowlist.conf)
19const THB_OK: i64 = 1 // fetched -> body in out[0..outlen)
20const THB_NOROUTE: i64 = 0 // tool not an HTTP backend -> caller falls back to fork-exec
21const THB_ERR: i64 = 0 - 1 // declared but malformed/unreachable

functions

23func thb_hex(v: i64) -> i64 { if v < 10 { return 48 + v } return 55 + v } // 0-9 then A-F
called by 1: thb_urlenc
24func thb_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
25func 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 }
called by 1: thb_dispatch_from
26func 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 }
called by 1: thb_dispatch_from
29func thb_field(buf: *u8, ls: i64, le: i64, idx: i64, out2: *i64) -> i64
39func thb_atoi(buf: *u8, off: i64, len: i64) -> i64
45func thb_urlenc(src: *u8, slen: i64, dst: *u8) -> i64
called by 2: thb_dispatch_frommain calls 1: thb_hex
70func thb_sockaddr(addr: *u8, port: i64, a: i64, b: i64, c: i64, d: i64) -> i64
called by 1: thb_fetch
78func thb_parse_ip(s: *u8, slen: i64, out4: *i64) -> i64
called by 1: thb_fetch
90func thb_fetch(host: *u8, hostlen: i64, port: i64, req: *u8, reqn: i64, out: *u8, cap: i64) -> i64
115func thb_read_conf(path: *u8, out_len: *i64) -> *u8
136func thb_dispatch_from(conf: *u8, name: *u8, nlen: i64, argv: *i64, argc: i64, out: *u8, cap: i64, outlen: *i64) -> i64
202func thb_dispatch(name: *u8, nlen: i64, argv: *i64, argc: i64, out: *u8, cap: i64, outlen: *i64) -> i64
called by 1: ta_mcp_call calls 1: thb_dispatch_from