pub struct RawPacket<B = Vec<u8>> {
pub flags: PacketFlags,
pub hops: u8,
pub transport_id: Option<[u8; 16]>,
pub destination_hash: [u8; 16],
pub context: u8,
pub raw: B,
pub packet_hash: [u8; 32],
pub rssi: Option<i16>,
pub snr: Option<f32>,
}Expand description
A packet’s header fields and its wire bytes raw, owned (Vec<u8>, the
default) or in other storage: a borrowed view (&[u8]) reads a packet
without copying it, and shared bytes (PacketBytes) are cloned, not copied.
Fields§
§flags: PacketFlags§hops: u8§transport_id: Option<[u8; 16]>§destination_hash: [u8; 16]§context: u8§raw: B§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_unhashed_link_resource_wire(raw: &[u8]) -> bool
pub fn is_unhashed_link_resource_wire(raw: &[u8]) -> bool
RawPacket::is_unhashed_link_resource for wire bytes that are not
unpacked; false when they are too short to carry a context byte.
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.
Pack only wire bytes when the caller does not need a packet hash.
Validation and encoding match the hash-producing packing methods.
RawPacket::pack_raw_with_hash_with_max_mtu into shared bytes.
Sourcepub fn packet_hash_of(header_type: u8, raw: &[u8]) -> [u8; 32]
pub fn packet_hash_of(header_type: u8, raw: &[u8]) -> [u8; 32]
The packet hash of packed wire bytes with the given header type.
RawPacket::pack_raw_shared_with_max_mtu with a payload of
payload_len bytes that fill writes in place, so a payload produced
for this packet (a ciphertext, say) needs no buffer of its own. fill
receives the payload zeroed.
RawPacket::pack_raw_with_max_mtu into shared bytes, allocated once
at their final size, for packets that are routed and sent as they are.
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>
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, part request or proof is left unhashed, its packet_hash
zeroed, because nothing reads it (see
RawPacket::is_unhashed_link_resource).
RawPacket::unpack_owned for shared bytes, kept as they are.
RawPacket::unpack_outbound for shared bytes, kept as they are.
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.
Source§impl<B: AsRef<[u8]>> RawPacket<B>
impl<B: AsRef<[u8]>> RawPacket<B>
Sourcepub fn is_unhashed_link_resource(&self) -> bool
pub fn is_unhashed_link_resource(&self) -> bool
Whether this packet is link resource traffic whose hash nothing
reads: a part, a part request, or a resource proof. The packet filter
admits these contexts before deduplication (Transport.packet_filter),
no proof or receipt covers them, and their handlers read only the
payload (the receiver locates a part by its map hash). Their hashes
cannot mark any other packet as a duplicate either, since the context
byte is hashed, so they are neither computed nor remembered.
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 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.
Sourcepub fn to_owned_packet(&self) -> RawPacket
pub fn to_owned_packet(&self) -> RawPacket
This packet with its bytes copied into an owned buffer.
Source§impl<'a> RawPacket<&'a [u8]>
impl<'a> RawPacket<&'a [u8]>
Sourcepub fn view_prehashed(
raw: &'a [u8],
packet_hash: [u8; 32],
) -> Result<Self, PacketError>
pub fn view_prehashed( raw: &'a [u8], packet_hash: [u8; 32], ) -> Result<Self, PacketError>
RawPacket::unpack_prehashed as a view of raw, without copying it.