realy

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Unlicense Imports: 50 Imported by: 0

README

Nostr Relay Framework -- use it to implement your own custom relay.

There is an example/reference implementation at basic.

GoDoc

Documentation

Index

Constants

View Source
const AUTH_CONTEXT_KEY = iota
View Source
const ChallengeHRP = "nchal"
View Source
const ChallengeLength = 16

Variables

This section is empty.

Functions

func BroadcastEvent

func BroadcastEvent(authRequired bool, ev *event.T)

func GetListeningFilters

func GetListeningFilters() *filters.T

func NewServer

func NewServer(c Ctx, cancel context.F, rl relay.I, dbPath S, maxLimit N,
	opts ...Option) (*Server, E)

NewServer initializes the realy and its storage using their respective Init methods, returning any non-nil errors, and returns a Server ready to listen for HTTP requests.

Types

type B

type B = []byte

func AddEvent

func AddEvent(c Ctx, rl relay.I, ev *event.T, hr *http.Request, origin S,
	authedPubkey B) (accepted bool,
	message B)

AddEvent has a business rule to add an event to the relayer

type Ctx

type Ctx = context.T

type E

type E = error

type Listener

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

type N

type N = int

type Notice

type Notice struct {
	Kind    S `json:"kind"`
	Message S `json:"message"`
}

type Option

type Option func(*Options)

func WithPerConnectionLimiter

func WithPerConnectionLimiter(rps rate.Limit, burst N) Option

func WithSkipEventFunc

func WithSkipEventFunc(skipEventFunc func(*event.T) bool) Option

type Options

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

func DefaultOptions

func DefaultOptions() *Options

type S

type S = string

func GetAuthStatus

func GetAuthStatus(ctx Ctx) (pubkey S, ok bool)

type Server

type Server struct {
	Ctx
	Cancel context.F

	Addr, AdminAddr S
	// contains filtered or unexported fields
}

Server is a base for package users to implement nostr relays. It can serve HTTP requests and websockets, passing control over to a relay implementation.

To implement a relay, it is enough to satisfy [Relay] interface. Other interfaces are [Informationer], [CustomWebSocketHandler], [ShutdownAware] and AdvancedXxx types. See their respective doc comments.

The basic usage is to call Start or StartConf, which starts serving immediately. For a more fine-grained control, use NewServer.

func (*Server) HandleAdmin added in v1.0.16

func (s *Server) HandleAdmin(w http.ResponseWriter, r *http.Request)

func (*Server) HandleNIP11

func (s *Server) HandleNIP11(w http.ResponseWriter, r *http.Request)

func (*Server) HandleWebsocket

func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request)

func (*Server) Router

func (s *Server) Router() *http.ServeMux

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface.

func (*Server) Shutdown

func (s *Server) Shutdown()

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

If the realy is ShutdownAware, Shutdown calls its OnShutdown, passing the context as is. Note that the HTTP server make some time to shutdown and so the context deadline, if any, may have been shortened by the time OnShutdown is called.

func (*Server) Start

func (s *Server) Start(host S, port int, adminHost S, adminPort int, started ...chan bool) E

Jump to

Keyboard shortcuts

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