pub struct MessageHeader {
pub version: u8,
pub topic: TopicId,
pub msg_id: [u8; 32],
pub kind: MessageKind,
pub hop: u8,
pub ttl: u8,
pub payload_hash: Option<[u8; 32]>,
}Expand description
Wire format header for control frames (ML-DSA signed)
Format: ver:u8, topic:[u8;32], msg_id:[u8;32], kind:u8, hop:u8, ttl:u8
— v1, and exactly that. ADR-012 v2 appends
payload_hash: Option<[u8;32]> after ttl; the tail is serialized only
when version >= 2, so a v1 header re-serializes byte-identically (its
existing signature must keep verifying) and a v1 buffer never misparses
into v2.
Fields§
§version: u8Protocol version
topic: TopicIdTopic identifier
msg_id: [u8; 32]Message ID: BLAKE3(topic || epoch || signer || payload_hash)[:32]
kind: MessageKindMessage kind
hop: u8Current hop count
ttl: u8Time-to-live
payload_hash: Option<[u8; 32]>ADR-012 v2: BLAKE3 of the payload bytes the header signature covers.
None for v1 headers (the header-only-signature era) and for
payload-less control frames it is Some of the empty-input hash.
Implementations§
Source§impl MessageHeader
impl MessageHeader
Sourcepub fn new(topic: TopicId, kind: MessageKind, ttl: u8) -> MessageHeader
pub fn new(topic: TopicId, kind: MessageKind, ttl: u8) -> MessageHeader
Create a new message header
Sourcepub fn seal_payload_hash(&mut self, payload: Option<&[u8]>)
pub fn seal_payload_hash(&mut self, payload: Option<&[u8]>)
ADR-012: stamp the payload-covering hash and bump the wire version
to 2. Payload-less control frames pass None; receivers hash
payload.unwrap_or_default() symmetrically, so the empty-input hash
is the canonical cover for “no payload”.
Sourcepub fn calculate_msg_id(
topic: &TopicId,
epoch: u64,
signer: &PeerId,
payload_hash: &[u8; 32],
) -> [u8; 32]
pub fn calculate_msg_id( topic: &TopicId, epoch: u64, signer: &PeerId, payload_hash: &[u8; 32], ) -> [u8; 32]
Calculate message ID from components
Sourcepub fn increment_hop(&mut self) -> Result<(), Error>
pub fn increment_hop(&mut self) -> Result<(), Error>
Increment hop count
Sourcepub fn decrement_ttl(&mut self) -> Result<(), Error>
pub fn decrement_ttl(&mut self) -> Result<(), Error>
Decrement TTL
Trait Implementations§
Source§impl Clone for MessageHeader
impl Clone for MessageHeader
Source§fn clone(&self) -> MessageHeader
fn clone(&self) -> MessageHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more