Documentation
¶
Index ¶
- Constants
- Variables
- func GetRequest(ctx context.Context) *http.Request
- func ValidClientMsg(msg ClientMsg) bool
- type CacheHandler
- type ClientAuthMsg
- type ClientCloseMsg
- type ClientCountMsg
- type ClientEventMsg
- type ClientMsg
- type ClientReqMsg
- type Config
- type CreatedAtLowerLimitMiddleware
- type CreatedAtUpperLimitMiddleware
- type DefaultSimpleHandlerBase
- type Event
- type EventCache
- type EventCreatedAtMiddleware
- type EventInvalidIDError
- type EventInvalidSigError
- type EventLimitMatcher
- type EventLimitMatchers
- type EventMatcher
- type EventType
- type Handler
- type HandlerFunc
- type LoggingMiddleware
- type MaxContentLengthMiddleware
- type MaxEventTagsMiddleware
- type MaxLimitMiddleware
- type MaxReqFiltersMiddleware
- type MaxSubIDLengthMiddleware
- type MaxSubscriptionsMiddleware
- type MergeHandler
- type Middleware
- type NIP11
- type NIP11Fees
- type NIP11Limitation
- type NIP11Retention
- type NeoHandler
- type NeoHandlerFunc
- type NeoSimpleHandler
- type NeoSimpleHandlerBase
- type Nip11Fee
- type Nip11Kind
- type RecvEventAllowFilterMiddleware
- type RecvEventDenyFilterMiddleware
- type RecvEventUniqueFilterMiddleware
- type Relay
- type RelayOption
- type ReqFilter
- type ReqFilterEventLimitMatcher
- type ReqFiltersLimitMatcher
- type RouterHandler
- type SendEventUniqueFilterMiddleware
- type ServeMux
- type ServerAuthMsg
- type ServerClosedMsg
- type ServerCountMsg
- type ServerEOSEMsg
- type ServerEventMsg
- type ServerMsg
- type ServerNoticeMsg
- type ServerOKMsg
- type SimpleHandler
- type SimpleHandlerBase
- type SimpleMiddlewareBase
- type Tag
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 ValidClientMsg ¶
Types ¶
type CacheHandler ¶
type CacheHandler struct {
// contains filtered or unexported fields
}
func NewCacheHandler ¶
func NewCacheHandler(size int) CacheHandler
func (CacheHandler) ServeNostr ¶
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 ¶
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 ClientReqMsg ¶
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 ¶
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) ServeNostrEnd ¶
func (DefaultSimpleHandlerBase) ServeNostrEnd(ctx context.Context) error
func (DefaultSimpleHandlerBase) ServeNostrStart ¶
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) CreatedAtTime ¶
func (*Event) UnmarshalJSON ¶
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 Handler ¶
type Handler interface {
ServeNostr(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error
}
func NewDefaultHandler ¶
func NewDefaultHandler() Handler
func NewMergeHandler ¶
type HandlerFunc ¶
func (HandlerFunc) ServeNostr ¶
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 ¶
type Middleware ¶
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 ¶
LoadNIP11FromYAML loads NIP-11 information from YAML file
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 NeoHandler ¶
type NeoHandler interface {
NeoServeNostr(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error
}
func NewNeoSimpleHandler ¶
func NewNeoSimpleHandler(base NeoSimpleHandlerBase) NeoHandler
type NeoHandlerFunc ¶
func (NeoHandlerFunc) NeoServeNostr ¶
type NeoSimpleHandler ¶
type NeoSimpleHandler NeoHandlerFunc
type NeoSimpleHandlerBase ¶
type Nip11Kind ¶
type Nip11Kind struct {
From, To int
}
func (Nip11Kind) MarshalJSON ¶
func (Nip11Kind) MarshalYAML ¶
func (*Nip11Kind) UnmarshalJSON ¶
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
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 (*ReqFilter) UnmarshalJSON ¶
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 ¶
type SendEventUniqueFilterMiddleware ¶
type SendEventUniqueFilterMiddleware Middleware
func NewSendEventUniqueFilterMiddleware ¶
func NewSendEventUniqueFilterMiddleware(size int) SendEventUniqueFilterMiddleware
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 ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
type SimpleHandlerBase ¶
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)
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.