class

RNS::Packet

Inherits Reference < Object

The fundamental data unit in Reticulum. Handles serialization to/from wire format, encryption via destination identities, header construction, hash-based addressing, and proof generation for reliable delivery.

Constants

ANNOUNCE = 1_u8
CACHE_REQUEST = 8_u8
CHANNEL = 14_u8
COMMAND = 12_u8
COMMAND_STATUS = 13_u8
DATA = 0_u8

─── Packet types ───────────────────────────────────────────────

ENCRYPTED_MDU = ((((Reticulum::MDU - Identity::TOKEN_OVERHEAD) - (Identity::KEYSIZE // 16)) // Identity::AES128_BLOCKSIZE) * Identity::AES128_BLOCKSIZE) - 1

With an MTU of 500, the maximum of data we can send in a single encrypted packet is 383 bytes.

FLAG_SET = 1_u8

─── Context flag values ───────────────────────────────────────

FLAG_UNSET = 0_u8
HEADER_1 = 0_u8

─── Header types ──────────────────────────────────────────────

HEADER_2 = 1_u8
HEADER_MAXSIZE = Reticulum::HEADER_MAXSIZE

─── Size constants ────────────────────────────────────────────

HEADER_MINSIZE = Reticulum::HEADER_MINSIZE
KEEPALIVE = 250_u8
LINKCLOSE = 252_u8
LINKIDENTIFY = 251_u8
LINKPROOF = 253_u8
LINKREQUEST = 2_u8
LRPROOF = 255_u8
LRRTT = 254_u8
MDU = Reticulum::MDU
NONE = 0_u8

─── Context types ─────────────────────────────────────────────

PATH_RESPONSE = 11_u8
PLAIN_MDU = MDU
PROOF = 3_u8
REQUEST = 9_u8
RESOURCE = 1_u8
RESOURCE_ADV = 2_u8
RESOURCE_HMU = 4_u8
RESOURCE_ICL = 6_u8
RESOURCE_PRF = 5_u8
RESOURCE_RCL = 7_u8
RESOURCE_REQ = 3_u8
RESPONSE = 10_u8
TIMEOUT_PER_HOP = Reticulum::DEFAULT_PER_HOP_TIMEOUT

Constructors

new(destination : Destination::DestinationInterface | Nil, data : Bytes, packet_type : UInt8 = DATA, context : UInt8 = NONE, transport_type : UInt8 = Transport::BROADCAST, header_type : UInt8 = HEADER_1, transport_id : Bytes | Nil = nil, attached_interface = nil, create_receipt : Bool = true, context_flag : UInt8 = FLAG_UNSET)

Creates a new packet. When destination is provided, builds a packet for sending with the given data payload, packet_type, and routing parameters. When destination is nil, treats data as raw wire bytes for unpacking.

Source

Instance methods

attached_interface
Source
attached_interface=(attached_interface : Interface | Nil)
Source
ciphertext
Source
ciphertext=(ciphertext : Bytes | Nil)
Source
context
Source
context=(context : UInt8)
Source
context_flag
Source
context_flag=(context_flag : UInt8)
Source
create_receipt
Source
create_receipt=(create_receipt : Bool)
Source
data
Source
data=(data : Bytes)
Source
destination
Source
destination=(destination : Destination::DestinationInterface | Nil)
Source
destination_hash
Source
destination_hash=(destination_hash : Bytes | Nil)
Source
destination_type
Source
destination_type=(destination_type : UInt8 | Nil)
Source
flags
Source
flags=(flags : UInt8)
Source
from_packed
Source
from_packed=(from_packed : Bool)
Source
generate_proof_destination
Source
get_hash

Returns the full SHA-256 hash of this packet's hashable part.

Source
get_hashable_part
Source
get_packed_flags
Source
get_truncated_hash

Returns the truncated hash of this packet, used for addressing and proof routing within the network.

Source
header
Source
header=(header : Bytes | Nil)
Source
header_type
Source
header_type=(header_type : UInt8)
Source
hops

─── Instance properties ───────────────────────────────────────

Source
hops=(hops : UInt8)

─── Instance properties ───────────────────────────────────────

Source
map_hash

NOTE: property link : Link? — not added due to Packet/Link circular dependency

Source
map_hash=(map_hash : Bytes | Nil)

NOTE: property link : Link? — not added due to Packet/Link circular dependency

Source
mtu=(mtu : Int32)
Source
pack

Serializes the packet into wire format by constructing the header, encrypting the payload when required, and concatenating into @raw.

Source
packed
Source
packed=(packed : Bool)
Source
packet_hash
Source
packet_hash=(packet_hash : Bytes | Nil)
Source
packet_type
Source
packet_type=(packet_type : UInt8)
Source
plaintext
Source
plaintext=(plaintext : Bytes | Nil)
Source
q=(q : Float64 | Nil)
Source
ratchet_id
Source
ratchet_id=(ratchet_id : Bytes | Nil)
Source
raw=(raw : Bytes | Nil)
Source
receipt
Source
receipt=(receipt : PacketReceipt | Nil)
Source
receiving_interface
Source
receiving_interface=(receiving_interface : Interface | Nil)
Source
resend

Re-sends a previously sent packet. Re-packs to obtain new ciphertext for encrypted destinations.

Source
rssi
Source
rssi=(rssi : Float64 | Nil)
Source
send

Sends the packet via Transport, packing it first if needed. Returns the PacketReceipt on success, or nil if no interface could process the packet.

Source
sent
Source
sent=(sent : Bool)
Source
sent_at
Source
sent_at=(sent_at : Float64 | Nil)
Source
snr=(snr : Float64 | Nil)
Source
transport_id
Source
transport_id=(transport_id : Bytes | Nil)
Source
transport_type
Source
transport_type=(transport_type : UInt8)
Source
unpack

Deserializes a raw byte packet from @raw, extracting flags, header fields, destination hash, and payload data. Returns true on success, false if the packet is malformed.

Source
update_hash
Source