skip to content
==> include/mesh/control.h <==
1/* @ajax/mesh-control: the control port (control.rs; mesh-abi "control protocol").
2 *
3 * One text line per request, a text line back (`ok ...` / `err ...`), except
4 * the framed replies (u32 LE length + bytes): `snap`, `programs`, `catalog`,
5 * `req`, `peek`, `log`, `trace`, `http`, `cluster`, `load`, `fleet`, `groups`,
6 * `sched`, `sched explain <name>`, `sched dry-run`, `jobs`, `job status`,
7 * `job results`. In a fleet every lifecycle change (load, upgrade, rollback,
8 * unload, start, stop, reset, place, the lockstep program's tasks, `group
9 * ...`) is a change of the desired state: it goes to the leader, which
10 * commits it and answers once the reachable members reconciled it.
11 *
12 * A request line is at most 4096 bytes, at most 32 clients are served at
13 * once, a client idle for 120 s (or not taking a reply within 10 s) is closed. */
14#ifndef MESH_CONTROL_H
15#define MESH_CONTROL_H
16
17#include "mesh/buf.h"
18#include "mesh/shared.h"
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
24/* Reads the next n body bytes of the request's connection (`req`); false when short. */
25typedef bool (*mesh_control_body)(void *ctx, uint8_t *out, size_t n);
26
27/* One request (its line trimmed) answered into out. */
28void mesh_control_handle(mesh_shared *sh, const char *req, mesh_control_body body, void *ctx, mesh_buf *out);
29/* Serves clients from a listening socket until the process exits (one thread per client). */
30void mesh_control_serve(mesh_shared *sh, int listen_fd);
31/* One client on a connected socket (the serve loop's thread body), idle limit in ms. Closes fd. */
32void mesh_control_client(mesh_shared *sh, int fd, int64_t idle_ms);
33
34/* The text producers other parts reuse: `programs`, `pipes`, `cluster`, the views. */
35void mesh_control_programs(mesh_shared *sh, mesh_buf *out);
36void mesh_control_pipes(mesh_shared *sh, mesh_buf *out);
37void mesh_control_cluster(mesh_shared *sh, mesh_buf *out);
38/* A view (fleet, jobs, pipes) as text or JSON: 0, or -1 and *err ("view \"x\": fleet, jobs or pipes [json]"). */
39int mesh_control_view(mesh_shared *sh, const char *which, bool json, mesh_buf *out, char **err);
40void mesh_control_pipes_recs(mesh_shared *sh, mesh_recs *out);
41
42/* A fleet-rendered image (`render [<job>|latest] [status|ppm|bmp|raw]`): the jobs area's blob thread
43 * answers it when wired; NULL: "the blob thread is gone". */
44extern bool (*mesh_control_render)(mesh_shared *sh, char **words, size_t n, uint8_t **out, size_t *len, char **err);
45
46#endif