relay

package
v0.0.0-...-c164061 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admission

type Admission struct {
	Kinds  []int    `json:"kinds,omitempty"`  // Kinds specifies the types of events allowed.
	Amount int      `json:"amount,omitempty"` // Amount indicates the payment required for accessing paid relays.
	Unit   []string `json:"unit,omitempty"`   // Unit denotes the currency unit used for payment.
}

Admission represents the admission requirements for accessing a Nostr relay.

type Fees

type Fees struct {
	Admission *Admission `json:"admission,omitempty"` // Admission represents the admission fee for an operation, if applicable.
}

Fees is a struct that contains information about the fees associated with an operation.

type InformationDocument

type InformationDocument struct {
	Name           string       `json:"name,omitempty"`
	Description    string       `json:"description,omitempty"`
	PubKey         string       `json:"pub_key,omitempty"`
	Contact        string       `json:"contact,omitempty"`
	SupportedNIPs  string       `json:"supported_nips,omitempty"`
	Software       string       `json:"software,omitempty"`
	Version        string       `json:"version,omitempty"`
	Limitations    *Limitations `json:"limitations,omitempty"`
	LanguageTags   []string     `json:"language_tags,omitempty"`
	RelayCountries []string     `json:"relay_countries,omitempty"`
	Tags           []tag.Tag    `json:"tags,omitempty"`
	PostingPolicy  string       `json:"posting_policy,omitempty"`
	PaymentsURL    string       `json:"payments_url,omitempty"`
	Fees           *Fees        `json:"fees,omitempty"`
}

InformationDocument contains information about a Nostr relay.

type InternetIdentifier

type InternetIdentifier struct {
	Names  []string `json:"names,omitempty"`
	Relays []string `json:"relays,omitempty"`
}

type Limitations

type Limitations struct {
	AuthRequired     bool `json:"auth_required,omitempty"`      // Indicates if authentication is required.
	MaxContentLength int  `json:"max_content_length,omitempty"` // Maximum content length.
	MaxEventTags     int  `json:"max_event_tags,omitempty"`     // Maximum number of event tags.
	MaxFilters       int  `json:"max_filters,omitempty"`        // Maximum number of filters.
	MaxLimit         int  `json:"max_limit,omitempty"`          // Maximum limit for query results.
	MaxMessageLength int  `json:"max_message_length,omitempty"` // Maximum length of a message.
	MaxSubIDLength   int  `json:"max_subid_length,omitempty"`   // Maximum length of a subscription ID.
	MaxSubscriptions int  `json:"max_subscriptions,omitempty"`  // Maximum number of subscriptions.
	MinPowDifficulty int  `json:"min_pow_difficulty,omitempty"` // Minimum proof-of-work difficulty.
	MinPrefix        int  `json:"min_prefix,omitempty"`         // Minimum prefix length.
	PaymentRequired  bool `json:"payment_required,omitempty"`   // Indicates if payment is required.
}

Limitations represents various limits and constraints imposed by a Nostr server.

type Options

type Options struct {
	Name          string
	Description   string
	PubKey        string
	Contact       string
	Origin        string
	SupportedNIPs []int
	Software      string
	Version       string
	Limitations   *Limitations
}

Options holds the configuration options for a Relay instance. This includes the name, description, public key, contact, origin, supported NIPs, software, version, and limitations for the relay instance.

type Relay

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

Relay represents a websocket relay server. It holds options, a map of connections, handlers for errors and messages, mutex for concurrent access, and a ServeMux for HTTP request routing.

func New

func New(opt *Options) *Relay

New creates a new Relay instance with the provided Options. If no options are provided, it will create default options. If the Origin in options is not set, it sets it to "*". This function also initializes a map for connections, sets error and message handlers to default functions, and sets two HTTP handlers for ".well-known/nostr.json" and "/" routes.

func (*Relay) HandleErrorFunc

func (rl *Relay) HandleErrorFunc(fn func(error))

HandleErrorFunc registers a function that will handle errors. This function is called when an error occurs.

func (*Relay) HandleInformationDocumentFunc

func (rl *Relay) HandleInformationDocumentFunc(fn func() (*InformationDocument, error))

HandleInformationDocumentFunc registers a function that will handle the generation of an information document. This function is expected to return an InformationDocument instance or an error.

func (*Relay) HandleInternetIdentifierFunc

func (rl *Relay) HandleInternetIdentifierFunc(fn func(string) (*InternetIdentifier, error))

HandleInternetIdentifierFunc registers a function that will handle the internet identifier. This function is expected to return an InternetIdentifier instance or an error given a string input.

func (*Relay) HandleMessageFunc

func (rl *Relay) HandleMessageFunc(fn func(message.Message))

HandleMessageFunc registers a function that will handle messages. This function is called with a Message as a parameter whenever a message is received.

func (*Relay) SendMessage

func (rl *Relay) SendMessage(ctx context.Context, msg message.Message)

SendMessage sends the provided Message to all connected clients. If an error occurs while marshalling the message, it calls the registered error handler function.

func (*Relay) ServeHTTP

func (rl *Relay) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the given HTTP request using the internal ServeMux. It allows the Relay instance to be used as an HTTP handler.

Jump to

Keyboard shortcuts

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