Skip to main content

Module fetch

Module fetch 

Source
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_fetches returns only the content addresses the configured FetchScope wants 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_step extends 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_blob fetches a blob with HTTP Range windows; an interrupted transfer resumes from the last persisted byte instead of restarting, and re-fetches zero bytes it already holds. fetch_blob_into streams the same loop into a writer in bounded windows, so an original of any size is fetched — and, through a StreamDecryptor sink, restored — in bounded memory. RangedFetcher::fetch_to_file lands 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_representation decrypts a fetched thumbnail or preview with the material its signed DerivativeManifest records — 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 the format = "original" sentinel is satisfied by the original and is never fetched.
  • Admitting derivative manifests. verify_derivative_manifests decodes the exact bytes a feed entry carries and runs each through core’s verify_derivative chokepoint, walking each (asset, role) chain from its start. Only what it accepts goes into AssetBlobs::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§

AssetBlobs
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.
EmptyCache
A cache that holds nothing — every planned representation is fetched.
HttpBlobSource
The production ranged blob source: reqwest GET /blob/{hash} with a Range header, authorized through the SDK session. rustls only.
LocalHoldings
What this device holds for one asset.
PixelSize
A size in device pixels.
QuarantinedDerivative
One quarantined derivative manifest: surfaced with its reason, never silently dropped.
RangedFetcher
The resumable ranged-fetch engine: stall-cut-resume, bounded transfer windows under adverse, and the shared RetryEngine backoff — the bulk-transfer retry class the download-resume ladder instantiates.
RenderRequest
What a surface asks the ladder for.
RenderStep
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.
VerifiedDerivatives
The outcome of verify_derivative_manifests over one feed entry’s manifests.

Enums§

DegradeReason
Why an asset is shown at a lower representation than requested.
DerivativeQuarantine
Why a received derivative manifest was quarantined rather than admitted.
FetchError
Why a representation could not be fetched. The variants drive the degrade ladder: FetchError::Gone is permanent, FetchError::AuthorizationChanged triggers a membership re-sync, FetchError::PendingUpload is the transient awaiting-original state, and the rest are transient/structural.
FetchResolution
The resolution of an on-demand open.
FetchScope
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.
NextStep
How to obtain the next rung.
RangeOutcome
The outcome of one ranged request to a BlobSource.
Representation
The ladder of an asset’s representations, cheapest first. Ord is the ladder order, so best_available can degrade with a plain max.
RungSource
Where the pixels of a shown rung come from.

Constants§

PARTIAL_SUFFIX
The suffix partial_path appends to a destination’s file name.
SINK_WINDOW
The largest Range window RangedFetcher::fetch_into asks 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 Range window RangedFetcher::fetch_unsized asks 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.
BlobCache
A read-only view of the local content-addressed blob cache, for dedup.
BlobSource
The ranged blob transport. Abstracted so the resume loop and degrade ladder are exercised by deterministic mocks; HttpBlobSource is the production impl.

Functions§

best_available
The best locally-held representation no higher than desired — the degrade target. LQIP is always present, so this is Some whenever held contains it.
fetch_blob
Fetch a whole blob with resumable Range windows, verifying the reassembled ciphertext against its content address.
fetch_blob_into
Fetch a whole blob into sink with bounded Range windows, verifying it against its content address — the unmetered convenience over RangedFetcher::fetch_into, and the bounded-memory counterpart of fetch_blob. sink holds unverified bytes until this returns Ok.
fetch_blob_to_file
Fetch a whole blob into the file dest — the unmetered convenience over RangedFetcher::fetch_to_file, the file-backed counterpart of fetch_blob_into.
open_representation
Fetch desired for an asset, applying the degrade ladder on failure.
partial_path
The partial file a download to dest is written to before it is renamed into place: dest with PARTIAL_SUFFIX appended, 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 in cache (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 asset asset_id, so that only verified ones reach AssetBlobs::derivative_manifests.