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: OriginByteStreamChunked byte stream. See OriginByteStream for the bounds.
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
impl OriginFetch
Sourcepub fn found_one_shot(bytes: Bytes) -> Self
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.
Sourcepub async fn collect_to_bytes(self) -> Result<Option<Bytes>, Error>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for OriginFetch
impl !UnwindSafe for OriginFetch
impl Freeze for OriginFetch
impl Send for OriginFetch
impl Sync for OriginFetch
impl Unpin for OriginFetch
impl UnsafeUnpin for OriginFetch
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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