realy

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Unlicense Imports: 48 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 added in v1.0.5

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

func GetListeningFilters added in v1.0.5

func GetListeningFilters() *filters.T

func NewServer

func NewServer(c Ctx, cancel context.F, rl relay.I, dbPath S, 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 added in v1.0.5

type B = []byte

func AddEvent added in v1.0.5

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

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

type Ctx added in v1.0.5

type Ctx = context.T

type E added in v1.0.5

type E = error

type Listener added in v1.0.5

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

type N added in v1.0.5

type N = int

type Notice added in v1.0.5

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

type Option added in v1.0.5

type Option func(*Options)

func WithPerConnectionLimiter added in v1.0.5

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

func WithSkipEventFunc added in v1.0.5

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

type Options added in v1.0.5

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

func DefaultOptions added in v1.0.5

func DefaultOptions() *Options

type S added in v1.0.5

type S = string

func GetAuthStatus added in v1.0.5

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 added in v1.0.5

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

func (*Server) HandleWebsocket added in v1.0.5

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