nx_backend_probe.nx source
↩ module page · 36 lines · 1923 B
1// nx_backend_probe.nx -- probe the plain-HTTP library backend (:8095) on both the
2// deploy target (.227) and the public-DNS edge (.240) to settle the topology:
3// which box actually serves the 16K-taxon library after this deploy.
4import "nx_syscalls.nx"
5import "nx_http_proxy.nx"
6const K_MAGIC_262144: i64 = 262144
7const K_MAGIC_8095: i64 = 8095
8
9func bp_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
10func bp_wr(p: *u8, n: i64) -> i64 { sys_write(1, p, n); return 0 }
11func bp_putn(v: i64) -> i64 {
12 let bb: *u8 = sys_mmap(28); var m: i64 = v
13 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
14 let t: *u8 = sys_mmap(28); var k: i64 = 0
15 if m == 0 { t[0] = 48 as u8; k = 1 }
16 while m > 0 { t[k] = (48 + (m - (m/10)*10)) as u8; m = m / 10; k = k + 1 }
17 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
18}
19
20func probe(ip: *u8, iplen: i64, req: *u8, label: *u8) -> i64 {
21 var rn: i64 = 0; while req[rn] != (0 as u8) { rn = rn + 1 }
22 let cap: i64 = K_MAGIC_262144
23 let out: *u8 = sys_mmap(cap)
24 bp_puts("=== "); bp_puts(ip); bp_puts(":8095 "); bp_puts(label); bp_puts(" ===\n")
25 let n: i64 = nx_http_proxy_forward(ip, iplen, K_MAGIC_8095, req, rn, out, cap)
26 bp_puts("bytes="); bp_putn(n); bp_puts("\n")
27 if n > 0 { var w: i64 = n; if w > 700 { w = 700 } bp_wr(out, w); bp_puts("\n--- end ---\n") }
28 return 0
29}
30
31func main() -> i64 {
32 probe("192.168.8.227" as *u8, 13, "GET /?q=archaea HTTP/1.0\r\nHost: n\r\nConnection: close\r\n\r\n\x00" as *u8, "q=archaea (lower)")
33 probe("192.168.8.227" as *u8, 13, "GET /?q=Caldisphaera HTTP/1.0\r\nHost: n\r\nConnection: close\r\n\r\n\x00" as *u8, "q=Caldisphaera")
34 probe("192.168.8.227" as *u8, 13, "GET /api/search?q=Archaea HTTP/1.0\r\nHost: n\r\nConnection: close\r\n\r\n\x00" as *u8, "api/search q=Archaea")
35 return 0
36}