Files
nostr_terminal/include/net.h
T

96 lines
2.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);
/* 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);
/*
* 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);
/*
* 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 */