simple documentation

This commit is contained in:
Vitor Pamplona
2026-03-20 17:15:05 -04:00
parent b247310ba7
commit 9bfb170ffa
3 changed files with 18 additions and 11 deletions
@@ -26,6 +26,16 @@ import com.vitorpamplona.quartz.nip01Core.store.IEventStore
import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
/**
* A reactive event store that combines historical data retrieval with live event streaming.
*
* This class wraps an [IEventStore] to provide real-time updates. When a [query] is executed,
* it first replays all matching historical events from the underlying store, signals the
* End of Stored Events (EOSE), and then continues to stream matching new events as they
* are inserted.
*
* @property store The underlying persistent storage for events.
*/
class LiveEventStore( class LiveEventStore(
private val store: IEventStore, private val store: IEventStore,
) { ) {
@@ -30,18 +30,14 @@ import kotlinx.coroutines.cancel
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
/** /**
* This class manages per-connection subscriptions as coroutines. Each * Represents a Nostr relay server that manages client connections, event storage, and verification.
* subscription ([REQ]) launches a child coroutine that first replays stored
* events matching the filters, sends EOSE, and then streams live events.
* Closing a subscription ([CLOSE]) immediately cancels its coroutine.
* *
* The server is transport-agnostic: callers feed incoming JSON via * This class acts as the central coordinator for a relay server, handling the lifecycle of [RelaySession]s
* [processMessage] and receive outgoing JSON via the [send] callback * and providing access to the underlying event store.
* provided to [connect]. This allows use with any WebSocket library.
* *
* @param store The [EventStore] backing this relay. * @property store The persistent storage engine for Nostr events.
* @param verify Validates incoming events. Defaults to cryptographic * @property parentContext The coroutine context used as a base for the server's execution scope.
* verification (id + signature). Override for testing. * @property verify The function used to validate the integrity and signatures of incoming events.
*/ */
class NostrServer( class NostrServer(
private val store: IEventStore, private val store: IEventStore,
@@ -41,7 +41,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
* Represents a single connected client with its active subscriptions. * Represents an active session between a Nostr client and the relay.
* Each one of these is a connection that can hold many subscriptions
*/ */
class RelaySession( class RelaySession(
private val store: LiveEventStore, private val store: LiveEventStore,