Expand description
Tiered, on-demand blob fetch (SSoT: Download & Sync).
Where crate::sync discovers what changed, this module fetches the
smallest representation that satisfies the user’s current intent, and nothing
more. It owns four things the transfer download doc specifies:
- Tiered fetch + cross-asset dedup.
plan_eager_fetchesreturns only the content addresses the configuredFetchScopewants that are not already in the local cache (blobs are content-addressed, so a representation shared between assets — an identical thumbnail — is fetched at most once). - The degrade ladder. When an above-tier representation cannot be fetched,
the client distinguishes permanent (
410 Gone/ purged) from authorization change (403) from transient, and degrades gracefully to the best representation already in hand (best_available) — down to the always-present LQIP — never removing the asset’s metadata or index entry (open_representation). - The render ladder.
render_stepextends that ladder with what the device holds, a RAW original’s embedded preview included, and answers what a surface shows now and what to fetch or generate next; it is the one ladder the apps reach over the FFI. - Resumable ranged fetch.
fetch_blobfetches a blob with HTTPRangewindows; an interrupted transfer resumes from the last persisted byte instead of restarting, and re-fetches zero bytes it already holds.fetch_blob_intostreams the same loop into a writer in bounded windows, so an original of any size is fetched — and, through aStreamDecryptorsink, restored — in bounded memory.RangedFetcher::fetch_to_filelands a blob in a file: it writes a fsynced partial beside the destination, resumes from that partial’s length across a process restart, and renames it into place only once the content address verifies. - Self-verification. The client recomputes the ciphertext content hash against the requested content address; any mismatch discards the blob.
- Opening a derivative. Derivative bytes are ciphertext on the server
(Encryption).
open_representationdecrypts a fetched thumbnail or preview with the material its signedDerivativeManifestrecords — the epoch, the source asset id and the nonce prefix — after running the closed still-format check a receiver owes a manifest it did not author. An AEAD failure is a corrupt blob: it is discarded and the open degrades so the caller regenerates from the original. A tier whose manifest carries theformat = "original"sentinel is satisfied by the original and is never fetched. - Admitting derivative manifests.
verify_derivative_manifestsdecodes the exact bytes a feed entry carries and runs each through core’sverify_derivativechokepoint, walking each(asset, role)chain from its start. Only what it accepts goes intoAssetBlobs::derivative_manifests; what fails is quarantined and returned, never dropped.
The BlobSource seam abstracts the wire so the resume loop and degrade ladder
are driven by deterministic mocks; HttpBlobSource is the production
reqwest-over-Range implementation against the media server’s GET /blob/{hash}.
Structs§
- Asset
Blobs - An asset’s fetchable representations, resolved from a sync feed entry’s blob manifest, plus the signed derivative manifests that open them. LQIP is not here — it rides the metadata blob.
- Empty
Cache - A cache that holds nothing — every planned representation is fetched.
- Http
Blob Source - The production ranged blob source:
reqwestGET /blob/{hash}with aRangeheader, authorized through the SDK session. rustls only. - Local
Holdings - What this device holds for one asset.
- Pixel
Size - A size in device pixels.
- Quarantined
Derivative - One quarantined derivative manifest: surfaced with its reason, never silently dropped.
- Ranged
Fetcher - The resumable ranged-fetch engine: stall-cut-resume, bounded
transfer windows under
adverse, and the sharedRetryEnginebackoff — thebulk-transferretry class the download-resume ladder instantiates. - Render
Request - What a surface asks the ladder for.
- Render
Step - The answer to one
render_step. - Rendition
- What a surface shows: a rung, and the source that fills it.
- RepBlob
- A single representation’s content address and ciphertext size.
- Verified
Derivatives - The outcome of
verify_derivative_manifestsover one feed entry’s manifests.
Enums§
- Degrade
Reason - Why an asset is shown at a lower representation than requested.
- Derivative
Quarantine - Why a received derivative manifest was quarantined rather than admitted.
- Fetch
Error - Why a representation could not be fetched. The variants drive the degrade
ladder:
FetchError::Goneis permanent,FetchError::AuthorizationChangedtriggers a membership re-sync,FetchError::PendingUploadis the transientawaiting-originalstate, and the rest are transient/structural. - Fetch
Resolution - The resolution of an on-demand open.
- Fetch
Scope - The per-library synchronization-scope setting: the eager fetch ceiling. LQIP is always present (embedded); Preview is always on-demand (fetched on open), so it never appears in the eager set even at the highest scope.
- Next
Step - How to obtain the next rung.
- Range
Outcome - The outcome of one ranged request to a
BlobSource. - Representation
- The ladder of an asset’s representations, cheapest first.
Ordis the ladder order, sobest_availablecan degrade with a plainmax. - Rung
Source - Where the pixels of a shown rung come from.
Constants§
- PARTIAL_
SUFFIX - The suffix
partial_pathappends to a destination’s file name. - SINK_
WINDOW - The largest
RangewindowRangedFetcher::fetch_intoasks for: the memory a streamed fetch holds is one of these, whatever the blob’s size. It is the upload protocol’s largest chunk (PROTOCOL_MAX_CHUNK, 16 MiB), so a transfer holds the same bound in either direction. - UNSIZED_
WINDOW - The
RangewindowRangedFetcher::fetch_unsizedasks for (64 KiB). A sealed sidecar is a few KiB, so one window is the usual whole fetch.
Traits§
- AmkSource
- The album keys a reader holds, by epoch — what opens a derivative.
- Blob
Cache - A read-only view of the local content-addressed blob cache, for dedup.
- Blob
Source - The ranged blob transport. Abstracted so the resume loop and degrade ladder are
exercised by deterministic mocks;
HttpBlobSourceis the production impl.
Functions§
- best_
available - The best locally-held representation no higher than
desired— the degrade target. LQIP is always present, so this isSomewheneverheldcontains it. - fetch_
blob - Fetch a whole blob with resumable
Rangewindows, verifying the reassembled ciphertext against its content address. - fetch_
blob_ into - Fetch a whole blob into
sinkwith boundedRangewindows, verifying it against its content address — the unmetered convenience overRangedFetcher::fetch_into, and the bounded-memory counterpart offetch_blob.sinkholds unverified bytes until this returnsOk. - fetch_
blob_ to_ file - Fetch a whole blob into the file
dest— the unmetered convenience overRangedFetcher::fetch_to_file, the file-backed counterpart offetch_blob_into. - open_
representation - Fetch
desiredfor an asset, applying the degrade ladder on failure. - partial_
path - The partial file a download to
destis written to before it is renamed into place:destwithPARTIAL_SUFFIXappended, in the same directory so the rename stays on one filesystem and is atomic. - plan_
eager_ fetches - Plan the eager fetches for one asset under
scope: the content addresses the scope wants that are not already cached, de-duplicated within the plan. A blob already incache(looked up by content address) is skipped — the cross-asset dedup guarantee. - render_
step - One step of the render ladder: what to show, and what to obtain next.
- thumbnail_
long_ edge - The long edge an embedded preview must reach to fill the Thumbnail rung: the Thumbnail tier’s own.
- verify_
derivative_ manifests - Decode and verify a feed entry’s derivative manifests
(
FeedEntry::derivative_manifests) for the assetasset_id, so that only verified ones reachAssetBlobs::derivative_manifests.