pub struct RawPacket {
pub flags: PacketFlags,
pub hops: u8,
pub transport_id: Option<[u8; 16]>,
pub destination_hash: [u8; 16],
pub context: u8,
pub raw: Vec<u8>,
pub packet_hash: [u8; 32],
pub rssi: Option<i16>,
pub snr: Option<f32>,
}Fields§
§flags: PacketFlags§hops: u8§transport_id: Option<[u8; 16]>§destination_hash: [u8; 16]§context: u8§raw: Vec<u8>§packet_hash: [u8; 32]§rssi: Option<i16>§snr: Option<f32>Implementations§
Source§impl RawPacket
impl RawPacket
Sourcepub const fn data_offset(header_type: u8) -> usize
pub const fn data_offset(header_type: u8) -> usize
Offset of the payload in the wire bytes of a packet with this header type.
Sourcepub fn is_link_resource_part(&self) -> bool
pub fn is_link_resource_part(&self) -> bool
Whether this packet is a part of a link resource. Nothing reads such a packet’s hash: the packet filter admits parts before deduplication, no proof or receipt covers them, and the resource receiver locates a part by its map hash. A part’s hash cannot mark any other packet as a duplicate either, since the context byte is hashed.
Sourcepub fn is_link_resource_part_wire(raw: &[u8]) -> bool
pub fn is_link_resource_part_wire(raw: &[u8]) -> bool
RawPacket::is_link_resource_part for wire bytes that are not
unpacked; false when they are too short to carry a context byte.
Sourcepub fn is_unproven_link_data(&self) -> bool
pub fn is_unproven_link_data(&self) -> bool
Whether a link peer never proves this packet: link data in a context with its own protocol handling (requests and responses, resource control and parts, keepalives, identification, RTT and close). Only plain link data and channel messages are proven, so a sent packet in one of these contexts has no receipt to wait for.
Sourcepub fn pack(
flags: PacketFlags,
hops: u8,
destination_hash: &[u8; 16],
transport_id: Option<&[u8; 16]>,
context: u8,
data: &[u8],
) -> Result<Self, PacketError>
pub fn pack( flags: PacketFlags, hops: u8, destination_hash: &[u8; 16], transport_id: Option<&[u8; 16]>, context: u8, data: &[u8], ) -> Result<Self, PacketError>
Pack fields into raw bytes.
Sourcepub fn pack_raw_with_hash(
flags: PacketFlags,
hops: u8,
destination_hash: &[u8; 16],
transport_id: Option<&[u8; 16]>,
context: u8,
data: &[u8],
) -> Result<(Vec<u8>, [u8; 32]), PacketError>
pub fn pack_raw_with_hash( flags: PacketFlags, hops: u8, destination_hash: &[u8; 16], transport_id: Option<&[u8; 16]>, context: u8, data: &[u8], ) -> Result<(Vec<u8>, [u8; 32]), PacketError>
Pack fields into raw bytes and packet hash without constructing a full RawPacket.
Sourcepub fn pack_with_max_mtu(
flags: PacketFlags,
hops: u8,
destination_hash: &[u8; 16],
transport_id: Option<&[u8; 16]>,
context: u8,
data: &[u8],
max_mtu: usize,
) -> Result<Self, PacketError>
pub fn pack_with_max_mtu( flags: PacketFlags, hops: u8, destination_hash: &[u8; 16], transport_id: Option<&[u8; 16]>, context: u8, data: &[u8], max_mtu: usize, ) -> Result<Self, PacketError>
Pack fields into raw bytes with a caller-provided MTU limit.
Sourcepub fn pack_raw_with_hash_with_max_mtu(
flags: PacketFlags,
hops: u8,
destination_hash: &[u8; 16],
transport_id: Option<&[u8; 16]>,
context: u8,
data: &[u8],
max_mtu: usize,
) -> Result<(Vec<u8>, [u8; 32]), PacketError>
pub fn pack_raw_with_hash_with_max_mtu( flags: PacketFlags, hops: u8, destination_hash: &[u8; 16], transport_id: Option<&[u8; 16]>, context: u8, data: &[u8], max_mtu: usize, ) -> Result<(Vec<u8>, [u8; 32]), PacketError>
Pack fields into raw bytes and packet hash with a caller-provided MTU limit.
Sourcepub fn pack_raw_with_max_mtu(
flags: PacketFlags,
hops: u8,
destination_hash: &[u8; 16],
transport_id: Option<&[u8; 16]>,
context: u8,
data: &[u8],
max_mtu: usize,
) -> Result<Vec<u8>, PacketError>
pub fn pack_raw_with_max_mtu( flags: PacketFlags, hops: u8, destination_hash: &[u8; 16], transport_id: Option<&[u8; 16]>, context: u8, data: &[u8], max_mtu: usize, ) -> Result<Vec<u8>, PacketError>
Pack only wire bytes when the caller does not need a packet hash. Validation and encoding match the hash-producing packing methods.
Sourcepub fn unpack(raw: &[u8]) -> Result<Self, PacketError>
pub fn unpack(raw: &[u8]) -> Result<Self, PacketError>
Unpack raw bytes into fields.
Sourcepub fn unpack_owned(raw: Vec<u8>) -> Result<Self, PacketError>
pub fn unpack_owned(raw: Vec<u8>) -> Result<Self, PacketError>
Unpack wire bytes the caller owns, keeping them as raw instead of
copying them.
Sourcepub fn unpack_outbound(raw: Vec<u8>) -> Result<Self, PacketError>
pub fn unpack_outbound(raw: Vec<u8>) -> Result<Self, PacketError>
Unpack owned wire bytes of a packet this node sends. A link resource
part is left unhashed, its packet_hash zeroed, because nothing reads
it (see RawPacket::is_link_resource_part).
Sourcepub fn unpack_prehashed(
raw: &[u8],
packet_hash: [u8; 32],
) -> Result<Self, PacketError>
pub fn unpack_prehashed( raw: &[u8], packet_hash: [u8; 32], ) -> Result<Self, PacketError>
Unpack wire bytes whose packet hash the caller already computed from these exact bytes (for example a delivered packet’s hash), instead of hashing them again. The hash is trusted, not checked.
Sourcepub fn get_hashable_part(&self) -> Vec<u8> ⓘ
pub fn get_hashable_part(&self) -> Vec<u8> ⓘ
Get the hashable part of the packet.
From Python Packet.py:354-361:
- Take raw[0] & 0x0F (mask out upper 4 bits of flags)
- For HEADER_1: append raw[2:]
- For HEADER_2: skip transport_id: append raw[18:]
Sourcepub fn get_truncated_hash(&self) -> [u8; 16]
pub fn get_truncated_hash(&self) -> [u8; 16]
Truncated hash (first 16 bytes) of the cached packet hash.
Packet construction and unpacking compute packet_hash once; routing
paths use this prefix instead of hashing the raw packet again.