summaryrefslogtreecommitdiff
path: root/include/hybbx/link.h
blob: 3bd60d1314b953bdb2eb56d8d9e05d83d41de670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef HYBBX_LINK_H
#define HYBBX_LINK_H

/**
 * HyBBX link/repeater edge daemon registry.
 *
 * Roles: gateway, digipeater, repeater, link — edge daemons toward centralized
 * daemon [circuit]. Password auth only (LINK_AUTH); stale prune link_stale_days.
 * INI: [circuit] link_* ; data/links/<id>.ini ; [link.<id>] in hybbx.ini.
 */

#include "hybbx/types.h"
#include "hybbx/limits.h"

#include <stddef.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif

#define HYBBX_LINK_STALE_DAYS       10u
#define HYBBX_LINK_ID_MAX           64
#define HYBBX_LINK_ROLE_MAX         32
#define HYBBX_LINK_CODE_MAX         16
#define HYBBX_LINK_AUTH_PAYLOAD_MAX 512

typedef struct hybbx_link_auth {
    char password[128];
    char role[HYBBX_LINK_ROLE_MAX];
    char id[HYBBX_LINK_ID_MAX];
    unsigned baud;
    int duplex;
    char bandwidth[16];
    char frequency_mhz[16];
} hybbx_link_auth_t;

typedef struct hybbx_link_registry {
    char dir[HYBBX_PATH_MAX];
    char config_path[HYBBX_PATH_MAX];
    unsigned stale_days;
} hybbx_link_registry_t;

void hybbx_link_auth_clear(hybbx_link_auth_t *auth);

/**
 * Build line-oriented LINK_AUTH payload (password=, role=, id=, optional
 * baud=, duplex=, bandwidth= for circuit load-balancing).
 * @return payload length or 0 on error.
 */
size_t hybbx_link_auth_format(const hybbx_link_auth_t *auth,
                              char *out, size_t out_cap);

/** Parse LINK_AUTH payload into @p auth. Returns HYBBX_OK on success. */
hybbx_result_t hybbx_link_auth_parse(const char *payload, size_t len,
                                     hybbx_link_auth_t *auth);

void hybbx_link_registry_init(hybbx_link_registry_t *reg,
                              const char *data_dir,
                              const char *config_path,
                              unsigned stale_days);

/**
 * Record successful password authentication for @p id.
 * Creates or updates @c data/links/<id>.ini and @c [link.<id>] in hybbx.ini.
 */
hybbx_result_t hybbx_link_registry_touch(hybbx_link_registry_t *reg,
                                         const char *id,
                                         const char *role,
                                         char *link_code_out,
                                         size_t link_code_cap);

/**
 * Remove link entries with @c last_seen older than @p stale_days.
 * Also drops matching @c [link.*] sections from hybbx.ini when @p config_path set.
 */
hybbx_result_t hybbx_link_registry_prune(hybbx_link_registry_t *reg);

/** Generate a short link code (uppercase alphanumeric). */
void hybbx_link_generate_code(char *out, size_t out_cap);

#ifdef __cplusplus
}
#endif

#endif /* HYBBX_LINK_H */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com