1use bytes::Bytes;
2
3use ndn_faces::local::InProcHandle;
4use ndn_ipc::ForwarderClient;
5use ndn_packet::Name;
6
7use crate::AppError;
8
9pub enum NdnConnection {
14 Embedded(InProcHandle),
16 External(ForwarderClient),
18}
19
20impl NdnConnection {
21 pub async fn send(&self, pkt: Bytes) -> Result<(), AppError> {
23 match self {
24 NdnConnection::Embedded(h) => h.send(pkt).await.map_err(|_| AppError::Closed),
25 NdnConnection::External(c) => c.send(pkt).await.map_err(AppError::Connection),
26 }
27 }
28
29 pub async fn recv(&self) -> Option<Bytes> {
31 match self {
32 NdnConnection::Embedded(h) => h.recv().await,
33 NdnConnection::External(c) => c.recv().await,
34 }
35 }
36
37 pub async fn register_prefix(&self, prefix: &Name) -> Result<(), AppError> {
40 match self {
41 NdnConnection::Embedded(_) => Ok(()), NdnConnection::External(c) => c
43 .register_prefix(prefix)
44 .await
45 .map_err(AppError::Connection),
46 }
47 }
48}