#[repr(C)]pub struct RoutingHeader {
pub dest_id: u64,
pub src_id: u32,
pub ttl: u8,
pub hop_count: u8,
pub flags: RouteFlags,
pub _reserved: u8,
}Expand description
Routing header for multi-hop Net packets.
Layout (18 bytes):
┌───────────────────────────────────────────────────────────────────┐
│ magic (2) │ ttl │ hops │ flags │ rsvd │ src_id (4) │ dest_id (8) │
└───────────────────────────────────────────────────────────────────┘magic is always ROUTING_MAGIC (ASCII "RT" on the wire —
0x5452 as a little-endian u16), distinct from the direct-
packet magic 0x4E45. The receive-loop discriminator reads bytes
0-1 alone and dispatches unambiguously — the previous 16-byte
layout put dest_id at bytes 0-7, and any recipient whose
node_id had low-16-bits equal to the direct-packet magic
(~1 in 65 536) silently mis-classified its own incoming routed
packets as Net packets.
Fields§
§dest_id: u64Final destination node ID (64-bit)
src_id: u32Source node ID (truncated to 32-bit for space)
ttl: u8Time-to-live (decremented at each hop)
hop_count: u8Hop count so far
flags: RouteFlagsRoute flags
_reserved: u8Reserved for future use
Implementations§
Source§impl RoutingHeader
impl RoutingHeader
Sourcepub fn to_bytes(&self) -> [u8; 18]
pub fn to_bytes(&self) -> [u8; 18]
Serialize to bytes.
The magic tag rides at bytes 0-1 so the receive-loop
discriminator reads it directly — see ROUTING_MAGIC.
Sourcepub fn from_bytes(buf: &[u8]) -> Option<Self>
pub fn from_bytes(buf: &[u8]) -> Option<Self>
Deserialize from bytes. Returns None on short input, wrong
magic, or malformed numeric fields.
Sourcepub fn read_from(buf: &mut Bytes) -> Option<Self>
pub fn read_from(buf: &mut Bytes) -> Option<Self>
Read from a buffer. Returns None on short input or wrong
magic; fields are consumed only on successful parse.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if TTL is expired
Sourcepub fn forward(&mut self) -> bool
pub fn forward(&mut self) -> bool
Decrement TTL and increment hop count (for forwarding)
hop_count is u8, so on a 256+-hop path the saturating_add
pins it at 255 and the hop_count + 2 indirect-route metric
used downstream undercounts the true distance. Routing
correctness is preserved — ttl (separate, larger) still
bounds loops — but best-route selection may pick a path with
bogus metrics. Log once at saturation so an operator can
notice and reconfigure path lengths or upgrade hop_count to
u16. (Changing the wire format is a breaking change held
off until consumers migrate.)
Trait Implementations§
Source§impl Clone for RoutingHeader
impl Clone for RoutingHeader
Source§fn clone(&self) -> RoutingHeader
fn clone(&self) -> RoutingHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RoutingHeader
impl Debug for RoutingHeader
Source§impl PartialEq for RoutingHeader
impl PartialEq for RoutingHeader
Source§fn eq(&self, other: &RoutingHeader) -> bool
fn eq(&self, other: &RoutingHeader) -> bool
self and other values to be equal, and is used by ==.impl Copy for RoutingHeader
impl Eq for RoutingHeader
impl StructuralPartialEq for RoutingHeader
Auto Trait Implementations§
impl Freeze for RoutingHeader
impl RefUnwindSafe for RoutingHeader
impl Send for RoutingHeader
impl Sync for RoutingHeader
impl Unpin for RoutingHeader
impl UnsafeUnpin for RoutingHeader
impl UnwindSafe for RoutingHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.