archive

package
v0.52.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2026 License: Unlicense Imports: 12 Imported by: 0

Documentation

Overview

Package archive provides query augmentation from authoritative archive relays. It manages connections to archive relays and fetches events that match local queries, caching them locally for future access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchiveDatabase

type ArchiveDatabase interface {
	SaveEvent(ctx context.Context, ev *event.E) (exists bool, err error)
}

ArchiveDatabase defines the interface for storing fetched events.

type Config

type Config struct {
	Enabled     bool
	Relays      []string
	TimeoutSec  int
	CacheTTLHrs int
}

Config holds the configuration for the archive manager.

type EventDeliveryChannel

type EventDeliveryChannel interface {
	SendEvent(ev *event.E) error
	IsConnected() bool
}

EventDeliveryChannel defines the interface for streaming results back to clients.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles connections to archive relays for query augmentation.

func New

func New(ctx context.Context, db ArchiveDatabase, cfg Config) *Manager

New creates a new archive manager.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

IsEnabled returns whether the archive manager is enabled.

func (*Manager) QueryArchive

func (m *Manager) QueryArchive(
	subID string,
	connID string,
	f *filter.F,
	delivered map[string]struct{},
	listener EventDeliveryChannel,
)

QueryArchive queries archive relays asynchronously and stores/streams results. This should be called in a goroutine after returning local results.

Parameters:

  • subID: the subscription ID for the query
  • connID: the connection ID (for access tracking)
  • f: the filter to query
  • delivered: map of event IDs already delivered to the client
  • listener: optional channel to stream results back (may be nil)

func (*Manager) Stats

func (m *Manager) Stats() ManagerStats

Stats returns current archive manager statistics.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the archive manager and closes all connections.

type ManagerStats

type ManagerStats struct {
	Enabled          bool
	TotalRelays      int
	ConnectedRelays  int
	CachedQueries    int
	MaxCachedQueries int
}

ManagerStats holds archive manager statistics.

type QueryCache

type QueryCache struct {
	// contains filtered or unexported fields
}

QueryCache tracks which filters have been queried recently to avoid repeated requests to archive relays for the same filter.

func NewQueryCache

func NewQueryCache(ttl time.Duration, maxSize int) *QueryCache

NewQueryCache creates a new query cache.

func (*QueryCache) Clear

func (qc *QueryCache) Clear()

Clear removes all entries from the cache.

func (*QueryCache) HasQueried

func (qc *QueryCache) HasQueried(f *filter.F) bool

HasQueried returns true if the filter was queried within the TTL.

func (*QueryCache) Len

func (qc *QueryCache) Len() int

Len returns the number of cached queries.

func (*QueryCache) MarkQueried

func (qc *QueryCache) MarkQueried(f *filter.F)

MarkQueried marks a filter as having been queried.

func (*QueryCache) MaxSize

func (qc *QueryCache) MaxSize() int

MaxSize returns the maximum cache size.

type RelayConnection

type RelayConnection struct {
	// contains filtered or unexported fields
}

RelayConnection manages a single archive relay connection.

func NewRelayConnection

func NewRelayConnection(parentCtx context.Context, url string) *RelayConnection

NewRelayConnection creates a new relay connection.

func (*RelayConnection) Close

func (rc *RelayConnection) Close()

Close closes the relay connection.

func (*RelayConnection) Connect

func (rc *RelayConnection) Connect() error

Connect establishes a connection to the archive relay.

func (*RelayConnection) IsConnected

func (rc *RelayConnection) IsConnected() bool

IsConnected returns whether the relay is currently connected.

func (*RelayConnection) Query

func (rc *RelayConnection) Query(ctx context.Context, f *filter.F) ([]*event.E, error)

Query executes a query against the archive relay. Returns a slice of events matching the filter.

func (*RelayConnection) URL

func (rc *RelayConnection) URL() string

URL returns the relay URL.

Source Files

  • archive.go
  • connection.go
  • query_cache.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL