pub struct UdpFace { /* private fields */ }Expand description
NDN face over unicast UDP.
Uses an unconnected socket with send_to / recv_from rather than a
connected socket with send / recv. On macOS (and some BSDs), a
connected UDP socket that receives an ICMP port-unreachable enters a
permanent error state where every subsequent send() fails with
EPIPE (broken pipe). The unconnected approach avoids this entirely —
each datagram is independent at the kernel level.
send_to is &self-safe: UdpSocket::send_to takes &self and UDP
sends are atomic at the kernel level, so no mutex is needed.
Packets larger than the configured MTU are automatically fragmented into NDNLPv2 LpPacket fragments before sending.
Implementations§
Source§impl UdpFace
impl UdpFace
Sourcepub async fn bind(
local: SocketAddr,
peer: SocketAddr,
id: FaceId,
) -> Result<Self>
pub async fn bind( local: SocketAddr, peer: SocketAddr, id: FaceId, ) -> Result<Self>
Bind to local, targeting peer for all sends.
The socket is not connected — recv_from is used and datagrams
from other sources are silently discarded.
If local is 0.0.0.0:0 (or [::]:0), the socket is bound to the
specific local interface that the OS routes to peer. This avoids
EHOSTUNREACH on macOS when the peer is on a non-default-route
subnet (e.g. a VM bridge network).
Sourcepub fn from_socket(id: FaceId, socket: UdpSocket, peer: SocketAddr) -> Self
pub fn from_socket(id: FaceId, socket: UdpSocket, peer: SocketAddr) -> Self
Wrap an already-bound socket, targeting peer for all sends.
Create a face that shares an existing socket (e.g. the UDP listener socket).
Replies go out from the same port the listener is bound to, so the
remote peer’s connected/filtered socket accepts them. The recv()
loop filters datagrams by peer address.
pub fn peer(&self) -> SocketAddr
Trait Implementations§
Source§impl Face for UdpFace
impl Face for UdpFace
Source§async fn recv(&self) -> Result<Bytes, FaceError>
async fn recv(&self) -> Result<Bytes, FaceError>
Receive the next datagram from the peer.
Returns the raw datagram bytes (may be a bare packet or LpPacket). Fragment reassembly is handled by the pipeline’s TlvDecode stage, not here — keeping the Face layer protocol-agnostic.
Datagrams from addresses other than self.peer are silently discarded.
fn id(&self) -> FaceId
fn kind(&self) -> FaceKind
Source§fn remote_uri(&self) -> Option<String>
fn remote_uri(&self) -> Option<String>
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>
fn local_uri(&self) -> Option<String>
unix:///run/nfd/nfd.sock). Returns None for face
types that don’t expose local binding info.