Files
LithosAnanake/v4/include/v4/manage.h
T
2026-10-19 06:35:46 -04:00

111 lines
5.8 KiB
C

/* manage.h -- what a node asks of whoever holds the fabric about nodes and
* capsules. docs/v4.0.0/MESH.md sections 9 and 9a.
*
* Births follow v3 (MESH.md 9): any node may birth, on its own ports, and is
* its child's parent; only Hera may put a node to sleep, wake it or remove
* it. The kernel keeps a registry of the live nodes -- each one's number,
* place and parent -- as v3's kernel keeps its registry of VMs, and checks
* every request against it. A request that is refused is error 12 on the
* node that asked, and changes nothing.
*
* Each request is a word on the node made with KERNEL-WORD (capsules/v4/
* centre.4th, hera.4th), whose number is fixed, below the block requests'
* (v4/blocks.h):
*
* -6 NODE-ME ( -- place ) any node
* -7 NODE-BORN ( number -- place | -1 ) any node in the registry: a node
* is born, empty, and entered with
* the asker as its parent; a number
* that is live, or below 1, is
* refused; -1: no room
* -8 NODE-WIRE ( a pa b pb -- flag ) a and b each the asker or a node
* it birthed
* -9 NODE-UNWIRE ( a pa -- ) a the asker or a node it birthed
* -10 NODE-SLEEP ( number -- ) Hera
* -11 NODE-WAKE ( number -- ) Hera
* -12 NODE-KILL ( number -- ) Hera; not herself; a number not
* live does nothing. The node's
* children are not removed, as v3,
* and become Hera's children. The
* kernel puts a GONE about it on
* every live node's wire from its
* parent: no node hands one on.
* -13 NODE-PARITY ( place number -- ) for a node the asker birthed,
* under the number it was born as
* -14 CAPSULE-OPEN ( baddr u -- flag ) any node in the registry: the
* capsule is found, checked and
* read from its start by that node
* -15 CAPSULE-CELL ( -- w flag ) the next cell of the asker's
* -16 CAPSULE-LINE ( baddr -- u | -1 ) the next line of the asker's
* -17 NODE-CHILD ( number i -- child | 0 ) any node: the i-th live child
* -18 NODE-PLACE ( number -- place | -1 ) any node
*
* A place is where a node is in the fabric (fabric.h): the host's name for
* it. A number is the nodes' own name for it, which messages go by.
*
* Nothing here uses the C library: the bare-metal kernel links this file.
*/
#ifndef V4_MANAGE_H
#define V4_MANAGE_H
#include "v4/fabric.h"
#define V4_REQ_NODE_ME (-6)
#define V4_REQ_NODE_BORN (-7)
#define V4_REQ_NODE_WIRE (-8)
#define V4_REQ_NODE_UNWIRE (-9)
#define V4_REQ_NODE_SLEEP (-10)
#define V4_REQ_NODE_WAKE (-11)
#define V4_REQ_NODE_KILL (-12)
#define V4_REQ_NODE_PARITY (-13)
#define V4_REQ_CAPSULE_OPEN (-14)
#define V4_REQ_CAPSULE_CELL (-15)
#define V4_REQ_CAPSULE_LINE (-16)
#define V4_REQ_NODE_CHILD (-17)
#define V4_REQ_NODE_PLACE (-18)
#define V4_MANAGE_WORDS 13 /* -6 down to -18 */
extern const char *const v4_manage_words[V4_MANAGE_WORDS]; /* [k] is request -6 - k */
#define V4_MANAGE_LINE 64 /* the most characters in a line of a block */
/* A live node: number 0 marks a free entry. */
typedef struct {
v4_cell number;
v4_cell parent; /* the number of the node that birthed it; 0: none */
unsigned place;
} v4_manage_entry;
typedef struct {
v4_fabric *f;
v4_manage_entry *reg; /* the registry: room the owner gives */
unsigned reg_cap;
unsigned hera; /* Hera's place: the one node that may sleep, wake and kill */
/* A node is born: the host finds it room, adds it to the fabric and gives
* it what a node's hardware gives it. Its place, or -1. */
int (*born)(void *self);
/* The node that was at `place` has been removed: its room is free. */
void (*gone)(void *self, unsigned place, v4_fabric_node *was);
/* For the node at `asker`: the capsule called `name`, found, its hash
* and signature checked, and to be read from its start. 1, or 0. */
int (*open)(void *self, unsigned asker, const char *name, unsigned len);
/* The next cell of the capsule `asker` has open: 1 with it in *w, 0 at its end. */
int (*cell)(void *self, unsigned asker, v4_cell *w);
/* The next line of it that is part of a block, at most V4_MANAGE_LINE characters: its length, or -1. */
int (*line)(void *self, unsigned asker, char *text);
/* The node at `place`, numbered `number`: record its parity. */
void (*parity)(void *self, unsigned place, v4_cell number, const v4_node *n);
void *self;
} v4_manage;
/* Enter a node made by the owner -- Hera -- in the registry. 1; 0 if the
* number is below 1, already live, or there is no room. */
int v4_manage_enter(const v4_manage *m, v4_cell number, unsigned place, v4_cell parent);
/* The node at `place` has written `request` to the port its requests go to.
* 0 if it is not one of these, and nothing is done; otherwise 1: it was
* served, its arguments taken from the node's data stack and its results
* left there, or it was refused and error 12 raised on the node. */
int v4_manage_serve(const v4_manage *m, unsigned place, v4_cell request);
#endif /* V4_MANAGE_H */