module

RNS::Transport

The routing and packet delivery engine for Reticulum. Transport manages the full lifecycle of packets: outbound routing via path and link tables, inbound processing (validation, announce handling, link requests, data delivery, and proof forwarding), and periodic maintenance of routing state. All state is held at the module level and accessed through class methods.

Constants

ANNOUNCES_CHECK_INTERVAL = 1.0
AP_PATH_TIME = (60 * 60) * 24
APP_NAME = "rnstransport"

─── App name ──────────────────────────────────────────────────

BLACKHOLE_CHECK_INTERVAL = 60
BROADCAST = 0_u8

Transport type constants: identify how a packet traverses the network. BROADCAST is a direct, one-hop delivery; TRANSPORT uses multi-hop routing; RELAY and TUNNEL provide indirect forwarding paths.

CACHE_CLEAN_INTERVAL = 5 * 60
DESTINATION_TIMEOUT = ((60 * 60) * 24) * 7
HASHLIST_MAXSIZE = 1000000
IDX_AT_ATTCHD_IF = 8
IDX_AT_BLCK_RBRD = 7
IDX_AT_HOPS = 4
IDX_AT_LCL_RBRD = 6
IDX_AT_PACKET = 5
IDX_AT_RCVD_IF = 3
IDX_AT_RETRIES = 2
IDX_AT_RTRNS_TMO = 1
IDX_AT_TIMESTAMP = 0

─── Announce table entry indices ──────────────────────────────

IDX_LT_DSTHASH = 6
IDX_LT_HOPS = 5
IDX_LT_NH_IF = 2
IDX_LT_NH_TRID = 1
IDX_LT_PROOF_TMO = 8
IDX_LT_RCVD_IF = 4
IDX_LT_REM_HOPS = 3
IDX_LT_TIMESTAMP = 0

─── Link table entry indices ──────────────────────────────────

IDX_LT_VALIDATED = 7
IDX_PT_EXPIRES = 3
IDX_PT_HOPS = 2
IDX_PT_NEXT_HOP = 1
IDX_PT_PACKET = 6
IDX_PT_RANDBLOBS = 4
IDX_PT_RVCD_IF = 5
IDX_PT_TIMESTAMP = 0

Path table entry indices: positional offsets used when interoperating with the Python-format path table arrays.

IDX_RT_OUTB_IF = 1
IDX_RT_RCVD_IF = 0

─── Reverse table entry indices ───────────────────────────────

IDX_RT_TIMESTAMP = 2
IDX_TT_EXPIRES = 3
IDX_TT_IF = 1
IDX_TT_PATHS = 2
IDX_TT_TUNNEL_ID = 0

─── Tunnel table entry indices ────────────────────────────────

INBOUND_DISPATCH = ->(data : Bytes, iface : Interface) do Transport.inbound(data, iface) end
INTERFACE_JOBS_INTERVAL = 5.0
JOB_INTERVAL = 0.250

Job interval constants: how often each periodic maintenance task runs.

LINK_TIMEOUT = (LinkLike::STALE_TIME * 1.25)

Link timeout derived from Link stale time

LINKS_CHECK_INTERVAL = 1.0
LOCAL_CLIENT_CACHE_MAXSIZE = 512
LOCAL_REBROADCASTS_MAX = 2
MAX_PR_TAGS = 32000
MAX_RANDOM_BLOBS = 64
MAX_RATE_TIMESTAMPS = 16
MAX_RECEIPTS = 1024
MGMT_ANNOUNCE_INTERVAL = (2 * 60) * 60
PATH_REQUEST_GRACE = 0.4
PATH_REQUEST_MI = 20
PATH_REQUEST_RG = 1.5
PATH_REQUEST_TIMEOUT = 15

Path request constants: control timing and rate-limiting for on-demand path discovery requests.

PATHFINDER_E = ((60 * 60) * 24) * 7
PATHFINDER_G = 5
PATHFINDER_M = 128

Pathfinder constants: govern path discovery and announce propagation limits, including maximum hop count, retry policy, and path expiry.

PATHFINDER_R = 1
PATHFINDER_RW = 0.5
PENDING_PRS_CHECK_INTERVAL = 30.0
PERSIST_RANDOM_BLOBS = 32
REACHABILITY_DIRECT = 1_u8
REACHABILITY_TRANSPORT = 2_u8
REACHABILITY_UNREACHABLE = 0_u8

Reachability constants: describe how a destination can be reached. DIRECT means the destination is on a locally attached interface; TRANSPORT means it is reachable via multi-hop routing.

RECEIPTS_CHECK_INTERVAL = 1.0
RELAY = 2_u8
REVERSE_TIMEOUT = 8 * 60

Timeout and capacity limits for routing table entries, receipts, and in-memory caches. LINK_TIMEOUT is set after Link is defined; use class method for now

ROAMING_PATH_TIME = (60 * 60) * 6
STATE_RESPONSIVE = 2_u8
STATE_UNKNOWN = 0_u8

Path state constants: track responsiveness of known destinations.

STATE_UNRESPONSIVE = 1_u8
TABLES_CULL_INTERVAL = 5.0
TRANSPORT = 1_u8
TUNNEL = 3_u8
TYPES = [BROADCAST, TRANSPORT, RELAY, TUNNEL]

Class methods

add_packet_hash(packet_hash : Bytes)

Adds a packet hash to the deduplication hashlist.

Source
add_remote_management_allowed(hash : Bytes)
Source
announce_emitted(packet : Packet) : Int64

Extracts the announce emission timebase from a packet's data.

Source
announce_handlers
Source
announce_rate_table
Source
announce_table
Source
blackhole_identity(identity_hash : Bytes, until_time : Float64 | Nil = nil, reason : String | Nil = nil) : Bool | Nil

Blackhole an identity so that its announces and packets are dropped. Returns true on success, nil if already blackholed, false on error. Matches Python Transport.blackhole_identity().

Source
blackhole_last_checked
Source
blackhole_last_checked=(value : Float64)
Source
blackholed_identities
Source
cache(packet : Packet, force_cache : Bool = false, packet_type : String | Nil = nil)

Caches a packet to storage. Packets are stored exactly as they arrived over their interface (hop count not yet incremented). When force_cache is false, should_cache() is consulted.

Source
cache_packet(packet : Packet, cache_path : String, force_cache : Bool = false, packet_type : String | Nil = nil)

Caches a packet to storage.

Source
cache_request(packet_hash : Bytes, destination : Destination::DestinationInterface)

Requests a cached packet either from local cache or from the network.

Source
cache_request_packet(packet : Packet) : Bool

Handles a cache request packet. Retrieves the requested packet from the local cache and replays it to Transport.

Source
check_announce_rate(dest_hex : String, now : Float64) : Bool

Checks announce rate limiting for a destination. Returns true if the announce should be rate-blocked.

Source
clean_announce_cache(cache_path : String)

Cleans the announce file cache. Removes cached announce files that are no longer referenced by the path table or tunnel table.

Source
clean_cache

Cleans the packet cache by removing stale announce files.

Source
clear_destinations

Alias for backward compat with existing specs

Source
control_destinations
Source
control_hashes
Source
deregister_announce_handler(handler : AnnounceHandler)
Source
deregister_destination(destination : Destination)

Removes a previously registered destination from Transport.

Source
deregister_interface(interface_hash : Bytes)

Hash-only overload for backward compatibility.

Source
deregister_interface(interface : Interface)

Deregister an interface.

Source
destinations
Source
detach_interfaces

Detach all registered interfaces

Source
discovery_path_requests
Source
discovery_pr_tags
Source
drop_announce_queues

Drops all announce queues on all interfaces. Currently a no-op since interface objects are not yet implemented.

Source
exit_handler

Exit handler: persists all transport state to disk. Should be called before shutdown.

Source
expire_path(destination_hash : Bytes) : Bool

Expires the path to the specified destination by setting its timestamp to 0, which will cause it to be culled on the next jobs pass. Returns true if a path existed, false otherwise.

Source
find_interface_from_hash(interface_hash : Bytes) : Bytes | Nil

Utility to find an interface hash in the interfaces list.

Source
first_hop_timeout(destination_hash : Bytes) : Float64

Returns the first hop timeout for the specified destination. Without interface bitrate info (not yet available), returns DEFAULT_PER_HOP_TIMEOUT.

Source
from_local_client?(packet : Packet) : Bool

Checks if a packet is from a local client.

Source
get_cached_packet(packet_hash : Bytes, packet_type : String | Nil = nil) : Packet | Nil

Retrieves a cached packet from storage. Returns the packet if found, nil otherwise.

Source
handle_tunnel(tunnel_id : Bytes, interface_hash : Bytes | Nil)

Handles a tunnel establishment or restoration. For new tunnels, creates an entry in the tunnels table. For existing tunnels, restores paths and updates the interface.

Source
has_path(destination_hash : Bytes) : Bool

Returns true if a path to the destination is known.

Source
held_announces
Source
hops_to(destination_hash : Bytes) : Int32

Returns the number of hops to the specified destination, or PATHFINDER_M if the number of hops is unknown.

Source
identity
Source
identity=(value : Identity | Nil)
Source
inbound(raw : Bytes, interface_hash : Bytes)

Processes a raw inbound packet received from a network interface. Validates IFAC flags, unpacks the packet, checks for duplicates, and dispatches to the appropriate handler: announce processing, link request/proof handling, data delivery to local destinations, or multi-hop forwarding via the path and link tables. Backward-compatible overload accepting an interface hash (for tests and call sites that don't have the interface object).

Source
inbound(raw : Bytes, interface : Interface | Nil = nil, _interface_hash_override : Bytes | Nil = nil)
Source
inbound_announce(packet : Packet) : Bool

Processes an inbound announce packet. This is the core of the announce handling logic from RNS/Transport.py's inbound() method.

Returns true if the announce was valid and processed, false otherwise.

Source
inbound_announce_lock
Source
interface_objects
Source
interfaces
Source
invoke_announce_handlers(packet : Packet, destination_hash : Bytes)

Invokes registered announce handler callbacks for a processed announce.

Source
is_connected_to_shared_instance=(value : Bool)
Source
is_connected_to_shared_instance?
Source
is_local_client_interface?(interface_hash : Bytes | Nil) : Bool

Checks if an interface hash corresponds to a local client interface.

Source
is_local_client_interface?(interface : Interface | Nil) : Bool

Checks if an interface object corresponds to a local client interface.

Source
job_loop_running?
Source
jobs

Runs all periodic maintenance tasks.

Source
jobs_locked
Source
jobs_locked=(value : Bool)
Source
jobs_running
Source
jobs_running=(value : Bool)
Source
load_packet_hashlist(storage_path : String) : Int32

Loads the packet hashlist from disk.

Source
load_path_table(storage_path : String) : Int32

Loads the path table from disk. Returns the number of entries loaded, or -1 on error.

Source
load_tunnel_table(storage_path : String) : Int32

Loads the tunnel table from disk. Returns the number of tunnel entries loaded, or -1 on error.

Source
local_client_interfaces
Source
mark_path_responsive(destination_hash : Bytes) : Bool

Marks the path to the specified destination as responsive.

Source
mark_path_unknown_for_destination(destination_hash : Bytes)

Marks the path for a destination as unknown, used when the announce table entry should be reconsidered.

Source
mark_path_unknown_state(destination_hash : Bytes) : Bool

Marks the path to the specified destination as unknown state.

Source
mark_path_unresponsive(destination_hash : Bytes) : Bool

Marks the path to the specified destination as unresponsive.

Source
next_hop(destination_hash : Bytes) : Bytes | Nil

Returns the next hop hash for the specified destination, or nil if unknown.

Source
next_hop_interface(destination_hash : Bytes) : Bytes | Nil

Returns the receiving interface hash for the specified destination, or nil if unknown.

Source
outbound(packet : Packet) : Bool

Routes an outbound packet for delivery. Consults the path table, link table, and tunnel table to determine the correct next-hop interface. Handles broadcast, transport, and direct destination types. Returns true if the packet was successfully sent.

Source
owner
Source
owner=(value : OwnerRef | Nil)
Source
packet_filter(packet : Packet) : Bool

Filters packets for deduplication and validity. Returns true if the packet should be processed.

Source
packet_hash_in_list?(packet_hash : Bytes) : Bool

Checks if a packet hash is in the deduplication hashlist.

Source
packet_hashlist
Source
packet_hashlist_prev
Source
path_is_unresponsive(destination_hash : Bytes) : Bool

Returns true if the path to the specified destination is marked as unresponsive.

Source
path_requests
Source
path_states
Source
path_table
Source
pending_local_path_requests
Source
persist_data(storage_path : String)

Calls all persistence methods.

Source
process_announce_table

Processes the announce retransmission table. Called periodically by the Transport jobs loop. Returns an array of packets to send.

Source
receipts
Source
register_announce_handler(handler : AnnounceHandler)
Source
register_destination(destination : Destination)

Registers a destination with Transport so it can receive packets. Sets the destination's MTU and ensures no duplicate inbound destinations are registered (raises KeyError on conflict).

Source
register_interface(interface_hash : Bytes)

Hash-only overload for backward compatibility (used by some specs).

Source
register_interface(interface : Interface)

Register an interface. Stores both the hash (for broadcast iteration) and the object (for transmit resolution and inbound dispatch).

Source
remote_management_allowed
Source
remove_path(destination_hash : Bytes) : Bool

Removes a path table entry for the given destination hash. Returns true if the entry existed, false otherwise.

Source
request_path(destination_hash : Bytes, on_interface : Bytes | Nil = nil, tag : Bytes | Nil = nil, recursive : Bool = false)

Requests a path to the destination from the network. Creates a path request packet and broadcasts it.

Source
reset
Source
reverse_table
Source
save_packet_hashlist(storage_path : String) : Bool

Saves the packet hashlist to disk using MessagePack.

Source
save_path_table(storage_path : String) : Bool

Saves the path table to disk using MessagePack serialization. Each entry is serialized as: [destination_hash, timestamp, received_from, hops, expires, random_blobs, interface_hash, packet_hash]

Source
save_tunnel_table(storage_path : String) : Bool

Saves the tunnel table to disk using MessagePack.

Source
shared_connection_disappeared

Called when a shared instance connection is lost. Notifies relevant subsystems to handle the disconnection.

Source
shared_connection_reappeared

Called when a shared instance connection is re-established. Notifies relevant subsystems to handle the reconnection.

Source
should_cache(packet : Packet) : Bool

Determines whether a packet should be cached. Currently returns false — the Python implementation has this disabled with a TODO to rework the caching system.

Source
speed_rx
Source
speed_tx
Source
start(owner_ref : OwnerRef)

Initializes and starts the Transport layer. Creates or loads the transport identity, loads persisted state (packet hashlist, path table, tunnel table), sets up control destinations, and starts the periodic job fiber.

Source
start_job_loop

Starts the periodic job loop fiber.

Source
start_time
Source
stop_job_loop

Stops the periodic job loop fiber.

Source
synthesize_tunnel_data(interface_hash : Bytes) : Tuple(Bytes, Bytes) | Nil

Creates and returns a tunnel synthesis packet data payload. Returns {tunnel_id, data} or nil if no identity is set.

Source
tables_last_culled
Source
tables_last_culled=(value : Float64)
Source
timebase_from_random_blob(random_blob : Bytes) : Int64

Extracts a timebase value from a random blob (bytes 5..9). The random blob is 10 bytes; bytes 5..9 encode an emission timestamp.

Source
timebase_from_random_blobs(random_blobs : Array(Bytes)) : Int64

Extracts the maximum timebase from an array of random blobs.

Source
traffic_rxb
Source
traffic_txb
Source
transmit(interface_hash : Bytes, raw : Bytes)

Transmits raw data on an interface (identified by hash). Resolves the interface object from @@interface_objects, applies IFAC masking if the interface has IFAC enabled, and calls process_outgoing.

Source
transmit_log
Source
transport_enabled=(value : Bool)
Source
transport_enabled?
Source
tunnel_synthesize_handler(data : Bytes, packet : Packet)

Validates and processes a tunnel synthesis request. Called when a tunnel synthesis DATA packet is received. data format: public_key + interface_hash + random_hash + signature

Source
tunnels
Source
unblackhole_identity(identity_hash : Bytes) : Bool | Nil

Remove an identity from the blackhole list. Returns true on success, nil if not blackholed, false on error. Matches Python Transport.unblackhole_identity().

Source
update_path(destination_hash : Bytes, next_hop : Bytes, hops : Int32, expires : Float64, receiving_interface : Bytes | Nil = nil, packet_hash : Bytes = Bytes.empty, random_blobs : Array(Bytes) = [] of Bytes)

Inserts or updates a path table entry for the given destination hash.

Source
void_tunnel_interface(tunnel_id : Bytes)

Voids the interface reference for a tunnel, keeping paths intact.

Source

Nested types