92 lines
3.9 KiB
C
92 lines
3.9 KiB
C
/*
|
|
* C-Relay-PG Main Header - Version and Metadata Information
|
|
*
|
|
* This header contains version information and relay metadata.
|
|
* Version macros are auto-updated by the build system.
|
|
* Relay metadata should be manually maintained.
|
|
*/
|
|
|
|
#ifndef MAIN_H
|
|
#define MAIN_H
|
|
|
|
// Version information (auto-updated by build system)
|
|
// Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros
|
|
#define CRELAY_VERSION_MAJOR 2
|
|
#define CRELAY_VERSION_MINOR 1
|
|
#define CRELAY_VERSION_PATCH 37
|
|
#define CRELAY_VERSION "v2.1.37"
|
|
|
|
// Relay metadata (authoritative source for NIP-11 information)
|
|
#define RELAY_NAME "C-Relay-PG"
|
|
#define RELAY_DESCRIPTION "High-performance C Nostr relay with PostgreSQL storage"
|
|
#define RELAY_CONTACT ""
|
|
#define RELAY_SOFTWARE "https://git.laantungir.net/laantungir/c-relay-pg.git"
|
|
#define RELAY_VERSION CRELAY_VERSION // Use the same version as the build
|
|
#define SUPPORTED_NIPS "1,2,4,9,11,12,13,15,16,20,22,33,40,42,50,70"
|
|
#define LANGUAGE_TAGS ""
|
|
#define RELAY_COUNTRIES ""
|
|
#define POSTING_POLICY ""
|
|
#define PAYMENTS_URL ""
|
|
|
|
// Forward declaration to avoid pulling cJSON headers into all includers.
|
|
typedef struct cJSON cJSON;
|
|
|
|
// Forward declaration for libwebsockets struct (used by ingest_event).
|
|
struct lws;
|
|
|
|
// Async REQ handler status used by websocket callback to defer EOSE until worker completion
|
|
#define HANDLE_REQ_ASYNC_PENDING (-2)
|
|
|
|
// Async EVENT storage split:
|
|
// - store_event_core(): worker-safe core DB write path
|
|
// returns 0 when inserted, 1 when handled without insert (duplicate/ephemeral), -1 on error
|
|
// - store_event_post_actions(): main-thread-only follow-up actions (monitoring/tags/WoT sync)
|
|
// - store_event(): legacy wrapper preserving original behavior for synchronous call sites
|
|
int store_event_core(cJSON* event);
|
|
void store_event_post_actions(cJSON* event);
|
|
int store_event(cJSON* event);
|
|
|
|
// Drains completed async REQ jobs and queues EVENT/EOSE on the lws service thread.
|
|
void process_req_async_completions(void);
|
|
|
|
// Source mode for the shared event ingestion entry point.
|
|
typedef enum {
|
|
EVENT_SOURCE_CLIENT, // Normal WebSocket client event
|
|
EVENT_SOURCE_CACHING_INBOX // Event from the caching inbox (internal import)
|
|
} event_source_t;
|
|
|
|
// Process an event through the authoritative validation and storage pipeline.
|
|
// This is the shared entry point for both client events and caching inbox events.
|
|
//
|
|
// For EVENT_SOURCE_CLIENT: behaves exactly as the current client path does.
|
|
// For EVENT_SOURCE_CACHING_INBOX:
|
|
// - No NIP-42 client authentication requirement
|
|
// - No OK response sent (no wsi)
|
|
// - No administrator command execution (kind 23456 events are stored as data, not processed)
|
|
// - Still validates signature, structure, expiration, PoW
|
|
// - Still handles replaceable/addressable/ephemeral/duplicate/NIP-09 semantics
|
|
// - Still stores through the writer thread pool
|
|
// - Still queues post-actions and broadcast to the main thread
|
|
//
|
|
// Parameters:
|
|
// event_json - raw JSON string of the Nostr event
|
|
// event_json_len - length of the JSON string
|
|
// source - EVENT_SOURCE_CLIENT or EVENT_SOURCE_CACHING_INBOX
|
|
// wsi - WebSocket instance for client responses (NULL for caching inbox)
|
|
// pss - per-session data for client responses (NULL for caching inbox)
|
|
//
|
|
// Returns:
|
|
// 0 = accepted and stored (or duplicate, or ephemeral broadcast)
|
|
// -1 = rejected (validation failure, storage failure)
|
|
int ingest_event(const char* event_json, size_t event_json_len,
|
|
event_source_t source, struct lws* wsi, void* pss);
|
|
|
|
// Drains completed caching-inbox ingestion jobs on the lws service thread.
|
|
// Runs store_event_post_actions() and broadcast_event_to_subscriptions() for
|
|
// events that were stored off the main thread by ingest_event() with
|
|
// EVENT_SOURCE_CACHING_INBOX. Safe to call unconditionally; no-op when empty
|
|
// or when the PostgreSQL backend is not in use.
|
|
void process_inbox_event_completions(void);
|
|
|
|
#endif /* MAIN_H */
|