realy

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Unlicense Imports: 46 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(evt *event.T)

func GetListeningFilters

func GetListeningFilters() *filters.T

func NewServer

func NewServer(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

type B = []byte

func AddEvent

func AddEvent(c Ctx, rl relay.I, evt *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

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 {
	Addr 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. See basic/main.go, whitelisted/main.go, expensive/main.go and rss-bridge/main.go for example implementations.

The following resource is a good starting point for details on what nostr protocol is and how it works: https://github.com/nostr-protocol/nostr

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(ctx context.Context)

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, started ...chan bool) E

Jump to

Keyboard shortcuts

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