80 lines
2.5 KiB
C
80 lines
2.5 KiB
C
/*
|
|
* caching_relay - config parsing + persistent state (in the .jsonc file itself)
|
|
*/
|
|
#ifndef CACHING_RELAY_CONFIG_H
|
|
#define CACHING_RELAY_CONFIG_H
|
|
|
|
#include <stddef.h>
|
|
#include <time.h>
|
|
|
|
/* Maximums to keep things statically sized and simple. */
|
|
#define CR_MAX_ROOT_NPUBS 16
|
|
#define CR_MAX_UPSTREAM 32
|
|
#define CR_MAX_KINDS 32
|
|
#define CR_NPUB_LEN 64 /* npub1... bech32, generous */
|
|
#define CR_URL_LEN 256
|
|
#define CR_HEX_PUBKEY_LEN 65 /* 64 hex chars + NUL */
|
|
|
|
typedef struct {
|
|
int enabled;
|
|
int events_per_tick; /* per-query page size (default 500) */
|
|
int tick_interval_seconds;
|
|
} cr_backfill_config_t;
|
|
|
|
typedef struct {
|
|
int enabled;
|
|
int resubscribe_interval_seconds;
|
|
} cr_live_config_t;
|
|
|
|
/* Persistent state. The per-author until-cursor drain model stores all
|
|
* backfill progress in the caching_followed_pubkeys table, so the only
|
|
* state kept here is the legacy-mode first-time flag (used to drive relay
|
|
* discovery caching behavior). */
|
|
typedef struct {
|
|
long backfilled_until; /* legacy: 0 = first-time startup */
|
|
} cr_state_t;
|
|
|
|
typedef struct {
|
|
char root_npubs[CR_MAX_ROOT_NPUBS][CR_NPUB_LEN];
|
|
int root_npub_count;
|
|
/* Decoded hex pubkeys for root npubs (filled by follow_graph). */
|
|
char root_hex[CR_MAX_ROOT_NPUBS][CR_HEX_PUBKEY_LEN];
|
|
int root_hex_ready;
|
|
|
|
char upstream_relays[CR_MAX_UPSTREAM][CR_URL_LEN];
|
|
int upstream_count;
|
|
|
|
char local_relay[CR_URL_LEN];
|
|
|
|
int kinds[CR_MAX_KINDS];
|
|
int kind_count;
|
|
|
|
/* Kinds to follow specifically for the root (admin) npubs.
|
|
* If admin_all_kinds is 1, grab everything (no kind filter). */
|
|
int admin_kinds[CR_MAX_KINDS];
|
|
int admin_kind_count;
|
|
int admin_all_kinds;
|
|
|
|
cr_backfill_config_t backfill;
|
|
cr_live_config_t live;
|
|
int follow_graph_refresh_seconds;
|
|
|
|
cr_state_t state;
|
|
|
|
/* Path the config was loaded from (for state write-back). */
|
|
char path[1024];
|
|
} cr_config_t;
|
|
|
|
/* Load + validate config from a .jsonc file. Returns 0 on success, -1 on error.
|
|
* On success cfg->path is set and cfg->state is populated from the file. */
|
|
int cr_config_load(cr_config_t *cfg, const char *path);
|
|
|
|
/* Persist the state sub-object back into the config file (temp + rename).
|
|
* Preserves all other config fields. Returns 0 on success, -1 on error. */
|
|
int cr_config_save_state(cr_config_t *cfg);
|
|
|
|
/* Free any heap resources held by cfg (currently none, but kept for future). */
|
|
void cr_config_free(cr_config_t *cfg);
|
|
|
|
#endif /* CACHING_RELAY_CONFIG_H */
|