mocrelay

package module
v0.0.0-...-66ed5fe Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 28 Imported by: 0

README

mocrelay

Go

Nostr relay

Documentation

Index

Constants

View Source
const (
	MsgLabelEvent  = "EVENT"
	MsgLabelReq    = "REQ"
	MsgLabelClose  = "CLOSE"
	MsgLabelAuth   = "AUTH"
	MsgLabelCount  = "COUNT"
	MsgLabelEOSE   = "EOSE"
	MsgLabelNotice = "NOTICE"
	MsgLabelOK     = "OK"
	MsgLabelClosed = "CLOSED"
)
View Source
const (
	MachineReadablePrefixPoW         = "pow: "
	MachineReadablePrefixDuplicate   = "duplicate: "
	MachineReadablePrefixBlocked     = "blocked: "
	MachineReadablePrefixRateLimited = "rate-limited: "
	MachineReadablePrefixInvalid     = "invalid: "
	MachineReadablePrefixError       = "error: "
)

Variables

View Source
var ErrRecvClosed = errors.New("recv closed")
View Source
var ErrRelayStop = errors.New("relay stopped")

Functions

func GetRequest

func GetRequest(ctx context.Context) *http.Request

func ValidClientMsg

func ValidClientMsg(msg ClientMsg) bool

Types

type CacheHandler

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

func NewCacheHandler

func NewCacheHandler(size int) CacheHandler

func (CacheHandler) Dump

func (h CacheHandler) Dump(w io.Writer) error

func (CacheHandler) Restore

func (h CacheHandler) Restore(r io.Reader) error

func (CacheHandler) ServeNostr

func (h CacheHandler) ServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) error

type ClientAuthMsg

type ClientAuthMsg struct {
	Event *Event
}

func NewClientAuthMsg

func NewClientAuthMsg(event *Event) (*ClientAuthMsg, error)

func (*ClientAuthMsg) ClientMsgLabel

func (*ClientAuthMsg) ClientMsgLabel() string

func (ClientAuthMsg) MarshalJSON

func (msg ClientAuthMsg) MarshalJSON() ([]byte, error)

func (*ClientAuthMsg) UnmarshalJSON

func (msg *ClientAuthMsg) UnmarshalJSON(b []byte) error

func (*ClientAuthMsg) Valid

func (msg *ClientAuthMsg) Valid() bool

type ClientCloseMsg

type ClientCloseMsg struct {
	SubscriptionID string
}

func (*ClientCloseMsg) ClientMsgLabel

func (*ClientCloseMsg) ClientMsgLabel() string

func (ClientCloseMsg) MarshalJSON

func (msg ClientCloseMsg) MarshalJSON() ([]byte, error)

func (*ClientCloseMsg) UnmarshalJSON

func (msg *ClientCloseMsg) UnmarshalJSON(b []byte) error

func (*ClientCloseMsg) Valid

func (msg *ClientCloseMsg) Valid() bool

type ClientCountMsg

type ClientCountMsg struct {
	SubscriptionID string
	ReqFilters     []*ReqFilter
}

func (*ClientCountMsg) ClientMsgLabel

func (*ClientCountMsg) ClientMsgLabel() string

func (ClientCountMsg) MarshalJSON

func (msg ClientCountMsg) MarshalJSON() ([]byte, error)

func (*ClientCountMsg) UnmarshalJSON

func (msg *ClientCountMsg) UnmarshalJSON(b []byte) error

func (*ClientCountMsg) Valid

func (msg *ClientCountMsg) Valid() (ok bool)

type ClientEventMsg

type ClientEventMsg struct {
	Event *Event
}

func (*ClientEventMsg) ClientMsgLabel

func (*ClientEventMsg) ClientMsgLabel() string

func (ClientEventMsg) MarshalJSON

func (msg ClientEventMsg) MarshalJSON() ([]byte, error)

func (*ClientEventMsg) UnmarshalJSON

func (msg *ClientEventMsg) UnmarshalJSON(b []byte) error

func (*ClientEventMsg) Valid

func (msg *ClientEventMsg) Valid() bool

type ClientMsg

type ClientMsg interface {
	ClientMsgLabel() string
}

func ParseClientMsg

func ParseClientMsg(b []byte) (msg ClientMsg, err error)

type ClientReqMsg

type ClientReqMsg struct {
	SubscriptionID string
	ReqFilters     []*ReqFilter
}

func (*ClientReqMsg) ClientMsgLabel

func (*ClientReqMsg) ClientMsgLabel() string

func (ClientReqMsg) MarshalJSON

func (msg ClientReqMsg) MarshalJSON() ([]byte, error)

func (*ClientReqMsg) UnmarshalJSON

func (msg *ClientReqMsg) UnmarshalJSON(b []byte) error

func (*ClientReqMsg) Valid

func (msg *ClientReqMsg) Valid() (ok bool)

type Config

type Config struct {
	// Server settings
	ServerAddr         string
	ServerSendTimeout  time.Duration
	ServerPingDuration time.Duration

	// Relay settings
	RelayMaxMessageLength   int64
	RelayRecvRateLimitRate  float64
	RelayRecvRateLimitBurst int

	// Handler settings
	CacheSize  int
	RouterSize int

	// SQLite plugin settings
	SQLiteEnabled            bool
	SQLitePath               string
	SQLiteBulkInsertNum      int
	SQLiteBulkInsertDuration time.Duration
	SQLiteMaxLimit           int

	// Prometheus plugin settings
	PrometheusEnabled bool

	// NIP-11
	NIP11 *NIP11
}

Config holds all configuration loaded from NIP-11 YAML + environment variables

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads configuration from: 1. Default values 2. NIP-11 YAML file (if exists) 3. Environment variables (override)

type CreatedAtLowerLimitMiddleware

type CreatedAtLowerLimitMiddleware Middleware

func NewCreatedAtLowerLimitMiddleware

func NewCreatedAtLowerLimitMiddleware(lower int64) CreatedAtLowerLimitMiddleware

type CreatedAtUpperLimitMiddleware

type CreatedAtUpperLimitMiddleware Middleware

func NewCreatedAtUpperLimitMiddleware

func NewCreatedAtUpperLimitMiddleware(upper int64) CreatedAtUpperLimitMiddleware

type DefaultSimpleHandlerBase

type DefaultSimpleHandlerBase struct{}

func (DefaultSimpleHandlerBase) ServeNostrClientMsg

func (DefaultSimpleHandlerBase) ServeNostrClientMsg(
	ctx context.Context,
	msg ClientMsg,
) (<-chan ServerMsg, error)

func (DefaultSimpleHandlerBase) ServeNostrEnd

func (DefaultSimpleHandlerBase) ServeNostrEnd(ctx context.Context) error

func (DefaultSimpleHandlerBase) ServeNostrStart

func (DefaultSimpleHandlerBase) ServeNostrStart(ctx context.Context) (context.Context, error)

type Event

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

func (*Event) Address

func (ev *Event) Address() string

func (*Event) CreatedAtTime

func (ev *Event) CreatedAtTime() time.Time

func (*Event) EventType

func (ev *Event) EventType() EventType

func (*Event) Serialize

func (ev *Event) Serialize() ([]byte, error)

func (*Event) UnmarshalJSON

func (ev *Event) UnmarshalJSON(b []byte) error

func (*Event) Valid

func (ev *Event) Valid() bool

func (*Event) Verify

func (ev *Event) Verify() (bool, error)

type EventCache

type EventCache struct {
	Cap int
	// contains filtered or unexported fields
}

func NewEventCache

func NewEventCache(capacity int) *EventCache

func (*EventCache) Add

func (c *EventCache) Add(event *Event) (added bool)

func (*EventCache) Find

func (c *EventCache) Find(filters []*ReqFilter) []*Event

func (*EventCache) Len

func (c *EventCache) Len() int

type EventCreatedAtMiddleware

type EventCreatedAtMiddleware Middleware

func NewEventCreatedAtMiddleware

func NewEventCreatedAtMiddleware(
	from, to time.Duration,
) EventCreatedAtMiddleware

type EventInvalidIDError

type EventInvalidIDError struct {
	Correct, Actual string
}

func (*EventInvalidIDError) Error

func (e *EventInvalidIDError) Error() string

type EventInvalidSigError

type EventInvalidSigError struct {
	Correct, Actual string
}

func (*EventInvalidSigError) Error

func (e *EventInvalidSigError) Error() string

type EventLimitMatcher

type EventLimitMatcher interface {
	EventMatcher
	LimitMatch(*Event) bool
	Done() bool
}

type EventLimitMatchers

type EventLimitMatchers[T EventLimitMatcher] []T

func NewReqFiltersEventLimitMatcher

func NewReqFiltersEventLimitMatcher(
	filters []*ReqFilter,
) EventLimitMatchers[*ReqFilterEventLimitMatcher]

func (EventLimitMatchers[T]) Done

func (m EventLimitMatchers[T]) Done() bool

func (EventLimitMatchers[T]) LimitMatch

func (m EventLimitMatchers[T]) LimitMatch(event *Event) bool

func (EventLimitMatchers[T]) Match

func (m EventLimitMatchers[T]) Match(event *Event) bool

type EventMatcher

type EventMatcher interface {
	Match(*Event) bool
}

type EventType

type EventType int
const (
	EventTypeUnknown EventType = iota
	EventTypeRegular
	EventTypeReplaceable
	EventTypeEphemeral
	EventTypeParamReplaceable
)

type Handler

type Handler interface {
	ServeNostr(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error
}

func NewDefaultHandler

func NewDefaultHandler() Handler

func NewMergeHandler

func NewMergeHandler(handlers ...Handler) Handler

type HandlerFunc

type HandlerFunc func(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error

func (HandlerFunc) ServeNostr

func (f HandlerFunc) ServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) error

type LoggingMiddleware

type LoggingMiddleware Middleware

func NewLoggingMiddleware

func NewLoggingMiddleware(logger *slog.Logger) LoggingMiddleware

type MaxContentLengthMiddleware

type MaxContentLengthMiddleware Middleware

func NewMaxContentLengthMiddleware

func NewMaxContentLengthMiddleware(maxContentLength int) MaxContentLengthMiddleware

type MaxEventTagsMiddleware

type MaxEventTagsMiddleware Middleware

func NewMaxEventTagsMiddleware

func NewMaxEventTagsMiddleware(maxEventTags int) MaxEventTagsMiddleware

type MaxLimitMiddleware

type MaxLimitMiddleware Middleware

func NewMaxLimitMiddleware

func NewMaxLimitMiddleware(maxLimit int) MaxLimitMiddleware

type MaxReqFiltersMiddleware

type MaxReqFiltersMiddleware Middleware

func NewMaxReqFiltersMiddleware

func NewMaxReqFiltersMiddleware(maxFilters int) MaxReqFiltersMiddleware

type MaxSubIDLengthMiddleware

type MaxSubIDLengthMiddleware Middleware

func NewMaxSubIDLengthMiddleware

func NewMaxSubIDLengthMiddleware(maxSubIDLength int) MaxSubIDLengthMiddleware

type MaxSubscriptionsMiddleware

type MaxSubscriptionsMiddleware Middleware

func NewMaxSubscriptionsMiddleware

func NewMaxSubscriptionsMiddleware(maxSubs int) MaxSubscriptionsMiddleware

type MergeHandler

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

func (*MergeHandler) ServeNostr

func (h *MergeHandler) ServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) error

type Middleware

type Middleware func(Handler) Handler

func BuildMiddlewareFromNIP11

func BuildMiddlewareFromNIP11(nip11 *NIP11) Middleware

func NewSimpleMiddleware

func NewSimpleMiddleware(base SimpleMiddlewareBase) Middleware

type NIP11

type NIP11 struct {
	Name          string           `json:"name,omitempty" yaml:"name,omitempty"`
	Description   string           `json:"description,omitempty" yaml:"description,omitempty"`
	Pubkey        string           `json:"pubkey,omitempty" yaml:"pubkey,omitempty"`
	Contact       string           `json:"contact,omitempty" yaml:"contact,omitempty"`
	SupportedNIPs []int            `json:"supported_nips,omitempty" yaml:"supported_nips,omitempty"`
	Software      string           `json:"software,omitempty" yaml:"software,omitempty"`
	Version       string           `json:"version,omitempty" yaml:"version,omitempty"`
	Limitation    *NIP11Limitation `json:"limitation,omitempty" yaml:"limitation,omitempty"`
	Retention     *NIP11Retention  `json:"retention,omitempty" yaml:"retention,omitempty"`
	RelayContries []string         `json:"relay_countries,omitempty" yaml:"relay_countries,omitempty"`
	LanguageTags  []string         `json:"language_tags,omitempty" yaml:"language_tags,omitempty"`
	Tags          []string         `json:"tags,omitempty" yaml:"tags,omitempty"`
	PostingPolicy string           `json:"posting_policy,omitempty" yaml:"posting_policy,omitempty"`
	PaymentsURL   string           `json:"payments_url,omitempty" yaml:"payments_url,omitempty"`
	Fees          *NIP11Fees       `json:"fees,omitempty" yaml:"fees,omitempty"`
	Icon          string           `json:"icon,omitempty" yaml:"icon,omitempty"`
}

func LoadNIP11FromYAML

func LoadNIP11FromYAML(path string) (*NIP11, error)

LoadNIP11FromYAML loads NIP-11 information from YAML file

func (*NIP11) ServeHTTP

func (nip11 *NIP11) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NIP11Fees

type NIP11Fees struct {
	Admission    []*Nip11Fee `json:"admission,omitempty" yaml:"admission,omitempty"`
	Subscription []*Nip11Fee `json:"subscription,omitempty" yaml:"subscription,omitempty"`
	Publication  []*Nip11Fee `json:"publication,omitempty" yaml:"publication,omitempty"`
}

type NIP11Limitation

type NIP11Limitation struct {
	MaxMessageLength    int   `json:"max_message_length,omitempty" yaml:"max_message_length,omitempty"`
	MaxSubscriptions    int   `json:"max_subscriptions,omitempty" yaml:"max_subscriptions,omitempty"`
	MaxFilters          int   `json:"max_filters,omitempty" yaml:"max_filters,omitempty"`
	MaxLimit            int   `json:"max_limit,omitempty" yaml:"max_limit,omitempty"`
	MaxSubIDLength      int   `json:"max_subid_length,omitempty" yaml:"max_subid_length,omitempty"`
	MaxEventTags        int   `json:"max_event_tags,omitempty" yaml:"max_event_tags,omitempty"`
	MaxContentLength    int   `json:"max_content_length,omitempty" yaml:"max_content_length,omitempty"`
	MinPoWDifficulty    int   `json:"min_pow_difficulty,omitempty" yaml:"min_pow_difficulty,omitempty"`
	AuthRequired        bool  `json:"auth_required,omitempty" yaml:"auth_required,omitempty"`
	PaymentRequired     bool  `json:"payment_required,omitempty" yaml:"payment_required,omitempty"`
	CreatedAtLowerLimit int64 `json:"created_at_lower_limit,omitempty" yaml:"created_at_lower_limit,omitempty"`
	CreatedAtUpperLimit int64 `json:"created_at_upper_limit,omitempty" yaml:"created_at_upper_limit,omitempty"`
}

type NIP11Retention

type NIP11Retention struct {
	Kinds []*Nip11Kind `json:"kinds,omitempty" yaml:"kinds,omitempty"`
	Time  *int         `json:"time,omitempty" yaml:"time,omitempty"`
	Count *int         `json:"count,omitempty" yaml:"count,omitempty"`
}

type NeoHandler

type NeoHandler interface {
	NeoServeNostr(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error
}

func NewNeoSimpleHandler

func NewNeoSimpleHandler(base NeoSimpleHandlerBase) NeoHandler

type NeoHandlerFunc

type NeoHandlerFunc func(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error

func (NeoHandlerFunc) NeoServeNostr

func (f NeoHandlerFunc) NeoServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) error

type NeoSimpleHandler

type NeoSimpleHandler NeoHandlerFunc

type NeoSimpleHandlerBase

type NeoSimpleHandlerBase interface {
	NeoServeNostrOnStart(ctx context.Context) (newCtx context.Context, err error)
	NeoServeNostrClientMsg(ctx context.Context, msg ClientMsg) (<-chan ServerMsg, error)
	NeoServeNostrOnEnd(ctx context.Context, serveErr error) error
}

type Nip11Fee

type Nip11Fee struct {
	Kinds  []*Nip11Kind `json:"kinds,omitempty" yaml:"kinds,omitempty"`
	Amount int          `json:"amount" yaml:"amount"`
	Unit   string       `json:"unit,omitempty" yaml:"unit,omitempty"`
	Period *int         `json:"period,omitempty" yaml:"period,omitempty"`
}

type Nip11Kind

type Nip11Kind struct {
	From, To int
}

func (Nip11Kind) MarshalJSON

func (k Nip11Kind) MarshalJSON() ([]byte, error)

func (Nip11Kind) MarshalYAML

func (k Nip11Kind) MarshalYAML() (any, error)

func (*Nip11Kind) UnmarshalJSON

func (k *Nip11Kind) UnmarshalJSON(data []byte) error

func (*Nip11Kind) UnmarshalYAML

func (k *Nip11Kind) UnmarshalYAML(node *yaml.Node) error

type RecvEventAllowFilterMiddleware

type RecvEventAllowFilterMiddleware Middleware

func NewRecvEventAllowFilterMiddleware

func NewRecvEventAllowFilterMiddleware(matcher EventMatcher) RecvEventAllowFilterMiddleware

type RecvEventDenyFilterMiddleware

type RecvEventDenyFilterMiddleware Middleware

func NewRecvEventDenyFilterMiddleware

func NewRecvEventDenyFilterMiddleware(matcher EventMatcher) RecvEventDenyFilterMiddleware

type RecvEventUniqueFilterMiddleware

type RecvEventUniqueFilterMiddleware Middleware

func NewRecvEventUniqueFilterMiddleware

func NewRecvEventUniqueFilterMiddleware(size int) RecvEventUniqueFilterMiddleware

type Relay

type Relay struct {
	Handler Handler
	// contains filtered or unexported fields
}

func NewRelay

func NewRelay(handler Handler, option *RelayOption) *Relay

func (*Relay) ServeHTTP

func (relay *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Relay) Wait

func (relay *Relay) Wait()

type RelayOption

type RelayOption struct {
	Logger *slog.Logger

	SendTimeout time.Duration

	RecvRateLimitRate  float64
	RecvRateLimitBurst int

	MaxMessageLength int64

	PingDuration time.Duration
}

func NewDefaultRelayOption

func NewDefaultRelayOption() *RelayOption

type ReqFilter

type ReqFilter struct {
	IDs     []string
	Authors []string
	Kinds   []int64
	Tags    map[string][]string
	Since   *int64
	Until   *int64
	Limit   *int64
}

func (ReqFilter) MarshalJSON

func (fil ReqFilter) MarshalJSON() ([]byte, error)

func (*ReqFilter) UnmarshalJSON

func (fil *ReqFilter) UnmarshalJSON(b []byte) error

func (*ReqFilter) Valid

func (fil *ReqFilter) Valid() (ok bool)

type ReqFilterEventLimitMatcher

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

func NewReqFilterMatcher

func NewReqFilterMatcher(filter *ReqFilter) *ReqFilterEventLimitMatcher

func (*ReqFilterEventLimitMatcher) Done

func (m *ReqFilterEventLimitMatcher) Done() bool

func (*ReqFilterEventLimitMatcher) LimitMatch

func (m *ReqFilterEventLimitMatcher) LimitMatch(event *Event) bool

func (*ReqFilterEventLimitMatcher) Match

func (m *ReqFilterEventLimitMatcher) Match(event *Event) bool

type ReqFiltersLimitMatcher

type ReqFiltersLimitMatcher []*ReqFilterEventLimitMatcher

type RouterHandler

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

func NewRouterHandler

func NewRouterHandler(buflen int) *RouterHandler

func (*RouterHandler) ServeNostr

func (router *RouterHandler) ServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) (err error)

type SendEventUniqueFilterMiddleware

type SendEventUniqueFilterMiddleware Middleware

func NewSendEventUniqueFilterMiddleware

func NewSendEventUniqueFilterMiddleware(size int) SendEventUniqueFilterMiddleware

type ServeMux

type ServeMux struct {
	Relay   *Relay
	NIP11   *NIP11
	Default http.Handler
	Logger  *slog.Logger
}

func (*ServeMux) ServeHTTP

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerAuthMsg

type ServerAuthMsg struct {
	Challenge string
}

func (ServerAuthMsg) MarshalJSON

func (msg ServerAuthMsg) MarshalJSON() ([]byte, error)

func (*ServerAuthMsg) ServerMsgLabel

func (*ServerAuthMsg) ServerMsgLabel() string

func (*ServerAuthMsg) UnmarshalJSON

func (msg *ServerAuthMsg) UnmarshalJSON(b []byte) error

func (*ServerAuthMsg) Valid

func (msg *ServerAuthMsg) Valid() bool

type ServerClosedMsg

type ServerClosedMsg struct {
	SubscriptionID string
	Msg            string
	MsgPrefix      string
}

func NewServerClosedMsg

func NewServerClosedMsg(subID string, prefix, msg string) *ServerClosedMsg

func NewServerClosedMsgf

func NewServerClosedMsgf(subID string, prefix, format string, a ...any) *ServerClosedMsg

func (ServerClosedMsg) MarshalJSON

func (msg ServerClosedMsg) MarshalJSON() ([]byte, error)

func (*ServerClosedMsg) Message

func (msg *ServerClosedMsg) Message() string

func (*ServerClosedMsg) ServerMsgLabel

func (*ServerClosedMsg) ServerMsgLabel() string

func (*ServerClosedMsg) UnmarshalJSON

func (msg *ServerClosedMsg) UnmarshalJSON(b []byte) error

type ServerCountMsg

type ServerCountMsg struct {
	SubscriptionID string
	Count          uint64
	Approximate    *bool
}

func NewServerCountMsg

func NewServerCountMsg(subID string, count uint64, approx *bool) *ServerCountMsg

func (ServerCountMsg) MarshalJSON

func (msg ServerCountMsg) MarshalJSON() ([]byte, error)

func (*ServerCountMsg) ServerMsgLabel

func (*ServerCountMsg) ServerMsgLabel() string

func (*ServerCountMsg) UnmarshalJSON

func (msg *ServerCountMsg) UnmarshalJSON(b []byte) error

type ServerEOSEMsg

type ServerEOSEMsg struct {
	SubscriptionID string
}

func NewServerEOSEMsg

func NewServerEOSEMsg(subID string) *ServerEOSEMsg

func (ServerEOSEMsg) MarshalJSON

func (msg ServerEOSEMsg) MarshalJSON() ([]byte, error)

func (*ServerEOSEMsg) ServerMsgLabel

func (*ServerEOSEMsg) ServerMsgLabel() string

func (*ServerEOSEMsg) UnmarshalJSON

func (msg *ServerEOSEMsg) UnmarshalJSON(b []byte) error

type ServerEventMsg

type ServerEventMsg struct {
	SubscriptionID string
	Event          *Event
}

func NewServerEventMsg

func NewServerEventMsg(subID string, event *Event) *ServerEventMsg

func (ServerEventMsg) MarshalJSON

func (msg ServerEventMsg) MarshalJSON() ([]byte, error)

func (*ServerEventMsg) ServerMsgLabel

func (*ServerEventMsg) ServerMsgLabel() string

func (*ServerEventMsg) UnmarshalJSON

func (msg *ServerEventMsg) UnmarshalJSON(b []byte) error

type ServerMsg

type ServerMsg interface {
	ServerMsgLabel() string
}

type ServerNoticeMsg

type ServerNoticeMsg struct {
	Message string
}

func NewServerNoticeMsg

func NewServerNoticeMsg(message string) *ServerNoticeMsg

func NewServerNoticeMsgf

func NewServerNoticeMsgf(format string, a ...any) *ServerNoticeMsg

func (ServerNoticeMsg) MarshalJSON

func (msg ServerNoticeMsg) MarshalJSON() ([]byte, error)

func (*ServerNoticeMsg) ServerMsgLabel

func (*ServerNoticeMsg) ServerMsgLabel() string

func (*ServerNoticeMsg) UnmarshalJSON

func (msg *ServerNoticeMsg) UnmarshalJSON(b []byte) error

type ServerOKMsg

type ServerOKMsg struct {
	EventID   string
	Accepted  bool
	Msg       string
	MsgPrefix string
}

func NewServerOKMsg

func NewServerOKMsg(eventID string, accepted bool, prefix, msg string) *ServerOKMsg

func (ServerOKMsg) MarshalJSON

func (msg ServerOKMsg) MarshalJSON() ([]byte, error)

func (*ServerOKMsg) Message

func (msg *ServerOKMsg) Message() string

func (*ServerOKMsg) ServerMsgLabel

func (*ServerOKMsg) ServerMsgLabel() string

func (*ServerOKMsg) UnmarshalJSON

func (msg *ServerOKMsg) UnmarshalJSON(b []byte) error

type SimpleHandler

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

func NewSimpleHandler

func NewSimpleHandler(base SimpleHandlerBase) *SimpleHandler

func (*SimpleHandler) ServeNostr

func (h *SimpleHandler) ServeNostr(
	ctx context.Context,
	send chan<- ServerMsg,
	recv <-chan ClientMsg,
) error

type SimpleHandlerBase

type SimpleHandlerBase interface {
	ServeNostrStart(context.Context) (context.Context, error)
	ServeNostrEnd(context.Context) error
	ServeNostrClientMsg(context.Context, ClientMsg) (<-chan ServerMsg, error)
}

type SimpleMiddlewareBase

type SimpleMiddlewareBase interface {
	ServeNostrStart(context.Context) (context.Context, error)
	ServeNostrEnd(context.Context) error
	ServeNostrClientMsg(context.Context, ClientMsg) (<-chan ClientMsg, <-chan ServerMsg, error)
	ServeNostrServerMsg(context.Context, ServerMsg) (<-chan ServerMsg, error)
}

type Tag

type Tag []string

func (Tag) Key

func (t Tag) Key() string

func (Tag) Value

func (t Tag) Value() string

Directories

Path Synopsis
cmd
mocrelay command
handler
middleware

Jump to

Keyboard shortcuts

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