121 lines
3.9 KiB
C
121 lines
3.9 KiB
C
#ifndef NET_H
|
|
#define NET_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
char *relay_url;
|
|
int posted;
|
|
char *response;
|
|
} nt_publish_result_t;
|
|
|
|
/*
|
|
* Publish a pre-built event JSON to relays with per-relay result capture.
|
|
* Returns number of relays that acknowledged with OK=true.
|
|
* On success, caller owns results_out and must free via nt_publish_results_free().
|
|
*/
|
|
int nt_publish_detailed(const char *event_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
nt_publish_result_t **results_out,
|
|
int *result_count_out);
|
|
|
|
/*
|
|
* Publish wrapper that only returns accepted relay count.
|
|
*/
|
|
int nt_publish(const char *event_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms);
|
|
|
|
/*
|
|
* Same as nt_publish_detailed(), but skips db relay-post logging.
|
|
* Intended for background worker usage when DB handle is thread-affine.
|
|
*/
|
|
int nt_publish_detailed_nodb(const char *event_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
nt_publish_result_t **results_out,
|
|
int *result_count_out);
|
|
|
|
/* Free result array returned by nt_publish_detailed(). */
|
|
void nt_publish_results_free(nt_publish_result_t *results, int result_count);
|
|
|
|
/*
|
|
* Run a synchronous REQ query across relays, deduplicating by event id.
|
|
* On success returns 0 and sets events_out/event_count (caller frees strings and array).
|
|
* Returns -1 only when every relay fails.
|
|
*/
|
|
int nt_query_sync(const char *filter_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
char ***events_out,
|
|
int *event_count);
|
|
|
|
/*
|
|
* Same as nt_query_sync, but with optional user-facing progress output.
|
|
* If verbose != 0 and phase_label is provided, status lines are printed.
|
|
*/
|
|
int nt_query_sync_verbose(const char *filter_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
const char *phase_label,
|
|
int verbose,
|
|
char ***events_out,
|
|
int *event_count);
|
|
|
|
/*
|
|
* Query relays and return only the newest event found (by created_at).
|
|
* On success returns 0, sets event_out to malloc'd JSON string or NULL if none.
|
|
*/
|
|
int nt_get_first(const char *filter_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
char **event_out);
|
|
|
|
typedef void (*nt_event_callback_t)(const char *event_json, void *userdata);
|
|
|
|
/*
|
|
* Same as nt_get_first, but with optional user-facing progress output.
|
|
*/
|
|
int nt_get_first_verbose(const char *filter_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
int timeout_ms,
|
|
const char *phase_label,
|
|
int verbose,
|
|
char **event_out);
|
|
|
|
/*
|
|
* Blocking live subscription. Connects to relays, sends REQ with given filter,
|
|
* and calls on_event for each incoming EVENT. Returns when user presses any key
|
|
* or on timeout/error.
|
|
* Returns number of events received, or -1 on total failure.
|
|
*/
|
|
int nt_live_feed(const char *filter_json,
|
|
const char **relay_urls,
|
|
int relay_count,
|
|
nt_event_callback_t on_event,
|
|
void *userdata);
|
|
|
|
/*
|
|
* Fetch relay NIP-11 information document.
|
|
*
|
|
* Current implementation in nt is a stub for static MUSL builds and
|
|
* returns -1 (no HTTP client linked).
|
|
*/
|
|
int nt_fetch_nip11(const char *relay_url, char **info_json_out);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* NET_H */
|