ForwarderClient

Struct ForwarderClient 

Source
pub struct ForwarderClient {
    pub mgmt: MgmtClient,
    /* private fields */
}
Expand description

Client for connecting to and communicating with a running ndn-fwd forwarder.

Fields§

§mgmt: MgmtClient

Typed management API — shares the control face.

Implementations§

Source§

impl ForwarderClient

Source

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

Connect to the router’s face socket.

Automatically attempts SHM data plane with an auto-generated name; falls back to Unix socket if SHM is unavailable or fails.

Source

pub async fn connect_with_mtu( face_socket: impl AsRef<Path>, mtu: Option<usize>, ) -> Result<Self, ForwarderError>

Connect with an explicit MTU hint for the SHM data plane.

mtu is passed to the router’s faces/create so the SHM ring is sized to carry Data packets whose content body can be up to mtu bytes. Pass None to use the default slot size (enough for ~256 KiB content bodies). Producers that plan to emit larger segments — e.g. chunked transfers at 1 MiB per segment — should pass Some(chunk_size) here.

Source

pub async fn connect_unix_only( face_socket: impl AsRef<Path>, ) -> Result<Self, ForwarderError>

Connect using only the Unix socket for data (no SHM attempt).

Source

pub async fn connect_with_name( face_socket: impl AsRef<Path>, shm_name: Option<&str>, mtu: Option<usize>, ) -> Result<Self, ForwarderError>

Connect with an explicit SHM name for the data plane.

If shm_name is Some, creates an SHM face with that name. If None or SHM creation fails, falls back to Unix-only mode. mtu sizes the SHM ring slot for the expected max Data body.

Source

pub async fn register_prefix(&self, prefix: &Name) -> Result<(), ForwarderError>

Register a prefix with the router via rib/register.

Source

pub async fn unregister_prefix( &self, prefix: &Name, ) -> Result<(), ForwarderError>

Unregister a prefix from the router via rib/unregister.

Source

pub async fn close(self)

Gracefully tear down this client: cancel ongoing ops, destroy the SHM face (if any) via faces/destroy, then close the control socket.

Call this before dropping the client to ensure the router removes the SHM face immediately rather than waiting for GC.

Source

pub async fn send(&self, pkt: Bytes) -> Result<(), ForwarderError>

Send a packet on the data plane.

On the Unix transport, packets are wrapped in a minimal NDNLPv2 LpPacket before sending. External forwarders (yanfd/ndnd, NFD) always use LP framing on their Unix socket faces and reject bare TLV packets; encode_lp_packet is idempotent so already-wrapped packets pass through unchanged. SHM transport does not use LP — the engine handles framing internally.

Source

pub async fn send_batch(&self, pkts: &[Bytes]) -> Result<(), ForwarderError>

Send multiple packets on the data plane in one synchronisation.

On the SHM transport this goes through [SpscHandle::send_batch], which publishes all pkts with a single atomic tail advance and at most one wakeup — the primary reason this API exists. On the Unix transport this is a plain loop over send; the socket path has no equivalent batch primitive and per-packet cost dominates anyway.

A pipelined consumer filling a segmented-fetch window (e.g. ndn-peek) should prefer send_batch over a loop of send calls: it collapses the per-Interest scheduler round-trips into a single ring transition and measurably reduces the small- segment overhead (see docs/notes/throughput-roadmap.md).

Source

pub async fn recv(&self) -> Option<Bytes>

Receive a packet from the data plane.

Returns None if the data channel is closed or the router has disconnected. On the first call, automatically starts the disconnect monitor (see ForwarderClient::spawn_disconnect_monitor) so that callers do not need to start it explicitly.

Source

pub fn is_shm(&self) -> bool

Whether this client is using SHM for data transport.

Source

pub fn is_dead(&self) -> bool

Whether the router connection has been lost.

Source

pub fn spawn_disconnect_monitor(&self)

Explicitly start the disconnect monitor.

This is called automatically on the first ForwarderClient::recv call, so most applications do not need to call this directly.

In SHM mode the monitor watches the control socket for closure (no probes are sent; the control socket is idle after setup). In Unix mode the data recv() already returns None on closure, so this is a no-op.

Safe to call multiple times — only one monitor is ever started.

Source

pub async fn probe_alive(&self) -> bool

Check if the control face is still connected by attempting a non-blocking management probe. Returns true if the router is alive.

Called lazily by applications that detect SHM stalls.

Trait Implementations§

Source§

impl Drop for ForwarderClient

Source§

fn drop(&mut self)

Executes the destructor for this type. 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.

§

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