syncer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 29 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 syncer is a device's side of sync (ADR-0005, ADR-0017, docs/specs/sync-protocol.md): pairing with hubs, and for each synced vault a loop that pushes what differs from the agreed state, applies the hub's answers, and pulls and applies the heads the hub announces. A device never merges another device's content: it applies a head only where the file still holds its agreed state (vault.Vault.Apply), and otherwise pushes its own change first.

Index

Constants

This section is empty.

Variables

View Source
var ErrCrashed = errors.New("syncer: crashed for the simulation")

ErrCrashed ends a session that Config.Crash stopped.

Functions

This section is empty.

Types

type Config

type Config struct {
	DB      *store.DB
	Blobs   *blobs.Store
	Vaults  *vault.Manager
	Secrets secrets.Store
	// Broker delivers the device's own committed events: the loops watch
	// them for local changes. Publish sends the transient sync.changed.
	Broker  *events.Broker
	Publish func([]api.EventEnvelope)
	Log     *slog.Logger     // [discard]
	Now     func() time.Time // the clock of quiet periods [time.Now]
	// Device is this device's name on hubs unless a pairing names one
	// [the host name].
	Device string
	// Client is the name rpc.hello carries to hubs ["notesd"].
	Client string
	// PartDir holds partial downloads; it must exist.
	PartDir string
	// Dial opens every connection to a hub, for HTTP and the WebSocket
	// alike, so a test can cut a device off [a TCP dial with a 15 s
	// timeout].
	Dial func(ctx context.Context, addr string) (net.Conn, error)
	// HTTP sends pairing and blob requests [a client with timeouts, over
	// Dial].
	HTTP *http.Client
	// Quiet is how long a changed file waits for quiet before it is pushed,
	// and MaxQuiet the longest it waits [2s, 30s]. Idle is how often a loop
	// pulls without an announcement [60s].
	Quiet, MaxQuiet, Idle time.Duration
	// Backoff is the first wait before reconnecting, doubling to MaxBackoff
	// [1s, 60s].
	Backoff, MaxBackoff time.Duration
	// Crash, when set, is asked at each point a crash could fall in a push
	// ("uploaded": after the uploads, before the push; "answered": after
	// the hub's answers, before they are applied); true ends the session
	// with ErrCrashed. The simulation sets it (ADR-0020).
	Crash func(point string) bool
}

Config is what the syncer needs. Zero fields take the defaults in brackets.

type Syncer

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

Syncer runs one loop per synced vault and serves the sync domain.

func New

func New(cfg Config) *Syncer

New returns a syncer over cfg; Start runs its loops.

func (*Syncer) Kick

func (s *Syncer) Kick(vaultID int64)

Kick makes vault's loop look for work now, as a local change or an announcement does.

func (*Syncer) Service

func (s *Syncer) Service() api.SyncService

Service returns the sync domain, for the device's local clients.

func (*Syncer) Start

func (s *Syncer) Start(ctx context.Context) error

Start runs a loop for every synced vault, until ctx ends.

func (*Syncer) Wait

func (s *Syncer) Wait()

Wait waits for every loop to stop after Start's ctx ends.

func (*Syncer) WaitIdle

func (s *Syncer) WaitIdle(ctx context.Context, vaultID int64) error

WaitIdle returns once vault's loop has finished a cycle, begun after the call, that found nothing to push, nothing to pull and nothing pending: the quiet point tests and the simulation check at.

Jump to

Keyboard shortcuts

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