relay

package
v1.0.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	WebsocketContextKey = iota
	SubscriptionIDContextKey
)

Variables

This section is empty.

Functions

func GetAuthed

func GetAuthed(c context.T) string

func GetIP

func GetIP(c context.T) string

func GetListeningFilters

func GetListeningFilters() filters2.T

func GetOpenSubscriptions

func GetOpenSubscriptions(c context.T) (res []*filter.T)

func GetSubscriptionID

func GetSubscriptionID(c context.T) string

func RequestAuth

func RequestAuth(c context.T)

Types

type Listener

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

type Relay

type Relay struct {
	ServiceURL string

	RejectEvent               []func(c context.T, ev *event.T) (reject bool, msg string)
	RejectFilter              []func(c context.T, f *filter.T) (reject bool, msg string)
	RejectCountFilter         []func(c context.T, f *filter.T) (reject bool, msg string)
	OverwriteDeletionOutcome  []func(c context.T, target *event.T, deletion *event.T) (acceptDeletion bool, msg string)
	OverwriteResponseEvent    []func(c context.T, ev *event.T)
	OverwriteFilter           []func(c context.T, f *filter.T)
	OverwriteCountFilter      []func(c context.T, f *filter.T)
	OverwriteRelayInformation []func(c context.T, r *http.Request, info *relayinfo.T) *relayinfo.T
	StoreEvent                []func(c context.T, ev *event.T) error
	DeleteEvent               []func(c context.T, ev *event.T) error
	QueryEvents               []func(c context.T, f *filter.T) (chan *event.T, error)
	CountEvents               []func(c context.T, f *filter.T) (int64, error)
	OnAuth                    []func(c context.T, pubkey string)
	OnConnect                 []func(c context.T)
	OnDisconnect              []func(c context.T)
	OnEventSaved              []func(c context.T, ev *event.T)

	// editing info will affect
	Info *relayinfo.T

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

	// 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(c context.T, evt *event.T) (e 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(c context.T)

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) (e 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(c context.T) *WebSocket

func (*WebSocket) WriteJSON

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

func (*WebSocket) WriteMessage

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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