Skip to main content

Module push

Module push 

Source
Expand description

Pushing a locally-imported asset to a server — the glue between capsule_core’s UploadBundle and the hand-written upload client.

capsule-core builds the bundle (ciphertext, sealed metadata blob, derivatives, and the manifest-envelope projection); this module turns it into the protocol’s POST /upload bodies and drives them in tier ladder order. Nothing here re-implements a network flow — every byte goes through UploadClient, and the ordering/gating goes through StagedScheduler::plan_sessions.

Resume derives from server truth. There is no push-side state file: pull the sync feed, fold it with held_from_feed into the set of blob content addresses the server durably holds, and remaining_tiers rebuilds exactly the outstanding work. Within a blob, POST /upload’s idempotent re-create returns the authoritative offset; across an asset’s blobs, a duplicate_blob answer is a merge, not an error. Re-running a push against an unchanged library is therefore a no-op.

§The index tier is two blobs, not one

T0 is provenance and metadata, in that order. The server publishes an asset to other devices only once it holds both index-tier roles (capsule_server::upload::visibility::INDEX_TIER_ROLES), and the head of the server-side provenance chain — what a later lifecycle op’s prior_provenance_hash must equal — is the SHA-256 of the provenance blob’s bytes. A ladder that shipped only the metadata blob therefore uploaded an asset that no device could ever see and no op could ever chain onto: the bytes were on the server and the asset was not in anybody’s library.

The provenance blob is the canonical CBOR of the chain’s head ProvenanceRecord (UploadBundle::provenance_blob), which capsule-core encodes once so the SDK and the FFI cannot disagree about it. It goes first within T0: it is the blob the server reads prior_provenance_hash, action and retention_until out of, so sending it first is the order in which the asset’s own claims arrive before the bytes they describe.

Every blob this module ships is ciphertext. The original is re-derived from its manifest’s nonce prefix one upload chunk at a time (BlobBytes::Original), so a push holds one chunk window of an original and never the whole file; the metadata blob is carried sealed, and derivative blobs are encrypted too — capsule-core re-derives each one from the plaintext it holds locally using the prefix that derivative’s signed manifest recorded. Nothing here decrypts, encrypts, or inspects a blob; it moves opaque bytes.

One deviation from “the envelope mirrors the signed manifest”, and it is the server’s rule: invariant 15 requires manifest_envelope.ciphertext_hash == hash (the top-level declared content address of this blob). A bundle’s metadata and derivative blobs are not the original, so their envelope carries their own content address; every other field is the head manifest’s, verbatim. See envelope_for.

§A transfer is not custody

Every byte reaching the server is not the same as the server holding the asset. A finalize that lost its claim race answers the chunk 204 and is still running; an index failure after the commit leaves bytes nobody references. So a push does not end at the last chunk: verify_custody asks POST /storage/verify whether every blob the asset now relies on is stored, indexed and retrievable, then fetches the asset’s custody-receipt log and requires a receipt per blob that verifies under the server’s attestation-key history and names the exact bytes, size and role the client sent. That history is the one the caller pinned for the server (capsule_library::library::pin_attestation_keys), never a fetch trusted on its own. Only then is the asset reported as pushed, and the verified receipts are what the caller persists beside the provenance chain.

Structs§

AssetPushReport
What pushing one asset did.
BundleBlob
One transferable blob of an UploadBundle: its ladder tier, protocol blob role, declared content type, and the bytes themselves (borrowed from the bundle). Paired with its content address by bundle_blobs.
LaneBundle
One bundle queued on a lane, with the server truth its plan prunes against (see push_bundle’s held).
LanePush
One server’s share of a push_lanes run: the client that reaches it, and the bundles queued for it.
PushPlan
What a push would do for one bundle: the blobs it plans to open sessions for, in ladder order, plus what it skipped and why. Computed without touching the network — the dry-run primitive, and the first half of push_bundle.
PushedBlob
How one blob of a bundle resolved.
Redaction
What redact_asset did to one asset’s open upload sessions.
VerifiedCustody
What verify_custody established for one asset.

Enums§

BlobBytes
Where a BundleBlob’s bytes come from. Everything but the original is small and already in the bundle; the original is a OriginalCiphertext source the upload client reads one chunk window at a time, so a push never holds an original whole.
PushError
Errors a push can fail with.

Constants§

PUSH_BATCH_BUNDLES
The most bundles a caller pushing a long list of assets should hold at once: it pushes them in batches of this many, each batch through one push_lanes run. Four times the widest sessions window keeps that window full for most of a batch, while a list of any length holds at most this many bundles’ derivatives in memory.
PUSH_BYTE_BUDGET
The device-wide byte budget a push run’s ranges reserve against when the caller has no narrower one: four of the protocol’s largest chunks in flight at once, however many sessions and servers the run drives.

Functions§

bundle_blobs
Every transferable blob of bundle, in ladder order: the index tier (T0) — the provenance blob then the sealed metadata blob — the preview tier (T1) — each derivative tier’s signed manifest, then each derivative — then the original (T2).
create_request
The POST /upload body for one blob of bundle.
ensure_album
Register album_id with the server before any blob session opens for it.
envelope_for
The ManifestEnvelope for one blob of bundle: every field of the head manifest, verbatim, with ciphertext_hash naming this blob (the server’s invariant-15 consistency rule — manifest_envelope.ciphertext_hash must equal the top-level hash).
plan
Plan a push for one bundle: prune to what server truth says is outstanding, then let the scheduler decide which of those tiers open now.
push_bundle
Push one UploadBundle through client, in the order scheduler permits.
push_lanes
Push every lane’s bundles through one device-wide UploadQueue, up to W at once per lane.
redact_asset
Abort every open upload session this account holds for asset_id: the network half of redacting an asset deleted before its upload finished (Organization — Deletion State Machine).
staged_asset
The bundle as a StagedAsset the scheduler can order and gate.
verify_custody
Confirm the server holds what push_bundle sent, and collect the evidence that it does.
verify_custody_with_events
verify_custody, publishing the verdict (TransferEvent::Verify) and each verified receipt (TransferEvent::Receipt) to events.