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 ¶
Config holds the configuration for the archive manager.
type EventDeliveryChannel ¶
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 ¶
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.
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) HasQueried ¶
func (qc *QueryCache) HasQueried(f *filter.F) bool
HasQueried returns true if the filter was queried within the TTL.
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 ¶
Query executes a query against the archive relay. Returns a slice of events matching the filter.
Source Files
¶
- archive.go
- connection.go
- query_cache.go