Documentation
¶
Index ¶
- type ChangefeedEvent
- type CockroachClusterInfo
- type CockroachClusterNode
- type CompiledFilter
- type DB
- func (db *DB) BatchInsertEvents(ctx context.Context, events []nostr.Event) error
- func (db *DB) CleanExpiredEvents(ctx context.Context) (int, error)
- func (db *DB) CloseDB() error
- func (db *DB) CreateDatabaseIfNotExists(ctx context.Context, dbName string) error
- func (db *DB) DeleteExpiredEvents(ctx context.Context) error
- func (db *DB) EventExists(ctx context.Context, eventID string) (bool, error)
- func (db *DB) ExecuteBatch(ctx context.Context, batch *pgx.Batch) error
- func (db *DB) ExecuteCommand(ctx context.Context, query string, args ...interface{}) error
- func (db *DB) ExecuteQuery(ctx context.Context, query string, args ...interface{}) (pgx.Row, error)
- func (db *DB) GetAddressableEvent(ctx context.Context, pubkey string, kind int, dVal string) (nostr.Event, error)
- func (db *DB) GetClusterHealth(ctx context.Context) (map[string]interface{}, error)
- func (db *DB) GetCockroachClusterInfo(ctx context.Context) (*CockroachClusterInfo, error)
- func (db *DB) GetEventByID(ctx context.Context, eventID string) (nostr.Event, error)
- func (db *DB) GetEventCount(ctx context.Context, filter nostr.Filter) (int64, error)
- func (db *DB) GetEvents(ctx context.Context, filter nostr.Filter) ([]nostr.Event, error)
- func (db *DB) GetReplaceableEvent(ctx context.Context, pubkey string, kind int) (nostr.Event, error)
- func (db *DB) GetTotalEventCount(ctx context.Context) (int64, error)
- func (db *DB) InitializeChangefeed(ctx context.Context) error
- func (db *DB) InitializeSchema(ctx context.Context) error
- func (db *DB) InsertAddressableEvent(ctx context.Context, evt nostr.Event) error
- func (db *DB) InsertEvent(ctx context.Context, evt nostr.Event) error
- func (db *DB) InsertReplaceableEvent(ctx context.Context, evt nostr.Event) error
- func (db *DB) Ping() error
- func (db *DB) RebuildBloomFilter(ctx context.Context) error
- func (db *DB) SetEventDispatcher(ed *EventDispatcher)
- func (db *DB) StartExpiredEventsCleaner(ctx context.Context, interval time.Duration)
- func (db *DB) Stats() DatabaseStats
- func (db *DB) VerifySchema(ctx context.Context) error
- type DBState
- type DatabaseStats
- type EventDispatcher
- type EventProcessor
- type EventRowData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangefeedEvent ¶ added in v1.2.0
type ChangefeedEvent struct { Table string `json:"table"` Key []interface{} `json:"key"` Value *EventRowData `json:"value"` After *EventRowData `json:"after"` }
ChangefeedEvent represents a changefeed event from CockroachDB
type CockroachClusterInfo ¶
type CockroachClusterInfo struct { TotalNodes int64 `json:"total_nodes"` LiveNodes int64 `json:"live_nodes"` CurrentNode *CockroachClusterNode `json:"current_node"` AllNodes []*CockroachClusterNode `json:"all_nodes"` ClusterName string `json:"cluster_name"` IsCluster bool `json:"is_cluster"` }
CockroachClusterInfo represents cluster summary information
type CockroachClusterNode ¶
type CockroachClusterNode struct { NodeID int64 `json:"node_id"` Address string `json:"address"` SQLAddress string `json:"sql_address"` Locality string `json:"locality"` ClusterName string `json:"cluster_name"` ServerVersion string `json:"server_version"` BuildTag string `json:"build_tag"` StartedAt time.Time `json:"started_at"` IsLive bool `json:"is_live"` Ranges int64 `json:"ranges"` Leases int64 `json:"leases"` }
CockroachClusterNode represents a node in the CockroachDB cluster
type CompiledFilter ¶
type CompiledFilter struct { IDs map[string]bool Authors map[string]bool Kinds map[int]bool Since *time.Time Until *time.Time Tags map[string]map[string]bool Limit int Search string }
CompiledFilter represents a pre-compiled filter for efficient matching
func CompileFilter ¶
func CompileFilter(f nostr.Filter) *CompiledFilter
CompileFilter pre-compiles a nostr filter for efficient matching
func (*CompiledFilter) BuildQuery ¶
func (cf *CompiledFilter) BuildQuery() (string, []interface{}, error)
BuildQuery constructs the SQL query using the most efficient index
func (*CompiledFilter) GetBestIndex ¶
func (cf *CompiledFilter) GetBestIndex() string
GetBestIndex determines the most efficient index to use for the filter
type DB ¶
type DB struct { Pool *pgxpool.Pool Bloom *bloom.BloomFilter // contains filtered or unexported fields }
DB represents the CockroachDB connection
func InitDB ¶
InitDB initializes the CockroachDB connection with retries and optimized connection pooling
func (*DB) BatchInsertEvents ¶
BatchInsertEvents optimized for CockroachDB with timeout handling
func (*DB) CleanExpiredEvents ¶
CleanExpiredEvents removes events with expiration tags that have passed their expiration time
func (*DB) CreateDatabaseIfNotExists ¶
CreateDatabaseIfNotExists creates the specified database if it doesn't exist
func (*DB) DeleteExpiredEvents ¶
DeleteExpiredEvents removes events that have expired based on the "expiration" tag.
func (*DB) EventExists ¶
func (*DB) ExecuteBatch ¶
ExecuteBatch handles batch inserts or updates
func (*DB) ExecuteCommand ¶
ExecuteCommand handles INSERT, UPDATE, DELETE commands
func (*DB) ExecuteQuery ¶
ExecuteQuery handles single-row queries (SELECT)
func (*DB) GetAddressableEvent ¶
func (db *DB) GetAddressableEvent(ctx context.Context, pubkey string, kind int, dVal string) (nostr.Event, error)
GetAddressableEvent retrieves the latest addressable event for a given pubkey, kind, and 'd' tag.
func (*DB) GetClusterHealth ¶
GetClusterHealth returns cluster health information
func (*DB) GetCockroachClusterInfo ¶
func (db *DB) GetCockroachClusterInfo(ctx context.Context) (*CockroachClusterInfo, error)
GetCockroachClusterInfo retrieves cluster information from CockroachDB
func (*DB) GetEventByID ¶
GetEventByID retrieves a single event by its ID.
func (*DB) GetEventCount ¶
GetEventCount returns the count of events matching the given filter
func (*DB) GetReplaceableEvent ¶
func (db *DB) GetReplaceableEvent(ctx context.Context, pubkey string, kind int) (nostr.Event, error)
GetReplaceableEvent retrieves the latest replaceable event for a given pubkey and kind.
func (*DB) GetTotalEventCount ¶
GetTotalEventCount returns the total number of events stored in the database
func (*DB) InitializeChangefeed ¶ added in v1.2.0
InitializeChangefeed verifies changefeed capability for distributed event synchronization
func (*DB) InitializeSchema ¶
InitializeSchema creates the necessary database and tables if they don't exist
func (*DB) InsertAddressableEvent ¶
InsertAddressableEvent upserts (pubkey, kind, dTag) = unique
func (*DB) InsertEvent ¶
InsertEvent directly inserts a single event
func (*DB) InsertReplaceableEvent ¶
func (*DB) RebuildBloomFilter ¶
RebuildBloomFilter fetches all event IDs from CockroachDB and updates the Bloom filter.
func (*DB) SetEventDispatcher ¶ added in v1.2.0
func (db *DB) SetEventDispatcher(ed *EventDispatcher)
SetEventDispatcher sets the event dispatcher reference for immediate local broadcasting
func (*DB) StartExpiredEventsCleaner ¶
StartExpiredEventsCleaner starts a background goroutine to clean expired events periodically
func (*DB) Stats ¶ added in v1.3.3
func (db *DB) Stats() DatabaseStats
Stats returns database connection pool statistics
type DatabaseStats ¶ added in v1.3.3
type DatabaseStats struct { OpenConnections int InUse int Idle int MaxOpenConnections int MaxIdleConnections int }
DatabaseStats represents database connection pool statistics
type EventDispatcher ¶ added in v1.2.0
type EventDispatcher struct {
// contains filtered or unexported fields
}
EventDispatcher manages real-time event distribution across relay instances
func NewEventDispatcher ¶ added in v1.2.0
func NewEventDispatcher(db *DB) *EventDispatcher
NewEventDispatcher creates a new event dispatcher for real-time events
func (*EventDispatcher) AddClient ¶ added in v1.2.0
func (ed *EventDispatcher) AddClient(clientID string) chan *nostr.Event
AddClient registers a new client for event notifications
func (*EventDispatcher) GetClientCount ¶ added in v1.2.0
func (ed *EventDispatcher) GetClientCount() int
GetClientCount returns the number of active clients
func (*EventDispatcher) RemoveClient ¶ added in v1.2.0
func (ed *EventDispatcher) RemoveClient(clientID string)
RemoveClient unregisters a client from event notifications
func (*EventDispatcher) Start ¶ added in v1.2.0
func (ed *EventDispatcher) Start() error
Start begins listening to the changefeed and processing events
func (*EventDispatcher) Stop ¶ added in v1.2.0
func (ed *EventDispatcher) Stop()
Stop stops the event dispatcher
type EventProcessor ¶
type EventProcessor struct {
// contains filtered or unexported fields
}
EventProcessor manages event processing with a worker pool
func NewEventProcessor ¶
func NewEventProcessor(ctx context.Context, db *DB, bufferSize int) *EventProcessor
NewEventProcessor creates a new event processor
func (*EventProcessor) QueueDeletion ¶
func (ep *EventProcessor) QueueDeletion(evt nostr.Event) bool
QueueDeletion is called by the validator AFTER it has verified that the deleter has the right to try. The function will:
- delete all owned referenced events (same pubkey)
- store the deletion event itself
It reuses the same retry / back‑pressure mechanism.
func (*EventProcessor) QueueEvent ¶
func (ep *EventProcessor) QueueEvent(evt nostr.Event) bool
QueueEvent adds an event to processing queue with non-blocking behavior
func (*EventProcessor) Shutdown ¶
func (ep *EventProcessor) Shutdown()
Shutdown gracefully stops processing
type EventRowData ¶ added in v1.2.0
type EventRowData struct { ID string `json:"id"` PubKey string `json:"pubkey"` CreatedAt int64 `json:"created_at"` Kind int `json:"kind"` Tags json.RawMessage `json:"tags"` Content string `json:"content"` Sig string `json:"sig"` }
EventRowData represents the event data structure from the database
func (*EventRowData) ToNostrEvent ¶ added in v1.2.0
func (e *EventRowData) ToNostrEvent() (*nostr.Event, error)
ToNostrEvent converts EventRowData to a nostr.Event