ndn_packet/
lib.rs

1//! # ndn-packet -- NDN packet types and wire-format codec
2//!
3//! Defines the core NDN packet structures and their TLV serialization.
4//! Fields are decoded lazily via `OnceLock` so that fast-path operations
5//! (e.g. Content Store hits) avoid parsing unused fields.
6//!
7//! ## Key types
8//!
9//! - [`Name`] / [`NameComponent`] -- NDN hierarchical names (`SmallVec`-backed).
10//! - [`Interest`] -- Interest packet with lazy decode and optional [`Selector`].
11//! - [`Data`] -- Data packet carrying content, [`MetaInfo`], and [`SignatureInfo`].
12//! - [`Nack`] / [`NackReason`] -- Network-layer negative acknowledgement.
13//! - [`LpHeaders`] -- NDNLPv2 link-protocol header fields.
14//!
15//! ## Feature flags
16//!
17//! - **`std`** (default) -- enables `ring` signatures and fragment reassembly.
18//!   Disable for `no_std` environments (an allocator is still required).
19
20#![allow(missing_docs)]
21// Enable no_std when the `std` feature is disabled.
22// The crate requires an allocator (Name uses SmallVec, Bytes uses heap).
23#![cfg_attr(not(feature = "std"), no_std)]
24#[cfg(not(feature = "std"))]
25extern crate alloc;
26
27pub mod data;
28#[cfg(feature = "std")]
29pub mod encode;
30pub mod error;
31#[cfg(feature = "std")]
32pub mod fragment;
33pub mod interest;
34pub mod lp;
35pub mod meta_info;
36pub mod nack;
37pub mod name;
38pub mod signature;
39
40pub use data::Data;
41pub use error::PacketError;
42pub use interest::{Interest, Selector};
43pub use lp::{CachePolicyType, LpHeaders};
44pub use meta_info::MetaInfo;
45pub use nack::{Nack, NackReason};
46pub use name::{Name, NameComponent};
47pub use signature::{SignatureInfo, SignatureType};
48
49/// Well-known NDN TLV type codes.
50pub mod tlv_type {
51    pub const INTEREST: u64 = 0x05;
52    pub const DATA: u64 = 0x06;
53    pub const NAME: u64 = 0x07;
54    pub const NAME_COMPONENT: u64 = 0x08;
55    pub const IMPLICIT_SHA256: u64 = 0x01;
56    pub const PARAMETERS_SHA256: u64 = 0x02;
57    /// BLAKE3 content-digest component (32 bytes).
58    ///
59    /// **Experimental / NDA extension** — TLV type 0x03 is not yet assigned
60    /// by the NDN Packet Format specification. This value is used by the
61    /// Named Data Architecture (NDA) for self-certifying block identifiers.
62    /// A formal assignment request will be filed with the NDN community.
63    pub const BLAKE3_DIGEST: u64 = 0x03;
64    pub const SEGMENT: u64 = 0x32;
65    pub const KEYWORD: u64 = 0x20;
66    pub const BYTE_OFFSET: u64 = 0x34;
67    pub const VERSION: u64 = 0x36;
68    pub const TIMESTAMP: u64 = 0x38;
69    pub const SEQUENCE_NUM: u64 = 0x3A;
70    pub const CAN_BE_PREFIX: u64 = 0x21;
71    pub const MUST_BE_FRESH: u64 = 0x12;
72    pub const FORWARDING_HINT: u64 = 0x1e;
73    pub const NONCE: u64 = 0x0a;
74    pub const INTEREST_LIFETIME: u64 = 0x0c;
75    pub const HOP_LIMIT: u64 = 0x22;
76    pub const APP_PARAMETERS: u64 = 0x24;
77    pub const META_INFO: u64 = 0x14;
78    pub const CONTENT: u64 = 0x15;
79    pub const SIGNATURE_INFO: u64 = 0x16;
80    pub const SIGNATURE_VALUE: u64 = 0x17;
81    pub const CONTENT_TYPE: u64 = 0x18;
82    pub const FRESHNESS_PERIOD: u64 = 0x19;
83    pub const FINAL_BLOCK_ID: u64 = 0x1a;
84    pub const SIGNATURE_TYPE: u64 = 0x1b;
85    pub const KEY_LOCATOR: u64 = 0x1c;
86    pub const KEY_DIGEST: u64 = 0x1d;
87    pub const NACK: u64 = 0x0320;
88    pub const NACK_REASON: u64 = 0x0321;
89
90    // NDNLPv2 types
91    pub const LP_PACKET: u64 = 0x64;
92    pub const LP_FRAGMENT: u64 = 0x50;
93    pub const LP_SEQUENCE: u64 = 0x51;
94    pub const LP_FRAG_INDEX: u64 = 0x52;
95    pub const LP_FRAG_COUNT: u64 = 0x53;
96    pub const LP_PIT_TOKEN: u64 = 0x62;
97    pub const LP_CONGESTION_MARK: u64 = 0x0340;
98    pub const LP_ACK: u64 = 0x0344;
99    pub const LP_TX_SEQUENCE: u64 = 0x0348;
100    pub const LP_NON_DISCOVERY: u64 = 0x034C;
101    pub const LP_PREFIX_ANNOUNCEMENT: u64 = 0x0350;
102    pub const LP_INCOMING_FACE_ID: u64 = 0x032C;
103    pub const LP_NEXT_HOP_FACE_ID: u64 = 0x0330;
104    pub const LP_CACHE_POLICY: u64 = 0x0334;
105    pub const LP_CACHE_POLICY_TYPE: u64 = 0x0335;
106
107    // Certificate (NDN Packet Format v0.3 §10)
108    pub const VALIDITY_PERIOD: u64 = 0xFD;
109    pub const NOT_BEFORE: u64 = 0xFE;
110    pub const NOT_AFTER: u64 = 0xFF;
111    pub const ADDITIONAL_DESCRIPTION: u64 = 0x0102;
112    pub const DESCRIPTION_ENTRY: u64 = 0x0200;
113    pub const DESCRIPTION_KEY: u64 = 0x0201;
114    pub const DESCRIPTION_VALUE: u64 = 0x0202;
115
116    // Signed Interest (NDN Packet Format v0.3 §5.4)
117    pub const INTEREST_SIGNATURE_INFO: u64 = 0x2C;
118    pub const INTEREST_SIGNATURE_VALUE: u64 = 0x2E;
119    pub const SIGNATURE_NONCE: u64 = 0x26;
120    pub const SIGNATURE_TIME: u64 = 0x28;
121    pub const SIGNATURE_SEQ_NUM: u64 = 0x2A;
122}