Face

Trait Face 

Source
pub trait Face:
    Send
    + Sync
    + 'static {
    // Required methods
    fn id(&self) -> FaceId;
    fn kind(&self) -> FaceKind;
    fn recv(&self) -> impl Future<Output = Result<Bytes, FaceError>> + Send;
    fn send(
        &self,
        pkt: Bytes,
    ) -> impl Future<Output = Result<(), FaceError>> + Send;

    // Provided methods
    fn remote_uri(&self) -> Option<String> { ... }
    fn local_uri(&self) -> Option<String> { ... }
    fn recv_with_addr(
        &self,
    ) -> impl Future<Output = Result<(Bytes, Option<FaceAddr>), FaceError>> + Send { ... }
    fn link_type(&self) -> LinkType { ... }
}
Expand description

The core face abstraction.

recv is called only from the face’s own task (single consumer). send may be called concurrently from multiple pipeline tasks (must be &self and internally synchronised where the underlying transport requires it).

Required Methods§

Source

fn id(&self) -> FaceId

Source

fn kind(&self) -> FaceKind

Source

fn recv(&self) -> impl Future<Output = Result<Bytes, FaceError>> + Send

Receive the next packet. Blocks until a packet arrives or the face closes.

Source

fn send(&self, pkt: Bytes) -> impl Future<Output = Result<(), FaceError>> + Send

Send a packet. Must not block the caller; use internal buffering.

§LP encoding convention

Network-facing transports (UDP, TCP, Serial, Ethernet) wrap the raw NDN packet in an NDNLPv2 LpPacket envelope before writing to the wire. Local transports (Unix, App, SHM) send the raw packet as-is — the pipeline already strips LP framing before forwarding.

StreamFace makes this explicit via the lp_encode constructor parameter. Custom face implementations should follow the same convention based on FaceKind::scope().

Provided Methods§

Source

fn remote_uri(&self) -> Option<String>

Remote URI (e.g. udp4://192.168.1.1:6363). Returns None for face types that don’t have a meaningful remote endpoint.

Source

fn local_uri(&self) -> Option<String>

Local URI (e.g. unix:///run/nfd/nfd.sock). Returns None for face types that don’t expose local binding info.

Source

fn recv_with_addr( &self, ) -> impl Future<Output = Result<(Bytes, Option<FaceAddr>), FaceError>> + Send

Receive the next packet together with the link-layer sender address.

The default implementation returns None for the source address. Multicast and broadcast faces override this to return the link-layer source, enabling discovery to create unicast reply faces without embedding addresses in NDN payloads.

Link type of this face.

The default is LinkType::PointToPoint for all unicast transports. Multicast and broadcast faces override this to LinkType::MultiAccess. Wi-Fi ad-hoc / MANET faces should return LinkType::AdHoc.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<R, W, C> Face for StreamFace<R, W, C>
where R: AsyncRead + Unpin + Send + Sync + 'static, W: AsyncWrite + Unpin + Send + Sync + 'static, C: Decoder<Item = Bytes, Error = Error> + Encoder<Bytes, Error = Error> + Clone + Send + Sync + 'static,