Consumer

Struct Consumer 

Source
pub struct Consumer { /* private fields */ }
Expand description

High-level NDN consumer — fetches Data by name.

Implementations§

Source§

impl Consumer

Source

pub async fn connect(socket: impl AsRef<Path>) -> Result<Self, AppError>

Connect to an external router via its face socket.

Source

pub fn from_handle(handle: InProcHandle) -> Self

Create from an in-process InProcHandle (embedded engine).

Source

pub async fn fetch(&mut self, name: impl Into<Name>) -> Result<Data, AppError>

Express an Interest by name and return the decoded Data.

Uses DEFAULT_INTEREST_LIFETIME for the wire Interest and DEFAULT_TIMEOUT for the local wait. To set hop limit, application parameters, or forwarding hints, use fetch_with.

Source

pub async fn fetch_with( &mut self, builder: InterestBuilder, ) -> Result<Data, AppError>

Express an Interest built with InterestBuilder and return the decoded Data.

The local wait timeout is derived from the builder’s Interest lifetime (+ 500 ms forwarding buffer). This is the right method when you need hop limit, forwarding hints, or application parameters:

use ndn_packet::encode::InterestBuilder;

// Hop limit: limit forwarding to 4 hops.
let data = consumer.fetch_with(
    InterestBuilder::new("/ndn/remote/data").hop_limit(4)
).await?;

// Forwarding hint: reach a producer via a delegation prefix.
let data = consumer.fetch_with(
    InterestBuilder::new("/alice/files/photo.jpg")
        .forwarding_hint(vec!["/campus/ndn-hub".parse()?])
).await?;

// Application parameters: parameterised fetch (e.g. RPC / query).
let data = consumer.fetch_with(
    InterestBuilder::new("/service/query")
        .app_parameters(b"filter=recent&limit=10")
).await?;
Source

pub async fn fetch_wire( &mut self, wire: Bytes, timeout: Duration, ) -> Result<Data, AppError>

Express a pre-encoded Interest and return the decoded Data.

timeout is the local wait duration — set this to at least the Interest lifetime encoded in wire to avoid timing out before the forwarder does.

Returns AppError::Nacked if the forwarder responds with a Nack (e.g. no route to the name prefix).

Source

pub async fn fetch_verified( &mut self, name: impl Into<Name>, validator: &Validator, ) -> Result<SafeData, AppError>

Fetch and verify against a Validator. Returns SafeData on success.

Source

pub async fn get(&mut self, name: impl Into<Name>) -> Result<Bytes, AppError>

Convenience: fetch content as raw bytes.

Source

pub async fn fetch_all(&mut self, names: &[Name]) -> Vec<Result<Data, AppError>>

Fetch multiple names sequentially and collect results.

Each Interest is expressed in order; the result vector preserves the input order regardless of which fetches succeed or fail.

§Note

Fetches are sequential because a single NdnConnection cannot correlate concurrent Interests to their responses without PIT tokens. For true concurrent fetch, create multiple Consumer instances and use tokio::join!.

Source

pub async fn fetch_with_retry( &mut self, name: impl Into<Name>, max_attempts: u32, base_delay: Duration, ) -> Result<Data, AppError>

Fetch with exponential-backoff retry.

On timeout or connection error, waits base_delay, then 2×base_delay, etc., up to max_attempts total tries (including the first). Returns the last error if all attempts are exhausted.

Source

pub async fn fetch_segmented( &mut self, prefix: impl Into<Name>, ) -> Result<Bytes, AppError>

Fetch a segmented object produced with [Producer::publish_large].

Fetches /prefix/0, reads FinalBlockId to determine the total segment count, then fetches all remaining segments in order. Segments are reassembled into a single contiguous buffer.

Segment names are generic NameComponents with ASCII-decimal indices (e.g. /prefix/0, /prefix/1, …), matching the convention used by [Producer::publish_large].

Source

pub async fn get_verified( &mut self, name: impl Into<Name>, validator: &Validator, ) -> Result<SafeData, AppError>

Fetch and verify against a Validator. Returns SafeData on success.

This is a convenience wrapper around fetch + Validator::validate_chain.

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.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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