khatru

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Unlicense Imports: 19 Imported by: 38

README

khatru

Documentation

Index

Constants

View Source
const (
	AUTH_CONTEXT_KEY = iota
	WS_KEY           = iota
)

Variables

View Source
var ErrDupEvent = fmt.Errorf("duplicate: event already exists")

Functions

func GetAuthed

func GetAuthed(ctx context.Context) string

func GetListeningFilters

func GetListeningFilters() nostr.Filters

Types

type Listener

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

type Relay

type Relay struct {
	Name        string
	Description string
	PubKey      string
	Contact     string
	ServiceURL  string // required for nip-42

	RejectEvent              []func(ctx context.Context, event *nostr.Event) (reject bool, msg string)
	RejectFilter             []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
	RejectCountFilter        []func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
	OverwriteDeletionOutcome []func(ctx context.Context, target *nostr.Event, deletion *nostr.Event) (acceptDeletion bool, msg string)
	StoreEvent               []func(ctx context.Context, event *nostr.Event) error
	DeleteEvent              []func(ctx context.Context, event *nostr.Event) error
	QueryEvents              []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error)
	CountEvents              []func(ctx context.Context, filter nostr.Filter) (int64, error)
	EditInformation          []func(ctx context.Context, info *nip11.RelayInformationDocument)
	OnAuth                   []func(ctx context.Context, pubkey string)
	OnConnect                []func(ctx context.Context)
	OnEventSaved             []func(ctx context.Context, event *nostr.Event)

	// Default logger, as set by NewServer, is a stdlib logger prefixed with "[khatru-relay] ",
	// outputting to stderr.
	Log *log.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 NewRelay

func NewRelay() *Relay

func (*Relay) AddEvent

func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.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) RequestAuth

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

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 {

	// nip42
	Challenge      string
	Authed         string
	WaitingForAuth 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
examples
basic-badgern command
basic-lmdbn command
basic-postgres command
basic-sqlite3 command
exclusive command

Jump to

Keyboard shortcuts

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