syncserver

package
v2.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package syncserver is the sync socket (GET /api/v1/sync): the automerge-repo network protocol, version 1, over a WebSocket, so the stock @automerge/automerge-repo WebSocket adapter connects to the engine unchanged (docs/adr/0007). It is a driving adapter: it turns protocol messages into calls on the engine's shared-draft service and nothing more, and it keeps no state a later connection needs.

One connection is one peer (a browser tab, a terminal). Per document it holds an Automerge sync state for as long as the connection lives; across replicas it learns of changes through the fan-out port, and, because a fan-out hint may be lost, it also asks every peer it serves for heads on a timer. A lost hint costs latency, never an edit (docs/adr/0008).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v2.1.0

type Option func(*Server)

Option configures a Server.

func WithPing added in v2.1.0

func WithPing(d time.Duration) Option

WithPing pings each peer at this interval, so a quiet connection is not closed by a load balancer's idle timeout (60 s by default behind nginx or an AWS ALB) and a dead one is noticed. 0 turns pings off.

type Server

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

Server serves the sync socket.

func New

func New(shared *engine.Shared, fan fanout.Bus, authz auth.Authorizer, log *slog.Logger, opts ...Option) *Server

New returns a server over the engine's shared drafts. authz decides, per document, whether a peer may read or write it.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades the request and runs one peer until it leaves.

func (*Server) Shutdown added in v2.1.0

func (s *Server) Shutdown()

Shutdown closes every connection with "going away", so each peer reconnects at once (through the load balancer, to a replica that is staying) instead of finding out from a dead socket. Nothing is lost: a peer keeps its changes and offers them again on reconnecting.

func (*Server) Stats added in v2.1.0

func (s *Server) Stats() Stats

Stats returns the current counters.

type Stats added in v2.1.0

type Stats struct {
	Connections int   // peers connected to this replica
	Documents   int   // documents at least one of them has open
	Received    int64 // sync messages received
	Sent        int64 // sync messages sent
	Refused     int64 // messages refused: a read-only peer's change, a protocol error
}

Stats are counters for monitoring.

Jump to

Keyboard shortcuts

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