relay

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: CC0-1.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebsocketContextKey = iota
	SubscriptionIDContextKey
)

Variables

This section is empty.

Functions

func GetAuthed

func GetAuthed(ctx context.Context) string

func GetIP

func GetIP(ctx context.Context) string

func GetListeningFilters

func GetListeningFilters() nip1.Filters

func GetOpenSubscriptions

func GetOpenSubscriptions(ctx context.Context) (res []*nip1.Filter)

func GetSubscriptionID

func GetSubscriptionID(ctx context.Context) string

func RequestAuth

func RequestAuth(ctx context.Context)

Types

type Listener

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

type Relay

type Relay struct {
	ServiceURL string

	RejectEvent               []func(ctx context.Context, event *nip1.Event) (reject bool, msg string)
	RejectFilter              []func(ctx context.Context, filter *nip1.Filter) (reject bool, msg string)
	RejectCountFilter         []func(ctx context.Context, filter *nip1.Filter) (reject bool, msg string)
	OverwriteDeletionOutcome  []func(ctx context.Context, target *nip1.Event, deletion *nip1.Event) (acceptDeletion bool, msg string)
	OverwriteResponseEvent    []func(ctx context.Context, event *nip1.Event)
	OverwriteFilter           []func(ctx context.Context, filter *nip1.Filter)
	OverwriteCountFilter      []func(ctx context.Context, filter *nip1.Filter)
	OverwriteRelayInformation []func(ctx context.Context, r *http.Request, info *nip11.RelayInfo) *nip11.RelayInfo
	StoreEvent                []func(ctx context.Context, event *nip1.Event) error
	DeleteEvent               []func(ctx context.Context, event *nip1.Event) error
	QueryEvents               []func(ctx context.Context, filter *nip1.Filter) (chan *nip1.Event, error)
	CountEvents               []func(ctx context.Context, filter *nip1.Filter) (int64, error)
	OnAuth                    []func(ctx context.Context, pubkey string)
	OnConnect                 []func(ctx context.Context)
	OnDisconnect              []func(ctx context.Context)
	OnEventSaved              []func(ctx context.Context, event *nip1.Event)

	// editing info will affect
	Info *nip11.RelayInfo

	// Default logger, as set by NewServer, is a stdlib logger prefixed with "[khatru-relay] ",
	// outputting to stderr.
	Log *log2.Logger

	// 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 New

func New() *Relay

func (*Relay) AddEvent

func (rl *Relay) AddEvent(ctx context.Context, evt *nip1.Event) error

func (*Relay) HandleNIP11

func (rl *Relay) HandleNIP11(w http.ResponseWriter, r *http.Request)

func (*Relay) HandleWebsocket

func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request)

func (*Relay) Router

func (rl *Relay) Router() *http.ServeMux

func (*Relay) ServeHTTP

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

ServeHTTP implements http.Handler interface.

func (*Relay) Shutdown

func (rl *Relay) Shutdown(ctx context.Context)

Shutdown sends a websocket close control message to all connected clients.

func (*Relay) Start

func (rl *Relay) Start(host string, port int, started ...chan bool) error

Start creates an http server and starts listening on given host and port.

type WebSocket

type WebSocket struct {

	// original request
	Request *http.Request

	// nip42
	Challenge       string
	AuthedPublicKey string
	Authed          chan struct{}
	// contains filtered or unexported fields
}

func GetConnection

func GetConnection(ctx context.Context) *WebSocket

func (*WebSocket) WriteJSON

func (ws *WebSocket) WriteJSON(any any) error

func (*WebSocket) WriteMessage

func (ws *WebSocket) WriteMessage(t int, b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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