Skip to main content

Module sync

Module sync 

Source
Expand description

The key-free sync consumer (SSoT: Download & Sync).

SyncConsumer drives GET /v1/sync through the generated REST client — the same paged (cursor, page_size) feed the server serves — authorizing through the SDK session and retrying once on a 401. The opaque, server-MAC’d cursor is round-tripped verbatim: the client stores next_cursor and hands it back untouched.

There was a second transport here and there is not any more. The feed rode capsule.sync.v1.SyncService over tonic, which meant the SDK described one wire contract in a .proto and every other in an OpenAPI document. Nothing below the transport moved: SyncState and its two rules were never about gRPC.

SyncState is the client-side anti-rewind + forward-version layer, split out as a pure, network-free state machine so every rejection rule is a deterministic unit test (sync doc, “Cursor Authenticity and Anti-Rewind”):

  • Forward-version rejection. A feed entry whose protocol_version is above the client’s max known is rejected without partial application — the whole page is validated before any high-water mark advances (the tightened Postel’s Law).
  • Rewind rejection. The client holds a per-album sync_seq high-water mark; a page whose sync_seq regresses against it is surfaced, not applied. This is the independent anti-rewind layer that the server’s cursor MAC cannot provide: a malicious server can always hand back one of its own older, validly-MAC’d cursors, and only the client-held high-water mark defeats that (Download & Sync — cursor authenticity).

Blob bytes never ride this surface; on-demand ranged blob fetch is crate::fetch.

The feed carries only an asset’s latest provenance record. fetch_history walks the chain back from it to the asset’s create through that blob fetch, for a device that first sees an asset past its create and adopts it from its whole chain; history_sources names the live metadata blob and the original that adoption fetches, which an album page’s tombstone does not.

Modules§

reannounce
Re-announcing held manifests after a sync epoch change (#781).

Structs§

BlobManifest
The asset’s blobs by role.
BlobRef
A single blob’s content address and role, carried on a feed entry (never blob bytes).
FeedEntry
One decoded sync feed entry. Ids arrive as opaque bytes (UTF-8 nanoids / raw UUIDs); the manifest and metadata blob pass through as opaque bytes.
HistorySources
The blobs adopting an asset from its fetched history needs beyond its records, by content address: what history_sources reads off a head and the records before it.
SyncConsumer
The sync consumer, over the generated REST client.
SyncCursor
The opaque, server-MAC’d sync cursor. The client never interprets it — it is round-tripped verbatim: empty on first sync, then whatever the server last returned as next_cursor.
SyncPage
A decoded page of the feed plus the cursor for the next page.
SyncState
The client-side reconciliation state: the per-album sync_seq high-water marks, the max-known protocol version, and the opaque cursor. Pure and network-free — SyncState::apply_page is the whole anti-rewind / forward-version contract in one testable function.

Enums§

ChangeKind
What changed, mirroring capsule.sync.v1.ChangeKind.
HistoryError
Why an asset’s earlier provenance records could not be fetched, or the blobs its adoption needs could not be named from them (history_sources). Nothing is verified here — Workspace::adopt_remote_history does that — so each variant is a fact about the walk, not a verdict on the chain.
OriginalAvailability
The derived per-asset original availability — the badge a client’s timeline reads (staged uploads; transfer download doc, “The awaiting-original state”). It is always derived from the feed’s original_held fact, never stored as a second source of truth: an asset whose original has not yet landed on the server shows in the timeline immediately (LQIP, then T1 tiers as they arrive) with an “original still on device” badge, and its full-resolution fetch returns the transient error.blob.pending_upload rather than a failure.
SyncError
Everything the sync consumer / reconciliation can fail with. Callers switch on the typed variant (never a bare gRPC status); SyncError::error_code yields the stable error.* catalog code where one applies.

Constants§

MAX_HISTORY_RECORDS
The most records fetch_history walks back from a head: a chain longer than this is refused (HistoryError::TooLong) rather than held in memory without bound. Every record of a chain is one lifecycle write of one asset, so a real chain is far shorter.
MAX_RECORD_BYTES
The largest provenance record fetch_history accepts (1 MiB). A record is a signed manifest and its chain link, a few KiB; anything past this is not one.

Functions§

fetch_history
Walk an asset’s provenance chain back from head_record (the manifest_cbor a feed entry carries) to its create, fetching each record the one after it names by prior_provenance_hash through source (GET /v1/blob/{hash}, where the server keeps an asset’s superseded records under the live record’s read authority).
history_sources
Name the live metadata blob and the original an asset’s adoption needs, from its head record (a feed entry’s manifest_cbor) and the records before it (fetch_history’s answer).
retention_closed
Whether the retention window of the delete that is head_record (a feed entry’s manifest_cbor) had closed at at: at is at or after the retention_until signed into it, the instant from which the server refuses a trash-restore and stops serving the asset’s records and bytes to its readers.