Skip to main content

Module delegation

Module delegation 

Source
Expand description

Upload delegation: a device hands sealed, signed upload bundles to another device of the same account, which uploads them later as an opaque courier (SSoT: Peering § Delegation).

origin: seal + sign bundle ──hand-off──▶ delegate: verify, fsync, ack, upload ──▶ server
   ▲                                                                                │
   └──────── origin verifies custody of the hashes it computed itself ◀────────────┘

§What moves

A HandOff is one asset’s upload bundle exactly as the origin would upload it: every blob’s POST /v1/upload body (CreateUploadRequest, built by crate::push) and the blob’s bytes, which are ciphertext or signed CBOR. The delegate never holds an album key or plaintext for it, never re-signs, re-encrypts or re-derives anything, and uploads the requests byte for byte under its own session. The server admits the manifest on the origin’s signature, never on who uploads it (capsule-server::upload::signer).

A hand-off is per asset and all or nothing: the delegate verifies every member against the signed manifest before it persists any of it, so it never uploads an incomplete bundle.

§The origin (OriginLedger)

seal builds the hand-off and records the hashes the origin computed itself. The OriginLedger holds each Delegation with a monotonic deadline: on expiry, when the delegate is revoked, or when the clock the deadline was set on is gone (a reboot), the asset is re-queued for the origin to upload itself or delegate again (OriginLedger::due). It is released only through the verify-before-destroy gate over custody facts the origin fetched with its own session for its own hashes, plus a read-back of its own copy (OriginLedger::release); an acknowledgement is never custody, and nothing the delegate relays is consulted. A signed delete of a handed-off asset is held until the create’s custody is confirmed (OriginLedger::hold_delete), so the server never sees a delete for an asset it has not indexed.

§The delegate

accept_hand_off verifies a hand-off (verify_hand_off), persists it durably through a DelegateInbox and only then returns the HandOffAck. upload_hand_off drives the requests in ladder order under the delegate’s own StagedScheduler (its own battery and metering policy), and settle deletes the delegate’s copy once custody of every blob it sent is confirmed. A delegate copy is never a library asset. A held hand-off that can never succeed — its origin revoked after acceptance, its bytes no longer verifying, or a server refusal the delegate cannot act on — is quarantined by dispose_failure, never deleted: a revoked origin is often a lost device, and the delegate’s copy may be the only one left. A quarantined copy keeps its bytes, is no longer retried, and is deleted only when the user asks (DelegateInbox::discard). A transient failure keeps the copy for the next run (DelegationError::is_permanent).

§Transport

The hand-off is a self-verifying byte string with a content address (HandOff::address), so it rides any channel: the peering channel (offer_hand_offs on the origin, take_hand_offs on the delegate, a resumable ranged pull and the acknowledgement over the same verified TLS session), or a file a CLI writes and another reads. Integrity never depends on the channel: the delegate re-verifies every hash and the manifest’s signature, the server verifies the signature again, and the origin trusts only custody it fetched itself. What the channel adds is identity: a peer serves only hand-offs it sealed itself, and an acknowledgement counts only from the device the hand-off was sealed for.

Structs§

DelegatedUpload
What upload_hand_off did.
Delegation
One delegated asset, as the origin records it.
HandOff
One asset’s sealed upload bundle, as it moves from the origin to the delegate.
HandOffAck
A delegate’s acknowledgement: it verified the hand-off and persisted it durably. Not custody.
HandOffHeader
The hand-off’s header: who handed what to whom, and each member’s upload request.
MemoryInbox
An in-memory DelegateInbox: durable for the life of the process.
OriginLedger
The origin’s record of every asset it handed off: pinned until its own custody check passes, re-queued on a deadline or a revocation.
OwnBlob
One blob the origin handed off, as the origin itself computed it.
Quarantine
Why a held hand-off was quarantined, recorded beside its copy when it was.
SealedHandOff
A sealed hand-off: the container to send and what the origin records about it.
TakenHandOff
What became of one hand-off a peer offered.
TakenHandOffs
What one session of take_hand_offs did.
VerifiedHandOff
A hand-off the delegate verified: every member hashes to what its request declares, the signed manifest verifies under the origin’s published key, and every member is the one the manifest commits to.

Enums§

DelegationError
Why a hand-off could not be sealed, accepted, uploaded or settled.
DelegationState
Where a delegation stands on the origin.
DeleteDisposition
What OriginLedger::hold_delete did with a signed delete.
HeldFailure
What dispose_failure did with a held hand-off a run could not deliver.
ReleaseOutcome
What OriginLedger::release decided.
RequeueReason
Why a delegation was re-queued.
Settled
What settle did with the delegate’s copy.

Constants§

DEFAULT_HAND_OFF_DEADLINE_MS
How long an origin waits, by default, for a delegated asset’s custody before it re-queues the upload itself.
HAND_OFF_FORMAT
The hand-off container format this build writes, and the newest it reads.
MAX_HAND_OFF_HEADER
The largest header a hand-off may declare. The header is a few kilobytes of JSON (one upload request per blob); the ceiling bounds a malicious length prefix.
PERMANENT_UPLOAD_REFUSALS
The server’s error.* codes that refuse a hand-off’s requests for good. The delegate sends the origin’s signed requests verbatim and can change none of them, so no later run of the same hand-off can succeed:

Traits§

DelegateInbox
Where a delegate keeps the hand-offs it accepted until custody is confirmed. Never a library: a delegate copy is not an asset of the delegate’s.

Functions§

accept_hand_off
Take a hand-off: verify it (verify_hand_off), persist it durably in inbox, and only then acknowledge it.
accept_hand_off_from
accept_hand_off for a hand-off pulled over a peering channel from peer, the device the channel’s handshake verified: the hand-off must also have been sealed by that peer, so a peer can hand over only its own uploads.
dispose_failure
Decide the fate of the hand-off of asset_id held under address after error: a permanent refusal quarantines the delegate’s copy under a Quarantine note naming kind, so it neither fails every later run nor is lost; a transient one keeps it held.
offer_hand_offs
The origin’s side of a hand-off over a verified peering channel: offer each sealed hand-off to the channel’s peer, serve its ranged pulls, and take its acknowledgements, authorizing every request against trust (serve).
seal
Seal bundle for delegate: the full upload bundle exactly as the origin would upload it, and the hashes the origin computed itself.
settle
Delete the delegate’s copy of hand_off once the server holds every member it can receipt, by custody facts the delegate fetched with its own session through coordinator. Deferred members (deferred non-empty) keep the copy.
take_hand_offs
The delegate’s side of a hand-off over a verified peering channel: pull each hand-off the peer offers, verify it (accept_hand_off_from, so it must be the verified peer’s own), persist it durably, and only then acknowledge it over the same channel.
tier_of
The ladder tier a blob role belongs to (transfer upload doc, §Upload Tiering).
upload_hand_off
Upload a verified hand-off under the delegate’s own session, in the order the delegate’s own scheduler permits — its battery and metering policy, not the origin’s. Each member’s request is sent exactly as the origin built it.
verify_hand_off
Verify a hand-off addressed to delegate_device, all or nothing.