diff --git a/relay.pid b/relay.pid index 7556ecf..c919652 100644 --- a/relay.pid +++ b/relay.pid @@ -1 +1 @@ -3579819 +646463 diff --git a/src/main.h b/src/main.h index 0701621..088bb96 100644 --- a/src/main.h +++ b/src/main.h @@ -10,10 +10,10 @@ #define MAIN_H // Version information (auto-updated by build system) -#define VERSION "v0.7.31" +#define VERSION "v0.7.32" #define VERSION_MAJOR 0 #define VERSION_MINOR 7 -#define VERSION_PATCH 31 +#define VERSION_PATCH 32 // Relay metadata (authoritative source for NIP-11 information) #define RELAY_NAME "C-Relay" diff --git a/src/websockets.c b/src/websockets.c index 8e72c8f..4af91e2 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -678,16 +678,24 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso } } } else { - DEBUG_TRACE("Storing regular event in database"); - // Regular event - store in database and broadcast - if (store_event(event) != 0) { - DEBUG_ERROR("Failed to store event in database"); - result = -1; - strncpy(error_message, "error: failed to store event", sizeof(error_message) - 1); - } else { - DEBUG_LOG("Event stored and broadcast (kind %d)", event_kind); - // Broadcast event to matching persistent subscriptions + // Check if this is an ephemeral event (kinds 20000-29999) + // Per NIP-01: ephemeral events are broadcast but never stored + if (event_kind >= 20000 && event_kind < 30000) { + DEBUG_TRACE("Ephemeral event (kind %d) - broadcasting without storage", event_kind); + // Broadcast directly to subscriptions without database storage broadcast_event_to_subscriptions(event); + } else { + DEBUG_TRACE("Storing regular event in database"); + // Regular event - store in database and broadcast + if (store_event(event) != 0) { + DEBUG_ERROR("Failed to store event in database"); + result = -1; + strncpy(error_message, "error: failed to store event", sizeof(error_message) - 1); + } else { + DEBUG_LOG("Event stored and broadcast (kind %d)", event_kind); + // Broadcast event to matching persistent subscriptions + broadcast_event_to_subscriptions(event); + } } } } else { diff --git a/tests/ephemeral_test.sh b/tests/ephemeral_test.sh new file mode 100755 index 0000000..c668f9a --- /dev/null +++ b/tests/ephemeral_test.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Simplified Ephemeral Event Test +# Tests that ephemeral events are broadcast to active subscriptions + +echo "=== Generating Ephemeral Event (kind 20000) ===" +event=$(nak event --kind 20000 --content "test ephemeral event") +echo "$event" +echo "" + +echo "=== Testing Ephemeral Event Broadcast ===" +subscription='["REQ","test_sub",{"kinds":[20000],"limit":10}]' +echo "Subscription Filter:" +echo "$subscription" +echo "" + +event_msg='["EVENT",'"$event"']' +echo "Event Message:" +echo "$event_msg" +echo "" + +echo "=== Relay Responses ===" +( + # Send subscription + printf "%s\n" "$subscription" + # Wait for subscription to establish + sleep 1 + # Send ephemeral event on same connection + printf "%s\n" "$event_msg" + # Wait for responses + sleep 2 +) | timeout 5 websocat ws://127.0.0.1:8888 + +echo "" +echo "Test complete!"