replicationws

package
v0.1.0-alpha.14 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 replicationws transfers database changes between trusted servers over WebSocket.

It has no browser or 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 applies ordered source changes to a follower and acknowledges locally durable batches.

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 verifies a replication peer and returns its server-assigned 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 creates a peer authorizer using verified client certificate fingerprints.

The enclosing net/http server must require and verify 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
}

Config supplies the source database, peer authorizer, and replication resource limits.

type Handler

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

Handler sends database changes to authenticated replication peers.

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)

New creates a replication handler after checking its dependencies and resource limits.

func (*Handler) ServeHTTP

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

ServeHTTP authenticates a TLS peer and serves its exclusive replication connection.

type MTLSConfig

type MTLSConfig = replicationauth.MTLSConfig

MTLSConfig maps verified client certificate fingerprints to durable consumer names.

Fingerprints are lowercase SHA-256 hashes of certificate.Raw. They avoid ambiguous subject/SAN matching and let 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 sets the follower, source connection, and starting replication positions.

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