relay

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientInterface

type ClientInterface interface {
	SendMessage(msg interface{})
	// SendMessageBlocking enqueues with backpressure for REQ-fulfillment
	// loops that need producer/consumer rate parity. Never call from
	// BroadcastEvent. Returns non-nil if the client has gone away.
	SendMessageBlocking(msg interface{}) error
	GetWS() *websocket.Conn
	GetSubscriptions() map[string][]Filter
	SetSubscription(subID string, filters []Filter)
	DeleteSubscription(subID string)
	SubscriptionCount() int
	ForEachSubscription(fn func(subID string, filters []Filter))
	CloseClient()
	IsConnected() bool
	// AllowReq checks the client's per-connection REQ rate limiter.
	// Returns (true, "") if allowed, (false, reason) if rate limited.
	AllowReq() (bool, string)
	// AllowEvent checks the client's per-connection event rate limiter.
	AllowEvent(kind int, category string) (bool, string)
}

ClientInterface abstracts WebSocket clients

type Event

type Event struct {
	ID        string     `json:"id"`
	PubKey    string     `json:"pubkey"`
	CreatedAt int64      `json:"created_at"`
	Kind      int        `json:"kind"`
	Tags      [][]string `json:"tags"`
	Content   string     `json:"content"`
	Sig       string     `json:"sig"`
}

type Filter

type Filter struct {
	IDs     []string            `json:"ids,omitempty"`
	Authors []string            `json:"authors,omitempty"`
	Kinds   []int               `json:"kinds,omitempty"`
	Tags    map[string][]string `json:"#,omitempty"` // Fixed: should be "#" for tag filters
	Since   *time.Time          `json:"since,omitempty"`
	Until   *time.Time          `json:"until,omitempty"`
	Limit   *int                `json:"limit,omitempty"`
	Search  string              `json:"search,omitempty"` // NIP-50: fulltext search query
}

Filter represents the criteria used to query events

func (Filter) MatchesEvent added in v0.5.0

func (f Filter) MatchesEvent(evt Event) bool

MatchesEvent returns true if the event satisfies all filter criteria per NIP-01. An empty/zero field means "match all" for that field.

func (Filter) ToSubscriptionFilter added in v0.4.1

func (f Filter) ToSubscriptionFilter() map[string]interface{}

ToSubscriptionFilter converts Filter to a relay-compatible format

type Subscription

type Subscription struct {
	ID      string
	Filters []Filter
}

Jump to

Keyboard shortcuts

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