Skip to main content

OriginFetch

Enum OriginFetch 

Source
pub enum OriginFetch {
    Found {
        stream: OriginByteStream,
        size_hint: Option<u64>,
    },
    NotFound,
    AlreadyAdmitted,
}
Expand description

Result of an Origin::fetch call.

Found carries a streaming primitive so the cache engine pipes origin bytes straight into iroh_blobs::api::blobs::Blobs::add_stream without ever holding the full blob in memory (issue #271). size_hint carries the adapter’s best-effort length advertisement (HTTP Content-Length, filesystem metadata().len(), S3 content_length()); the engine uses it for a short-circuit BlobTooLarge check before reading the first byte and falls back to a running-total check via count_and_cap_stream for adapters that can’t know the length upfront or origins that lie. The hint is advisory — adapters that don’t know set None, and even when set the actual stream length may differ (e.g., HTTP origins lying in Content-Length).

Variants§

§

Found

The origin returned the bytes for this hash as a stream of chunks.

Fields

§stream: OriginByteStream

Chunked byte stream. See OriginByteStream for the bounds.

§size_hint: Option<u64>

Best-effort upfront size estimate from the adapter (HTTP Content-Length, filesystem metadata().len(), S3 content_length()). Treated as advisory by the engine — the running cap on streamed bytes is the load-bearing defense.

§

NotFound

The origin reported the object does not exist (e.g. HTTP 404).

§

AlreadyAdmitted

The origin streamed this blob into the store itself, verifying each chunk group against the rooted hash via crate::CacheEngine::admit_bao_stream, and it is present. The engine does not re-ingest: it reads the committed blob back for a ReturnBytes caller and reports Committed for a fill. The node-to-node pull uses this so a whole blob never lands in RAM.

Implementations§

Source§

impl OriginFetch

Source

pub fn found_one_shot(bytes: Bytes) -> Self

Wrap a fully-buffered Bytes payload as a single-chunk OriginFetch::Found. Useful for tests and any caller that already has the whole payload in hand. Real streaming adapters (FilesystemOrigin, HttpOrigin, S3Origin) construct their streams directly and don’t go through this shim.

Source

pub async fn collect_to_bytes(self) -> Result<Option<Bytes>, Error>

Drain the stream into a single Bytes. Returns Ok(None) for NotFound or AlreadyAdmitted (neither carries a stream to drain — a direct-admit origin’s caller reads the blob back from the store instead), Ok(Some(bytes)) for Found. Used by tests and other helpers that need the full payload as a contiguous buffer; the cache pull-through path goes through add_stream directly and never collects.

The initial allocation is capped at 1 MiB regardless of size_hint so a hostile origin advertising a multi-TiB Content-Length can’t trigger a huge alloc up front. The buffer still grows incrementally past the cap; the engine’s running cap on streamed bytes catches the actual overrun.

Trait Implementations§

Source§

impl Debug for OriginFetch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more