code wiki / _hdl_build / nx_consul_registry.nx
nx_consul_registry.nx source
↩ module page · 36 lines · 1898 B
1// nx_consul_registry.nx -- sovereign SERVICE REGISTRY + HEALTH-GATED DISCOVERY (HashiCorp Consul-class; the
2// first rung of the sovereign-Consul arc). Register service instances (name, addr, port, health); discover(name)
3// returns ONLY routable instances (health != CRITICAL) that are still registered -- so traffic NEVER routes to
4// a down or deregistered instance. The health gate is the core safety property Consul exists to provide.
5// Composes toward nx_dns_authoritative (service DNS), nx_reach_probe (the live health source), nx_vault
6// (service-mesh mTLS, later). Pure logic over the registry arrays. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9const SVC_PASSING: i64 = 0
10const SVC_WARNING: i64 = 1
11const SVC_CRITICAL: i64 = 2
12
13// is an instance routable? Consul default: PASSING + WARNING are returned; CRITICAL is removed from discovery.
14func cs_routable(health: i64) -> i64 { if health == SVC_CRITICAL { return 0 } return 1 }
15
16// discover: fill out_idx[] with the indices of REGISTERED, name-matching, ROUTABLE instances; return the count.
17func cs_discover(reg: *i64, names: *i64, healths: *i64, n: i64, qname: i64, out_idx: *i64) -> i64 {
18 var c: i64 = 0
19 var i: i64 = 0
20 while i < n {
21 if reg[i] == 1 { if names[i] == qname { if cs_routable(healths[i]) == 1 { out_idx[c] = i; c = c + 1 } } }
22 i = i + 1
23 }
24 return c
25}
26
27// deregister an instance (idempotent): mark it not-registered so discovery drops it immediately.
28func cs_deregister(reg: *i64, idx: i64) -> i64 { reg[idx] = 0; return 0 }
29
30// count of healthy (PASSING) registered instances of a service -- the strict ?passing view.
31func cs_passing_count(reg: *i64, names: *i64, healths: *i64, n: i64, qname: i64) -> i64 {
32 var c: i64 = 0
33 var i: i64 = 0
34 while i < n { if reg[i] == 1 { if names[i] == qname { if healths[i] == SVC_PASSING { c = c + 1 } } } i = i + 1 }
35 return c
36}