@@ -27,6 +27,9 @@ import time
2727#flag -lboj_loader
2828#flag -lboj_federation
2929#flag -lboj_coprocessor
30+ #flag -lboj_sla
31+ #flag -lboj_community
32+ #flag -lboj_sdp
3033#flag -L../../cartridges/container-mcp/ffi/zig-out/lib
3134#flag -lcontainer_mcp
3235
@@ -76,6 +79,42 @@ fn C.boj_coprocessor_select_by_name(name_ptr &u8, name_len usize, was_fallback &
7679fn C.boj_coprocessor_affinity_count () usize
7780fn C.boj_coprocessor_has_accelerator (kind u8 ) u8
7881
82+ // SLA & Monitoring C FFI declarations
83+ fn C.boj_sla_init () int
84+ fn C.boj_sla_deinit ()
85+ fn C.boj_sla_register (name_ptr & u8 , name_len usize, tier u8 ) int
86+ fn C.boj_sla_record_invocation (idx usize, latency_us u32 , success u8 )
87+ fn C.boj_sla_record_health (idx usize, healthy u8 )
88+ fn C.boj_sla_uptime (idx usize) u32
89+ fn C.boj_sla_error_rate (idx usize) u32
90+ fn C.boj_sla_p50 (idx usize) u32
91+ fn C.boj_sla_p95 (idx usize) u32
92+ fn C.boj_sla_p99 (idx usize) u32
93+ fn C.boj_sla_meets_target (idx usize) u8
94+ fn C.boj_sla_total_requests () u64
95+ fn C.boj_sla_total_errors () u64
96+ fn C.boj_sla_cartridge_count () usize
97+
98+ // Community cartridge submission C FFI declarations
99+ fn C.boj_community_init () int
100+ fn C.boj_community_deinit ()
101+ fn C.boj_community_submit (name_ptr & u8 , name_len usize, author_ptr & u8 , author_len usize, desc_ptr & u8 , desc_len usize, hash_ptr & u8 , hash_len usize) int
102+ fn C.boj_community_set_status (idx usize, status u8 ) int
103+ fn C.boj_community_status (idx usize) u8
104+ fn C.boj_community_count () usize
105+ fn C.boj_community_count_approved () usize
106+ fn C.boj_community_count_pending () usize
107+ fn C.boj_community_find (name_ptr & u8 , name_len usize) int
108+
109+ // Auto-SDP C FFI declarations
110+ fn C.boj_sdp_init () int
111+ fn C.boj_sdp_deinit ()
112+ fn C.boj_sdp_authorise (id_ptr & u8 , id_len usize, rate_limit u32 ) int
113+ fn C.boj_sdp_check (id_ptr & u8 , id_len usize) u8
114+ fn C.boj_sdp_set_open_mode (mode u8 )
115+ fn C.boj_sdp_peer_count () usize
116+ fn C.boj_sdp_ban_count () usize
117+
79118// ═══════════════════════════════════════════════════════════════════════
80119// Domain Types (match Idris2 ABI encodings)
81120// ═══════════════════════════════════════════════════════════════════════
@@ -727,6 +766,18 @@ fn (h RestHandler) handle(req http.Request) http.Response {
727766 if path == '/coprocessor/select' && req.method == .post {
728767 return handle_coprocessor_select (req.data)
729768 }
769+ if path == '/sla/status' {
770+ return handle_sla_status ()
771+ }
772+ if path == '/community/submissions' && req.method == .get {
773+ return handle_community_list ()
774+ }
775+ if path == '/community/submit' && req.method == .post {
776+ return handle_community_submit (req.data)
777+ }
778+ if path == '/sdp/status' {
779+ return handle_sdp_status ()
780+ }
730781 return error_response (404 , 'unknown endpoint: ${path} ' )
731782}
732783
@@ -2591,6 +2642,78 @@ fn handle_coprocessor_select(body string) http.Response {
25912642 }))
25922643}
25932644
2645+ // ═══════════════════════════════════════════════════════════════════════
2646+ // SLA Monitoring REST handlers
2647+ // ═══════════════════════════════════════════════════════════════════════
2648+
2649+ fn handle_sla_status () http.Response {
2650+ total_req := C.boj_sla_total_requests ()
2651+ total_err := C.boj_sla_total_errors ()
2652+ tracked := int (C.boj_sla_cartridge_count ())
2653+ return json_response ('{"total_requests":${total_req} ,"total_errors":${total_err} ,"cartridges_tracked":${tracked} }' )
2654+ }
2655+
2656+ // ═══════════════════════════════════════════════════════════════════════
2657+ // Community Submission REST handlers
2658+ // ═══════════════════════════════════════════════════════════════════════
2659+
2660+ fn review_status_name (status u8 ) string {
2661+ return match status {
2662+ 0 { 'submitted' }
2663+ 1 { 'under_review' }
2664+ 2 { 'approved' }
2665+ 3 { 'rejected' }
2666+ 4 { 'suspended' }
2667+ else { 'unknown' }
2668+ }
2669+ }
2670+
2671+ fn handle_community_list () http.Response {
2672+ total := int (C.boj_community_count ())
2673+ approved := int (C.boj_community_count_approved ())
2674+ pending := int (C.boj_community_count_pending ())
2675+ return json_response ('{"total":${total} ,"approved":${approved} ,"pending":${pending} }' )
2676+ }
2677+
2678+ fn handle_community_submit (body string ) http.Response {
2679+ params := json.decode (map [string ]string , body) or {
2680+ return error_response (400 , 'requires {"name","author","description","hash"}' )
2681+ }
2682+ name := params['name' ] or { '' }
2683+ author := params['author' ] or { '' }
2684+ desc := params['description' ] or { '' }
2685+ hash := params['hash' ] or { '' }
2686+ if name == '' || author == '' || hash == '' {
2687+ return error_response (400 , 'name, author, and hash are required' )
2688+ }
2689+ result := C.boj_community_submit (name.str, name.len, author.str, author.len, desc.str, desc.len, hash.str, hash.len)
2690+ if result < 0 {
2691+ err_msg := match result {
2692+ - 1 { 'max submissions reached' }
2693+ - 2 { 'invalid name' }
2694+ - 3 { 'hash must be 64 hex chars' }
2695+ - 4 { 'duplicate cartridge name' }
2696+ else { 'submission failed' }
2697+ }
2698+ return error_response (409 , err_msg)
2699+ }
2700+ return json_response (json.encode ({
2701+ 'status' : 'submitted'
2702+ 'name' : name
2703+ 'index' : result.str ()
2704+ }))
2705+ }
2706+
2707+ // ═══════════════════════════════════════════════════════════════════════
2708+ // Auto-SDP REST handlers
2709+ // ═══════════════════════════════════════════════════════════════════════
2710+
2711+ fn handle_sdp_status () http.Response {
2712+ peers := int (C.boj_sdp_peer_count ())
2713+ bans := int (C.boj_sdp_ban_count ())
2714+ return json_response ('{"authorised_peers":${peers} ,"active_bans":${bans} }' )
2715+ }
2716+
25942717// ═══════════════════════════════════════════════════════════════════════
25952718// Main
25962719// ═══════════════════════════════════════════════════════════════════════
@@ -2636,6 +2759,18 @@ fn main() {
26362759 coproc_devs := int (C.boj_coprocessor_device_count ())
26372760 println ('Coprocessor: ${coproc_devs} device(s) detected' )
26382761
2762+ // Initialise SLA monitoring
2763+ C.boj_sla_init ()
2764+ println ('SLA: monitoring initialised' )
2765+
2766+ // Initialise community cartridge registry
2767+ C.boj_community_init ()
2768+ println ('Community: Ayo tier submissions ready' )
2769+
2770+ // Initialise Auto-SDP perimeter
2771+ C.boj_sdp_init ()
2772+ println ('SDP: perimeter active (open mode for seed bootstrapping)' )
2773+
26392774 // Register built-in cartridges
26402775 app.register_builtin_cartridges () or {
26412776 eprintln ('FATAL: ${err.msg()} ' )
0 commit comments