replicationws

package
v0.1.0-alpha.13 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package replicationws adapts Meldbase's trusted-server replication protocol to WebSocket. It intentionally has no browser/session authentication: callers must supply an authorization callback backed by mTLS, a private network identity, or another server-to-server credential.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Receive

func Receive(ctx context.Context, config ReceiverConfig) error

Receive connects one follower to a primary replication endpoint. It returns only after context cancellation, a terminal resync, authentication/transport failure, or a failed follower apply. A batch is ACKed only after it is either covered by the verified bootstrap snapshot or durably applied locally.

Types

type Authorize

type Authorize = replicationauth.Authorize

Authorize must authenticate a server-to-server peer and return its stable durable-consumer name. The name scopes retention and must not be derived from an untrusted frame field. Returning an error rejects the WebSocket upgrade.

func NewMTLSAuthorizer

func NewMTLSAuthorizer(config MTLSConfig) (Authorize, error)

NewMTLSAuthorizer returns an Authorize callback for a net/http server whose TLS configuration requires and verifies client certificates. This helper does not configure TLS itself: callers must set tls.Config.ClientAuth and trusted roots on the server before requests reach the handler.

type Config

type Config struct {
	DB            *meldbase.DB
	Authorize     Authorize
	MaxFrameBytes int
	Buffer        int
}

type Handler

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

Handler serves one authenticated primary/source replication connection. Each connection is pull/acknowledge serialized: it reads hello, writes one batch, waits for its matching ACK, then repeats. This bounds server memory and guarantees that a peer cannot acknowledge an unseen token.

func New

func New(config Config) (*Handler, error)

func (*Handler) ServeHTTP

func (handler *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type MTLSConfig

type MTLSConfig = replicationauth.MTLSConfig

MTLSConfig maps the SHA-256 fingerprint of an already verified peer leaf certificate (lowercase hex over certificate.Raw) to its stable durable consumer name. A fingerprint avoids ambiguous subject/SAN matching and lets operators rotate identities with an explicit configuration change.

type ReceiverConfig

type ReceiverConfig struct {
	Follower              *meldbase.Follower
	URL                   string
	DialOptions           *websocket.DialOptions
	MaxFrameBytes         int
	SourceCheckpointToken uint64
	BootstrapToken        uint64
}

ReceiverConfig configures a follower-side WebSocket client. DialOptions is where callers install an mTLS HTTP client, private-network proxy or other server-to-server transport identity. It must not be used for browser tokens.

Jump to

Keyboard shortcuts

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