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 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.
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.