pub struct UploadClient { /* private fields */ }Expand description
The hand-written chunked, resumable, adaptive upload client.
Implementations§
Source§impl UploadClient
impl UploadClient
Sourcepub fn new(transport: UploadTransport) -> Self
pub fn new(transport: UploadTransport) -> Self
Build a client over an authorized UploadTransport, on an unmetered link, with a
lane retry budget of its own that every clone shares.
Sourcepub fn with_ranges_window(self, ranges: u32) -> Self
pub fn with_ranges_window(self, ranges: u32) -> Self
Hold up to ranges ranges of each session in flight (P), clamped into
1..=MAX_RANGES_WINDOW. A session’s advertised ranges narrows it further, and so
does a too_many_in_flight; under a scheduler each range also
waits for the scheduler’s own window and byte budget.
Sourcepub fn ranges_window(&self) -> u32
pub fn ranges_window(&self) -> u32
P: the most ranges of one session this client holds in flight.
Sourcepub fn with_lane_retries(self, lane: LaneRetries) -> Self
pub fn with_lane_retries(self, lane: LaneRetries) -> Self
Spend retries from lane — the budget the upload queue holds for this client’s server
(UploadQueue::lane_retries) — so every transfer to
the server, and the queue’s own retries, share one bound.
Sourcepub fn lane_retries(&self) -> &LaneRetries
pub fn lane_retries(&self) -> &LaneRetries
The lane retry budget this client spends from.
Sourcepub fn with_events(self, events: TransferEvents) -> Self
pub fn with_events(self, events: TransferEvents) -> Self
Publish every transfer this client drives to events (session, chunk, retry,
checksum-reject, finalize and merge steps). Without a subscriber it costs nothing.
Sourcepub fn events(&self) -> &TransferEvents
pub fn events(&self) -> &TransferEvents
The event handle this client publishes to.
Sourcepub fn with_connection_class(self, class: ConnectionClass) -> Self
pub fn with_connection_class(self, class: ConnectionClass) -> Self
Set the detected connection class (the target request duration follows it). On an
ConnectionClass::Adverse link every transfer this client drives sizes its chunks to
the shorter ADVERSE_TARGET_REQUEST_DURATION.
Sourcepub fn connection_class(&self) -> ConnectionClass
pub fn connection_class(&self) -> ConnectionClass
The connection class this client sizes its chunks for.
Sourcepub fn with_request_bounds(self, bounds: RequestBounds) -> Self
pub fn with_request_bounds(self, bounds: RequestBounds) -> Self
Run every request this client sends under bounds instead of
RequestBounds::default.
Sourcepub async fn create_session(
&self,
request: &CreateUploadRequest,
) -> Result<CreateOutcome, UploadError>
pub async fn create_session( &self, request: &CreateUploadRequest, ) -> Result<CreateOutcome, UploadError>
Create an upload session (POST /upload).
Resolves to CreateOutcome::Created, or CreateOutcome::AlreadyStored
on duplicate_blob (the merge trigger). A 426 returns
UploadError::UpgradeRequired — the session is never created.
This is one request: a retryable answer (rate_limited, unavailable,
storage_full, any 5xx, 408, 425) comes back as UploadError::Rejected.
UploadClient::upload waits those out.
Sourcepub async fn head(
&self,
session_id: &str,
) -> Result<Option<HeadInfo>, UploadError>
pub async fn head( &self, session_id: &str, ) -> Result<Option<HeadInfo>, UploadError>
Query progress (HEAD /upload/{id}). Ok(None) means the session is gone
(404) — a discarded/expired/never-existent session is uniform.
This is one request: a retryable answer (any 5xx, 408, 425, 429) comes
back as UploadError::Rejected. The transfer loop waits those out.
Sourcepub async fn delete(&self, session_id: &str) -> Result<(), UploadError>
pub async fn delete(&self, session_id: &str) -> Result<(), UploadError>
Cancel a session (DELETE /upload/{id}). Idempotent for the caller: a
404 (already gone) resolves as Ok(()); a 409 (finalization running,
not interruptible, or the session already finished) surfaces as
UploadError::Rejected with error.upload.session_not_active.
push::redact_asset reads that answer as a
session that finalized during the abort.
Sourcepub async fn list_sessions(&self) -> Result<Vec<SessionSummary>, UploadError>
pub async fn list_sessions(&self) -> Result<Vec<SessionSummary>, UploadError>
List the uploader’s active sessions (GET /upload/sessions), so a client
can resume across app restarts.
Sourcepub async fn upload<S: UploadSource + ?Sized>(
&self,
request: &CreateUploadRequest,
data: &S,
) -> Result<UploadOutcome, UploadError>
pub async fn upload<S: UploadSource + ?Sized>( &self, request: &CreateUploadRequest, data: &S, ) -> Result<UploadOutcome, UploadError>
Transfer a full ciphertext blob with the adaptive algorithm and the code-driven recovery matrix, starting from a fresh session.
data is the ciphertext’s source (opaque bytes); the client reads it one
chunk window at a time — never whole — and checksums each chunk. Every byte is sent when
the received-byte count reaches the declared size, at which point the server finalizes.
The server answers the completing chunk waiting_for_processing without waiting for
finalization, so the client then polls HEAD with backoff until the session is
completed — the outcome — or failed_processing, which is an
UploadError::Rejected carrying the X-Capsule-Upload-Error code.
A retryable answer to any request it makes — the create, a chunk, or a HEAD —
is waited out, each wait charging the one recovery budget the transfer shares and
the lane’s shared retry budget. That is rate_limited, unavailable,
storage_full, and every other 5xx, 408 or 425; a chunk’s wait resumes from
HEAD, so a completing chunk answered 500 storage_inconsistent settles on what
the server says it holds.
Sourcepub async fn upload_gated<S: UploadSource + ?Sized>(
&self,
request: &CreateUploadRequest,
data: &S,
gate: &dyn TransferGate,
) -> Result<UploadOutcome, UploadError>
pub async fn upload_gated<S: UploadSource + ?Sized>( &self, request: &CreateUploadRequest, data: &S, gate: &dyn TransferGate, ) -> Result<UploadOutcome, UploadError>
UploadClient::upload under a scheduler: every range the transfer sends first
reserves its length through gate and gives it back once the request ends, and the
advice the server sends on the session’s create and HEADs is reported to it. This is
how a lane’s sessions in flight share the device’s one byte budget.
Sourcepub async fn upload_resuming<S: UploadSource + ?Sized>(
&self,
session_id: &str,
request: &CreateUploadRequest,
data: &S,
) -> Result<UploadOutcome, UploadError>
pub async fn upload_resuming<S: UploadSource + ?Sized>( &self, session_id: &str, request: &CreateUploadRequest, data: &S, ) -> Result<UploadOutcome, UploadError>
Resume an existing session: HEAD for the authoritative offset, then
continue from there — no bytes the server already holds are re-sent
(transfer upload doc, §Idempotency and Resumption). If the session is gone
(404), it is re-created and driven from zero.
Trait Implementations§
Source§impl Clone for UploadClient
impl Clone for UploadClient
Source§fn clone(&self) -> UploadClient
fn clone(&self) -> UploadClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for UploadClient
impl !UnwindSafe for UploadClient
impl Freeze for UploadClient
impl Send for UploadClient
impl Sync for UploadClient
impl Unpin for UploadClient
impl UnsafeUnpin for UploadClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more