diff options
Diffstat (limited to 'include/hybbx/link.h')
| -rw-r--r-- | include/hybbx/link.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/include/hybbx/link.h b/include/hybbx/link.h new file mode 100644 index 0000000..3bd60d1 --- /dev/null +++ b/include/hybbx/link.h @@ -0,0 +1,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 */ |
