Documentation
¶
Index ¶
- Constants
- Variables
- func GetReactAppFS() http.FileSystem
- func GetRemoteFromReq(r *http.Request) (rr string)
- func LogProxyInfo(r *http.Request, prefix string)
- func Run(ctx context.Context, cfg *config.C, db *database.D) (quit chan struct{})
- func ServeEmbeddedWeb(w http.ResponseWriter, r *http.Request)
- type Listener
- func (l *Listener) Ctx() context.Context
- func (l *Listener) GetSerialsFromFilter(f *filter.F) (sers types.Uint40s, err error)
- func (l *Listener) HandleAuth(b []byte) (err error)
- func (l *Listener) HandleClose(req []byte) (err error)
- func (l *Listener) HandleCount(msg []byte) (err error)
- func (l *Listener) HandleDelete(env *eventenvelope.Submission) (err error)
- func (l *Listener) HandleEvent(msg []byte) (err error)
- func (l *Listener) HandleMessage(msg []byte, remote string)
- func (l *Listener) HandleReq(msg []byte) (err error)
- func (l *Listener) Write(p []byte) (n int, err error)
- type Map
- type OK
- type OKs
- type P
- type PaymentProcessor
- type Server
- func (s *Server) DashboardURL(req *http.Request) (url string)
- func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request)
- func (s *Server) Pinger(ctx context.Context, conn *websocket.Conn, ticker *time.Ticker, ...)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) ServiceURL(req *http.Request) (url string)
- func (s *Server) UserInterface()
- func (s *Server) WebSocketURL(req *http.Request) (url string)
- type SprocketManager
- func (sm *SprocketManager) DeleteSprocketVersion(filename string) error
- func (sm *SprocketManager) GetSprocketStatus() map[string]interface{}
- func (sm *SprocketManager) GetSprocketVersions() ([]map[string]interface{}, error)
- func (sm *SprocketManager) IsEnabled() bool
- func (sm *SprocketManager) IsRunning() bool
- func (sm *SprocketManager) ProcessEvent(evt *event.E) (*SprocketResponse, error)
- func (sm *SprocketManager) RestartSprocket() error
- func (sm *SprocketManager) Shutdown()
- func (sm *SprocketManager) StartSprocket() error
- func (sm *SprocketManager) StopSprocket() error
- func (sm *SprocketManager) UpdateSprocket(scriptContent string) error
- type SprocketResponse
- type Subscription
- type W
Constants ¶
const ( DefaultWriteWait = 10 * time.Second DefaultPongWait = 60 * time.Second DefaultPingWait = DefaultPongWait / 2 DefaultWriteTimeout = 3 * time.Second DefaultMaxMessageSize = 100 * units.Mb // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. CloseMessage = 8 // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PingMessage = 9 // PongMessage denotes a pong control message. The optional message payload // is UTF-8 encoded text. PongMessage = 10 )
const Type = "socketapi"
Variables ¶
var Ok = OKs{ Ok: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), true, []byte{}, ).Write(l) }, AuthRequired: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.AuthRequired.F(format, params...), ).Write(l) }, PoW: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.PoW.F(format, params...), ).Write(l) }, Duplicate: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Duplicate.F(format, params...), ).Write(l) }, Blocked: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Blocked.F(format, params...), ).Write(l) }, RateLimited: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.RateLimited.F(format, params...), ).Write(l) }, Invalid: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Invalid.F(format, params...), ).Write(l) }, Error: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Error.F(format, params...), ).Write(l) }, Unsupported: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Unsupported.F(format, params...), ).Write(l) }, Restricted: func( l *Listener, env eventenvelope.I, format string, params ...any, ) (err error) { return okenvelope.NewFrom( env.Id(), false, reason.Restricted.F(format, params...), ).Write(l) }, }
Ok provides a collection of handler functions for managing different types of operational outcomes, each corresponding to specific error or status conditions such as authentication requirements, rate limiting, and invalid inputs.
Functions ¶
func GetReactAppFS ¶ added in v0.6.0
func GetReactAppFS() http.FileSystem
GetReactAppFS returns a http.FileSystem from the embedded React app
func GetRemoteFromReq ¶
GetRemoteFromReq retrieves the originating IP address of the client from an HTTP request, considering standard and non-standard proxy headers.
Parameters ¶
- r: The HTTP request object containing details of the client and routing information.
Return Values ¶
- rr: A string value representing the IP address of the originating remote client.
Expected behaviour ¶
The function first checks for the standardized "Forwarded" header (RFC 7239) to identify the original client IP. If that isn't available, it falls back to the "X-Forwarded-For" header. If both headers are absent, it defaults to using the request's RemoteAddr.
For the "Forwarded" header, it extracts the client IP from the "for" parameter. For the "X-Forwarded-For" header, if it contains one IP, it returns that. If it contains two IPs, it returns the second.
func LogProxyInfo ¶ added in v0.9.3
LogProxyInfo logs comprehensive proxy information for debugging
func ServeEmbeddedWeb ¶ added in v0.11.0
func ServeEmbeddedWeb(w http.ResponseWriter, r *http.Request)
ServeEmbeddedWeb serves the embedded web application
Types ¶
type Listener ¶
type Listener struct {
*Server
// contains filtered or unexported fields
}
func (*Listener) Ctx ¶ added in v0.4.0
Ctx returns the listener's context, but creates a new context for each operation to prevent cancellation from affecting subsequent operations
func (*Listener) GetSerialsFromFilter ¶
func (*Listener) HandleAuth ¶
func (*Listener) HandleClose ¶
HandleClose processes a CLOSE envelope by unmarshalling the request, validates the presence of an <id> field, and signals cancellation for the associated listener through the server's publisher mechanism.
func (*Listener) HandleCount ¶ added in v0.10.0
HandleCount processes a COUNT envelope by parsing the request, verifying permissions, invoking the database CountEvents for each provided filter, and responding with a COUNT response containing the aggregate count.
func (*Listener) HandleDelete ¶
func (l *Listener) HandleDelete(env *eventenvelope.Submission) (err error)
func (*Listener) HandleEvent ¶
func (*Listener) HandleMessage ¶
type Map ¶
type Map map[*websocket.Conn]map[string]Subscription
Map is a map of filters associated with a collection of ws.Listener connections.
type OK ¶
OK represents a function that processes events or operations, using provided parameters to generate formatted messages and return errors if any issues occur during processing.
type OKs ¶
type OKs struct {
Ok OK
AuthRequired OK
PoW OK
Duplicate OK
Blocked OK
RateLimited OK
Invalid OK
Error OK
Unsupported OK
Restricted OK
}
OKs provides a collection of handler functions for managing different types of operational outcomes, each corresponding to specific error or status conditions such as authentication requirements, rate limiting, and invalid inputs.
type P ¶
type P struct {
// Mx is the mutex for the Map.
Mx sync.RWMutex
// Map is the map of subscribers and subscriptions from the websocket api.
Map
// contains filtered or unexported fields
}
P is a structure that manages subscriptions and associated filters for websocket listeners. It uses a mutex to synchronize access to a map storing subscriber connections and their filter configurations.
func NewPublisher ¶
func (*P) Deliver ¶
Deliver processes and distributes an event to all matching subscribers based on their filter configurations.
Parameters ¶
- ev (*event.E): The event to be delivered to subscribed clients.
Expected behaviour ¶
Delivers the event to all subscribers whose filters match the event. It applies authentication checks if required by the server and skips delivery for unauthenticated users when events are privileged.
func (*P) Receive ¶
Receive handles incoming messages to manage websocket listener subscriptions and associated filters.
Parameters ¶
- msg (publisher.Message): The incoming message to process; expected to be of type *W to trigger subscription management actions.
Expected behaviour ¶
- Checks if the message is of type *W.
- If Cancel is true, removes a subscriber by ID or the entire listener.
- Otherwise, adds the subscription to the map under a mutex lock.
- Logs actions related to subscription creation or removal.
type PaymentProcessor ¶ added in v0.8.0
type PaymentProcessor struct {
// contains filtered or unexported fields
}
PaymentProcessor handles NWC payment notifications and updates subscriptions
func NewPaymentProcessor ¶ added in v0.8.0
func NewPaymentProcessor( ctx context.Context, cfg *config.C, db *database.D, ) (pp *PaymentProcessor, err error)
NewPaymentProcessor creates a new payment processor
func (*PaymentProcessor) CreateWelcomeNote ¶ added in v0.8.0
func (pp *PaymentProcessor) CreateWelcomeNote(userPubkey []byte) error
CreateWelcomeNote creates a welcome note for first-time users with private tag for authorization
func (*PaymentProcessor) SetDashboardURL ¶ added in v0.8.2
func (pp *PaymentProcessor) SetDashboardURL(url string)
SetDashboardURL sets the dynamic dashboard URL based on HTTP request
func (*PaymentProcessor) Start ¶ added in v0.8.0
func (pp *PaymentProcessor) Start() error
Start begins listening for payment notifications
func (*PaymentProcessor) Stop ¶ added in v0.8.0
func (pp *PaymentProcessor) Stop()
Stop gracefully stops the payment processor
func (*PaymentProcessor) UpdateRelayProfile ¶ added in v0.8.4
func (pp *PaymentProcessor) UpdateRelayProfile() error
UpdateRelayProfile creates or updates the relay's kind 0 profile with subscription information
type Server ¶
type Server struct {
Config *config.C
Ctx context.Context
Admins [][]byte
*database.D
// contains filtered or unexported fields
}
func (*Server) DashboardURL ¶ added in v0.8.2
func (*Server) HandleRelayInfo ¶
func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request)
HandleRelayInfo generates and returns a relay information document in JSON format based on the server's configuration and supported NIPs.
Parameters ¶
w: HTTP response writer used to send the generated document.
r: HTTP request object containing incoming client request data.
Expected Behaviour ¶
The function constructs a relay information document using either the Informer interface implementation or predefined server configuration. It returns this document as a JSON response to the client.
func (*Server) HandleWebsocket ¶
func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request)
func (*Server) UserInterface ¶ added in v0.6.0
func (s *Server) UserInterface()
UserInterface sets up a basic Nostr NDK interface that allows users to log into the relay user interface
type SprocketManager ¶ added in v0.12.0
type SprocketManager struct {
// contains filtered or unexported fields
}
SprocketManager handles sprocket script execution and management
func NewSprocketManager ¶ added in v0.12.0
func NewSprocketManager(ctx context.Context, appName string, enabled bool) *SprocketManager
NewSprocketManager creates a new sprocket manager
func (*SprocketManager) DeleteSprocketVersion ¶ added in v0.12.0
func (sm *SprocketManager) DeleteSprocketVersion(filename string) error
DeleteSprocketVersion deletes a specific sprocket version
func (*SprocketManager) GetSprocketStatus ¶ added in v0.12.0
func (sm *SprocketManager) GetSprocketStatus() map[string]interface{}
GetSprocketStatus returns the current status of the sprocket
func (*SprocketManager) GetSprocketVersions ¶ added in v0.12.0
func (sm *SprocketManager) GetSprocketVersions() ([]map[string]interface{}, error)
GetSprocketVersions returns a list of all sprocket script versions
func (*SprocketManager) IsEnabled ¶ added in v0.12.0
func (sm *SprocketManager) IsEnabled() bool
IsEnabled returns whether sprocket is enabled
func (*SprocketManager) IsRunning ¶ added in v0.12.0
func (sm *SprocketManager) IsRunning() bool
IsRunning returns whether sprocket is currently running
func (*SprocketManager) ProcessEvent ¶ added in v0.12.0
func (sm *SprocketManager) ProcessEvent(evt *event.E) (*SprocketResponse, error)
ProcessEvent sends an event to the sprocket script and waits for a response
func (*SprocketManager) RestartSprocket ¶ added in v0.12.0
func (sm *SprocketManager) RestartSprocket() error
RestartSprocket stops and starts the sprocket script
func (*SprocketManager) Shutdown ¶ added in v0.12.0
func (sm *SprocketManager) Shutdown()
Shutdown gracefully shuts down the sprocket manager
func (*SprocketManager) StartSprocket ¶ added in v0.12.0
func (sm *SprocketManager) StartSprocket() error
StartSprocket starts the sprocket script
func (*SprocketManager) StopSprocket ¶ added in v0.12.0
func (sm *SprocketManager) StopSprocket() error
StopSprocket stops the sprocket script gracefully, with SIGKILL fallback
func (*SprocketManager) UpdateSprocket ¶ added in v0.12.0
func (sm *SprocketManager) UpdateSprocket(scriptContent string) error
UpdateSprocket updates the sprocket script and restarts it with zero downtime
type SprocketResponse ¶ added in v0.12.0
type SprocketResponse struct {
ID string `json:"id"`
Action string `json:"action"` // accept, reject, or shadowReject
Msg string `json:"msg"` // NIP-20 response message (only used for reject)
}
SprocketResponse represents a response from the sprocket script
type Subscription ¶
type W ¶
type W struct {
*websocket.Conn
// If Cancel is true, this is a close command.
Cancel bool
// Id is the subscription Id. If Cancel is true, cancel the named
// subscription, otherwise, cancel the publisher for the socket.
Id string
// The Receiver holds the event channel for receiving notifications or data
// relevant to this WebSocket connection.
Receiver event.C
// Filters holds a collection of filters used to match or process events
// associated with this WebSocket connection. It is used to determine which
// notifications or data should be received by the subscriber.
Filters *filter.S
// AuthedPubkey is the authenticated pubkey associated with the listener (if any).
AuthedPubkey []byte
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package config provides a go-simpler.org/env configuration table and helpers for working with the list of key/value lists stored in .env files.
|
Package config provides a go-simpler.org/env configuration table and helpers for working with the list of key/value lists stored in .env files. |