pushd

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pushd is a small self-hostable Web Push relay. It speaks the two halves of a push service:

  • towards application servers, the HTTP Web Push protocol (RFC 8030) with VAPID (RFC 8292): POST /wpush/v2/<token> with TTL, Urgency and Topic headers and an aes128gcm body (RFC 8291);
  • towards browsers, the autopush WebSocket protocol (hello, register, unregister, notification, ack, ping).

The relay never sees plaintext: bodies are opaque encrypted records that it stores (while the browser is offline, up to the message's TTL) and forwards. Endpoints are unguessable and unforgeable: an endpoint token is a random endpoint id followed by an HMAC of it under the relay's secret. See docs/push.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PublicURL is the externally visible base URL ("https://push.example.com"), used to build endpoints and as the
	// VAPID audience. Empty: derived from each request.
	PublicURL string
	// Secret keys the endpoint HMACs. Empty: loaded from (or created in) DataDir, else random for this process.
	Secret []byte
	// DataDir, when set, keeps registrations and undelivered messages across restarts (state.json, mode 0600).
	DataDir string

	MaxBody           int           // largest accepted request body (default 4096, RFC 8030 section 7.2)
	MaxTTL            time.Duration // longest retention (default 30 days)
	MaxQueuePerClient int           // stored messages per browser (default 100); the oldest is dropped beyond it
	MaxChannels       int           // subscriptions per browser (default 200)
	MaxStoredBytes    int           // all stored bodies together (default 64 MiB); beyond it POST answers 503
	ClientExpiry      time.Duration // forget a browser not seen for this long (default 60 days)
	IdleTimeout       time.Duration // close a WebSocket silent for this long (default 10 minutes)

	// Rate limits for application servers: requests per second and burst, per source address and per endpoint.
	IPRate, IPBurst             float64
	EndpointRate, EndpointBurst float64
	// TrustForwarded takes the client address from X-Forwarded-For (set it only behind your own proxy).
	TrustForwarded bool
	// RequireVAPID refuses posts without a valid VAPID header even for subscriptions made without a key.
	RequireVAPID bool

	Now  func() time.Time
	Logf func(format string, args ...any)
}

Config configures a relay. The zero value works (memory only, random secret) except that endpoints then do not survive a restart.

type Server

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

Server is a relay.

func New

func New(cfg Config) (*Server, error)

New starts a relay.

func (*Server) Close

func (s *Server) Close() error

Close stops the relay, closes every WebSocket and saves the state.

func (*Server) EndpointValid

func (s *Server) EndpointValid(raw string) bool

EndpointValid parses a push endpoint and reports whether its token is valid for this relay.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves the application-server API, the WebSocket and /health.

func (*Server) Stats

func (s *Server) Stats() Stats

Stats returns a snapshot of the counters.

func (*Server) Sweep

func (s *Server) Sweep()

Sweep drops expired messages and forgotten clients now (the janitor calls it every minute).

type Stats

type Stats struct {
	Clients, Connected, Channels, Stored, StoredBytes int
	Accepted, Delivered, Expired, Rejected            int64
}

Stats are counters for /health and tests.

Jump to

Keyboard shortcuts

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