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 ¶
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 (*Syncer) Kick ¶
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.