Add enhanced subscription functionality with EOSE result modes

This commit is contained in:
2025-10-02 15:00:50 -04:00
parent 0f897ab1b3
commit 54a6044083
12 changed files with 19452 additions and 1517 deletions

Binary file not shown.

View File

@@ -73,13 +73,22 @@ void on_event(cJSON* event, const char* relay_url, void* user_data) {
}
// EOSE callback - called when End of Stored Events is received
void on_eose(void* user_data) {
void on_eose(cJSON** events, int event_count, void* user_data) {
(void)user_data;
time_t now = time(NULL);
char timestamp[26];
ctime_r(&now, timestamp);
timestamp[24] = '\0';
dprintf(log_fd, "[%s] 📋 EOSE received - all stored events delivered\n\n", timestamp);
dprintf(log_fd, "[%s] 📋 EOSE received - %d events collected\n", timestamp, event_count);
// Log collected events if any
for (int i = 0; i < event_count; i++) {
cJSON* id = cJSON_GetObjectItem(events[i], "id");
if (id && cJSON_IsString(id)) {
dprintf(log_fd, " Event %d: %.12s...\n", i + 1, cJSON_GetStringValue(id));
}
}
dprintf(log_fd, "\n");
}
// Background polling thread
@@ -270,7 +279,7 @@ void add_subscription() {
int close_on_eose = (close_input && strcmp(close_input, "y") == 0) ? 1 : 0;
free(close_input);
// Create subscription
// Create subscription with new parameters
nostr_pool_subscription_t* sub = nostr_relay_pool_subscribe(
pool,
(const char**)relay_urls,
@@ -279,7 +288,11 @@ void add_subscription() {
on_event,
on_eose,
NULL,
close_on_eose
close_on_eose,
1, // enable_deduplication
NOSTR_POOL_EOSE_FULL_SET, // result_mode
30, // relay_timeout_seconds
60 // eose_timeout_seconds
);
// Free relay URLs

Binary file not shown.

View File

@@ -62,9 +62,17 @@ void on_event(cJSON* event, const char* relay_url, void* user_data) {
}
// EOSE callback - called when End of Stored Events is received
void on_eose(void* user_data) {
void on_eose(cJSON** events, int event_count, void* user_data) {
(void)user_data; // Suppress unused parameter warning
printf("📋 EOSE received - all stored events delivered\n");
printf("📋 EOSE received - %d events collected\n", event_count);
// Log collected events if any
for (int i = 0; i < event_count; i++) {
cJSON* id = cJSON_GetObjectItem(events[i], "id");
if (id && cJSON_IsString(id)) {
printf(" Event %d: %.12s...\n", i + 1, cJSON_GetStringValue(id));
}
}
fflush(stdout);
}
@@ -174,7 +182,7 @@ int main() {
printf("%s\n\n", filter_json);
free(filter_json);
// Create subscription
// Create subscription with new parameters
nostr_pool_subscription_t* subscription = nostr_relay_pool_subscribe(
pool,
relay_urls,
@@ -183,7 +191,11 @@ int main() {
on_event, // Event callback
on_eose, // EOSE callback
NULL, // User data (not used)
0 // close_on_eose (false - keep subscription open)
0, // close_on_eose (false - keep subscription open)
1, // enable_deduplication
NOSTR_POOL_EOSE_FULL_SET, // result_mode
30, // relay_timeout_seconds
60 // eose_timeout_seconds
);
if (!subscription) {