Documentation
¶
Index ¶
- Variables
- func GetAuthed(ctx context.Context) (nostr.PubKey, bool)
- func GetIP(ctx context.Context) string
- func GetIPFromRequest(r *http.Request) string
- func GetSubscriptionID(ctx context.Context) string
- func IsInternalCall(ctx context.Context) bool
- func IsNegentropySession(ctx context.Context) bool
- func RequestAuth(ctx context.Context)
- func SendNotice(ctx context.Context, msg string)
- func SetNegentropy(ctx context.Context) context.Context
- type NegentropySession
- type Relay
- func (rl *Relay) AddEvent(ctx context.Context, evt nostr.Event) (skipBroadcast bool, writeError error)
- func (rl *Relay) BroadcastEvent(evt nostr.Event) int
- func (rl *Relay) GetListeningFilters() []nostr.Filter
- func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) Router() *http.ServeMux
- func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rl *Relay) SetRouter(mux *http.ServeMux)
- func (rl *Relay) Shutdown(ctx context.Context)
- func (rl *Relay) Start(host string, port int, started ...chan bool) error
- func (rl *Relay) UseEventstore(store eventstore.Store, maxQueryLimit int)
- type RelayManagementAPI
- type Route
- type Router
- type WebSocket
Constants ¶
This section is empty.
Variables ¶
var ErrSubscriptionClosedByClient = errors.New("subscription closed by client")
Functions ¶
func GetIPFromRequest ¶
func GetSubscriptionID ¶
func IsInternalCall ¶
IsInternalCall returns true when a call to QueryEvents, for example, is being made because of a deletion or expiration request.
func IsNegentropySession ¶
func RequestAuth ¶
func SendNotice ¶
Types ¶
type NegentropySession ¶
type NegentropySession struct {
// contains filtered or unexported fields
}
type Relay ¶
type Relay struct { // setting this variable overwrites the hackish workaround we do to try to figure out our own base URL ServiceURL string // hooks that will be called at various times OnEvent func(ctx context.Context, event nostr.Event) (reject bool, msg string) StoreEvent func(ctx context.Context, event nostr.Event) error ReplaceEvent func(ctx context.Context, event nostr.Event) error DeleteEvent func(ctx context.Context, id nostr.ID) error OnEventSaved func(ctx context.Context, event nostr.Event) OnEphemeralEvent func(ctx context.Context, event nostr.Event) OnRequest func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) OnCount func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) QueryStored func(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] Count func(ctx context.Context, filter nostr.Filter) (uint32, error) CountHLL func(ctx context.Context, filter nostr.Filter, offset int) (uint32, *hyperloglog.HyperLogLog, error) RejectConnection func(r *http.Request) bool OnConnect func(ctx context.Context) OnDisconnect func(ctx context.Context) OverwriteRelayInformation func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument PreventBroadcast func(ws *WebSocket, event nostr.Event) bool // setting up handlers here will enable these methods ManagementAPI RelayManagementAPI // editing info will affect the NIP-11 responses Info *nip11.RelayInformationDocument // Default logger, as set by NewServer, is a stdlib logger prefixed with "[khatru-relay] ", // outputting to stderr. Log *log.Logger // set this to true to support negentropy Negentropy bool // in case you call Server.Start Addr string // websocket options WriteWait time.Duration // Time allowed to write a message to the peer. PongWait time.Duration // Time allowed to read the next pong message from the peer. PingPeriod time.Duration // Send pings to peer with this period. Must be less than pongWait. MaxMessageSize int64 // Maximum message size allowed from peer. // contains filtered or unexported fields }
func (*Relay) AddEvent ¶
func (rl *Relay) AddEvent(ctx context.Context, evt nostr.Event) (skipBroadcast bool, writeError error)
AddEvent sends an event through then normal add pipeline, as if it was received from a websocket.
func (*Relay) BroadcastEvent ¶
BroadcastEvent emits an event to all listeners whose filters' match, skipping all filters and actions it also doesn't attempt to store the event or trigger any reactions or callbacks
func (*Relay) GetListeningFilters ¶
func (*Relay) HandleNIP11 ¶
func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request)
func (*Relay) HandleNIP86 ¶
func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request)
func (*Relay) HandleWebsocket ¶
func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request)
func (*Relay) ServeHTTP ¶
func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface.
func (*Relay) UseEventstore ¶
func (rl *Relay) UseEventstore(store eventstore.Store, maxQueryLimit int)
UseEventstore hooks up an eventstore.Store into the relay in the default way. It should be used in 85% of the cases, when you don't want to do any complicated scheme with your event storage.
maxQueryLimit is the default max limit to be enforced when querying events, to prevent users for downloading way too much, setting it to something like 500 or 1000 should be ok in most cases.
type RelayManagementAPI ¶
type RelayManagementAPI struct { OnAPICall func(ctx context.Context, mp nip86.MethodParams) (reject bool, msg string) BanPubKey func(ctx context.Context, pubkey nostr.PubKey, reason string) error ListBannedPubKeys func(ctx context.Context) ([]nip86.PubKeyReason, error) AllowPubKey func(ctx context.Context, pubkey nostr.PubKey, reason string) error ListAllowedPubKeys func(ctx context.Context) ([]nip86.PubKeyReason, error) ListEventsNeedingModeration func(ctx context.Context) ([]nip86.IDReason, error) AllowEvent func(ctx context.Context, id nostr.ID, reason string) error BanEvent func(ctx context.Context, id nostr.ID, reason string) error ListBannedEvents func(ctx context.Context) ([]nip86.IDReason, error) ListAllowedEvents func(ctx context.Context) ([]nip86.IDReason, error) ChangeRelayName func(ctx context.Context, name string) error ChangeRelayDescription func(ctx context.Context, desc string) error ChangeRelayIcon func(ctx context.Context, icon string) error AllowKind func(ctx context.Context, kind int) error DisallowKind func(ctx context.Context, kind int) error ListAllowedKinds func(ctx context.Context) ([]int, error) ListDisAllowedKinds func(ctx context.Context) ([]int, error) BlockIP func(ctx context.Context, ip net.IP, reason string) error UnblockIP func(ctx context.Context, ip net.IP, reason string) error ListBlockedIPs func(ctx context.Context) ([]nip86.IPReason, error) Stats func(ctx context.Context) (nip86.Response, error) GrantAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error RevokeAdmin func(ctx context.Context, pubkey nostr.PubKey, methods []string) error Generic func(ctx context.Context, request nip86.Request) (nip86.Response, error) }
type WebSocket ¶
type WebSocket struct { // original request Request *http.Request // this Context will be canceled whenever the connection is closed from the client side or server-side. Context context.Context // nip42 Challenge string AuthedPublicKey nostr.PubKey Authed chan struct{} // contains filtered or unexported fields }