skip to content
==> include/mesh/host_block.h <==
1/* @ajax/mesh-host-block: the host status block (status.rs HostStatus):
2 * SNAP_HOST bytes, little-endian, written by meshd's threads under one lock,
3 * read whole by the snapshot with the uptime and the live network counters
4 * filled in at that moment (the counters' rates are timed by that uptime). */
5#ifndef MESH_HOST_BLOCK_H
6#define MESH_HOST_BLOCK_H
7
8#include "mesh/abi/snapshot.h"
9#include "mesh/net_counters.h"
10
11#include <pthread.h>
12#include <stddef.h>
13#include <stdint.h>
14
15typedef struct {
16    pthread_mutex_t mu;
17    uint8_t block[MESH_SNAP_HOST];
18    int64_t started_us;
19    mesh_net_counters net; /* the live counters (links, control port, HTTP relay) */
20} mesh_host_block;
21
22/* One field of a consistent set. */
23typedef struct {
24    size_t off;
25    const void *bytes;
26    size_t len;
27} mesh_host_field;
28
29void mesh_host_block_init(mesh_host_block *h);
30void mesh_host_block_set_u32(mesh_host_block *h, size_t off, uint32_t v);
31void mesh_host_block_set_f32(mesh_host_block *h, size_t off, float v);
32void mesh_host_block_set_u64(mesh_host_block *h, size_t off, uint64_t v);
33/* Several fields under one lock (a consistent set for readers). */
34void mesh_host_block_set_many(mesh_host_block *h, const mesh_host_field *f, size_t n);
35/* A u32 counter += n (wrapping). */
36void mesh_host_block_add_u32(mesh_host_block *h, size_t off, uint32_t n);
37/* A NUL-padded string field of len bytes (truncated to len - 1 so it stays terminated). */
38void mesh_host_block_set_str(mesh_host_block *h, size_t off, size_t len, const char *s);
39uint64_t mesh_host_block_uptime_ms(const mesh_host_block *h);
40uint32_t mesh_host_block_get_u32(mesh_host_block *h, size_t off);
41float mesh_host_block_get_f32(mesh_host_block *h, size_t off);
42/* The block with S_UPTIME_MS and the live network counters filled in. */
43void mesh_host_block_bytes(mesh_host_block *h, uint8_t out[MESH_SNAP_HOST]);
44
45#endif