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 ClientUnknownMsg
- type CreatedAtLowerLimitMiddleware
- type CreatedAtUpperLimitMiddleware
- type DefaultSimpleHandlerBase
- type Event
- type EventCache
- type EventCountMatcher
- type EventCountMatchers
- type EventCreatedAtMiddleware
- type EventInvalidIDError
- type EventInvalidSigError
- 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 RecvEventAllowFilterMiddleware
- type RecvEventDenyFilterMiddleware
- type RecvEventUniqueFilterMiddleware
- type Relay
- type RelayOption
- type ReqFilter
- type ReqFilterEventMatcher
- type ReqFiltersMatcher
- type RouterHandler
- type SendEventUniqueFilterMiddleware
- type ServeMux
- type ServerAuthMsg
- type ServerClosedMsg
- type ServerCountMsg
- type ServerEOSEMsg
- type ServerEventMsg
- type ServerMsg
- type ServerNoticeMsg
- type ServerOKMsg
- type SimpleHandlerBase
- type SimpleMiddlewareBase
- type Tag
Constants ¶
View Source
const ( ServerOKMsgPrefixNoPrefix = "" ServerOKMsgPrefixPoW = "pow: " ServerOKMsgPrefixDuplicate = "duplicate: " ServerOkMsgPrefixBlocked = "blocked: " ServerOkMsgPrefixRateLimited = "rate-limited: " ServerOkMsgPrefixRateInvalid = "invalid: " ServerOkMsgPrefixError = "error: " )
View Source
const ( ServerClosedMsgPrefixNoPrefix = "" ServerClosedMsgPrefixPoW = "pow: " ServerClosedMsgPrefixDuplicate = "duplicate: " ServerClosedMsgPrefixBlocked = "blocked: " ServerClosedMsgPrefixRateLimited = "rate-limited: " ServerClosedMsgPrefixRateInvalid = "invalid: " ServerClosedMsgPrefixError = "error: " )
Variables ¶
View Source
var ErrEventSerialize = errors.New("failed to serialize event")
View Source
var ErrInvalidClientMsg = errors.New("invalid client message")
View Source
var ErrMarshalServerAuthMsg = errors.New("failed to marshal server auth msg")
View Source
var ErrMarshalServerClosedMsg = errors.New("failed to marshal server closed msg")
View Source
var ErrMarshalServerCountMsg = errors.New("failed to marshal server count msg")
View Source
var ErrMarshalServerEOSEMsg = errors.New("failed to marshal server eose msg")
View Source
var ErrMarshalServerEventMsg = errors.New("failed to marshal server event msg")
View Source
var ErrMarshalServerNoticeMsg = errors.New("failed to marshal server notice msg")
View Source
var ErrMarshalServerOKMsg = errors.New("failed to marshal server ok msg")
View Source
var (
ErrRecvClosed = errors.New("recv closed")
)
View Source
var (
ErrRelayStop = errors.New("relay stopped")
)
View Source
var ErrServerAuthMsgNilEvent = errors.New("server auth msg event must be non nil value")
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 {
Challenge string
}
func (*ClientAuthMsg) ClientMsg ¶
func (*ClientAuthMsg) ClientMsg()
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) ClientMsg ¶
func (*ClientCloseMsg) ClientMsg()
func (*ClientCloseMsg) UnmarshalJSON ¶
func (msg *ClientCloseMsg) UnmarshalJSON(b []byte) error
func (*ClientCloseMsg) Valid ¶
func (msg *ClientCloseMsg) Valid() bool
type ClientCountMsg ¶
func (*ClientCountMsg) ClientMsg ¶
func (*ClientCountMsg) ClientMsg()
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) ClientMsg ¶
func (*ClientEventMsg) ClientMsg()
func (*ClientEventMsg) UnmarshalJSON ¶
func (msg *ClientEventMsg) UnmarshalJSON(b []byte) error
func (*ClientEventMsg) Valid ¶
func (msg *ClientEventMsg) Valid() bool
type ClientReqMsg ¶
func (*ClientReqMsg) ClientMsg ¶
func (*ClientReqMsg) ClientMsg()
func (*ClientReqMsg) UnmarshalJSON ¶
func (msg *ClientReqMsg) UnmarshalJSON(b []byte) error
func (*ClientReqMsg) Valid ¶
func (msg *ClientReqMsg) Valid() (ok bool)
type ClientUnknownMsg ¶
type ClientUnknownMsg struct { Label string Msg []interface{} }
func (*ClientUnknownMsg) ClientMsg ¶
func (*ClientUnknownMsg) ClientMsg()
func (*ClientUnknownMsg) UnmarshalJSON ¶
func (msg *ClientUnknownMsg) UnmarshalJSON(b []byte) error
func (*ClientUnknownMsg) Valid ¶
func (msg *ClientUnknownMsg) Valid() bool
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 EventCountMatcher ¶
type EventCountMatcher interface { EventMatcher CountMatch(*Event) bool Done() bool }
type EventCountMatchers ¶
type EventCountMatchers[T EventCountMatcher] []T
func NewReqFiltersEventMatchers ¶
func NewReqFiltersEventMatchers( filters []*ReqFilter, ) EventCountMatchers[*ReqFilterEventMatcher]
func (EventCountMatchers[T]) CountMatch ¶
func (m EventCountMatchers[T]) CountMatch(event *Event) bool
func (EventCountMatchers[T]) Done ¶
func (m EventCountMatchers[T]) Done() bool
func (EventCountMatchers[T]) Match ¶
func (m EventCountMatchers[T]) Match(event *Event) bool
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 EventMatcher ¶
type Handler ¶
type Handler interface {
ServeNostr(ctx context.Context, send chan<- ServerMsg, recv <-chan ClientMsg) error
}
func NewDefaultHandler ¶
func NewDefaultHandler() Handler
func NewMergeHandler ¶
func NewSimpleHandler ¶
func NewSimpleHandler(h SimpleHandlerBase) Handler
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"` Description string `json:"description,omitempty"` Pubkey string `json:"pubkey,omitempty"` Contact string `json:"contact,omitempty"` SupportedNIPs []int `json:"supported_nips,omitempty"` Software string `json:"software,omitempty"` Version string `json:"version,omitempty"` Limitation *NIP11Limitation `json:"limitation,omitempty"` Retention *NIP11Retention `json:"retention,omitempty"` RelayContries []string `json:"relay_countries,omitempty"` LanguageTags []string `json:"language_tags,omitempty"` Tags []string `json:"tags,omitempty"` PostingPolicy string `json:"posting_policy,omitempty"` PaymentsURL string `json:"payments_url,omitempty"` Fees *NIP11Fees `json:"fees,omitempty"` Icon string `json:"icon,omitempty"` }
type NIP11Limitation ¶
type NIP11Limitation struct { MaxMessageLength int `json:"max_message_length,omitempty"` MaxSubscriptions int `json:"max_subscriptions,omitempty"` MaxFilters int `json:"max_filters,omitempty"` MaxLimit int `json:"max_limit,omitempty"` MaxSubIDLength int `json:"max_subid_length,omitempty"` MaxEventTags int `json:"max_event_tags,omitempty"` MaxContentLength int `json:"max_content_length,omitempty"` MinPoWDifficulty int `json:"min_pow_difficulty,omitempty"` AuthRequired bool `json:"auth_required,omitempty"` PaymentRequired bool `json:"payment_required,omitempty"` CreatedAtLowerLimit int64 `json:"created_at_lower_limit,omitempty"` CreatedAtUpperLimit int64 `json:"created_at_upper_limit,omitempty"` }
type NIP11Retention ¶
type NIP11Retention struct { }
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) UnmarshalJSON ¶
type ReqFilterEventMatcher ¶
type ReqFilterEventMatcher struct {
// contains filtered or unexported fields
}
func NewReqFilterMatcher ¶
func NewReqFilterMatcher(filter *ReqFilter) *ReqFilterEventMatcher
func (*ReqFilterEventMatcher) CountMatch ¶
func (m *ReqFilterEventMatcher) CountMatch(event *Event) bool
func (*ReqFilterEventMatcher) Done ¶
func (m *ReqFilterEventMatcher) Done() bool
func (*ReqFilterEventMatcher) Match ¶
func (m *ReqFilterEventMatcher) Match(event *Event) bool
type ReqFiltersMatcher ¶
type ReqFiltersMatcher []*ReqFilterEventMatcher
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 {
Event *Event
}
func NewServerAuthMsg ¶
func NewServerAuthMsg(event *Event) (*ServerAuthMsg, error)
func (*ServerAuthMsg) MarshalJSON ¶
func (msg *ServerAuthMsg) MarshalJSON() ([]byte, error)
func (*ServerAuthMsg) ServerMsg ¶
func (*ServerAuthMsg) ServerMsg()
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) ServerMsg ¶
func (*ServerClosedMsg) ServerMsg()
type ServerCountMsg ¶
func NewServerCountMsg ¶
func NewServerCountMsg(subID string, count uint64, approx *bool) *ServerCountMsg
func (*ServerCountMsg) MarshalJSON ¶
func (msg *ServerCountMsg) MarshalJSON() ([]byte, error)
func (*ServerCountMsg) ServerMsg ¶
func (*ServerCountMsg) ServerMsg()
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) ServerMsg ¶
func (*ServerEOSEMsg) ServerMsg()
type ServerEventMsg ¶
func NewServerEventMsg ¶
func NewServerEventMsg(subID string, event *Event) *ServerEventMsg
func (*ServerEventMsg) MarshalJSON ¶
func (msg *ServerEventMsg) MarshalJSON() ([]byte, error)
func (*ServerEventMsg) ServerMsg ¶
func (*ServerEventMsg) ServerMsg()
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) ServerMsg ¶
func (*ServerNoticeMsg) ServerMsg()
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) ServerMsg ¶
func (*ServerOKMsg) ServerMsg()
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.