class

RNS::Link

Inherits RNS::Destination::DestinationInterface < RNS::LinkLike < Reference < Object

Encrypted bidirectional communication channel between two Reticulum destinations, established via ECDH key exchange over X25519 with Ed25519 signing.

Constants

ACCEPT_ALL = 2_u8
ACCEPT_APP = 1_u8
ACCEPT_NONE = 0_u8

Policies controlling whether incoming resource transfers are accepted. ─── Resource strategies ─────────────────────────────────────────

ACTIVE = 2_u8
CLOSED = 4_u8
CURVE = Identity::CURVE

Curve type and key sizes for ECDH key exchange and signing. ─── Curve and key size constants ────────────────────────────────

DESTINATION_CLOSED = 3_u8
ECPUBSIZE = 32 + 32
ENABLED_MODES = [MODE_AES256_CBC]
ESTABLISHMENT_TIMEOUT_PER_HOP = Reticulum::DEFAULT_PER_HOP_TIMEOUT.to_f64

Timeout, keepalive, and watchdog timing parameters for link lifecycle management. ─── Timing constants ────────────────────────────────────────────

HANDSHAKE = 1_u8
INITIATOR_CLOSED = 2_u8
KEEPALIVE = KEEPALIVE_MAX
KEEPALIVE_MAX = 360.0
KEEPALIVE_MAX_RTT = 1.75
KEEPALIVE_MIN = 5.0
KEEPALIVE_TIMEOUT_FACTOR = 4
KEYSIZE = 32
LINK_MTU_SIZE = 3
MDU = (((((Reticulum::MTU - Reticulum::IFAC_MIN_SIZE) - Reticulum::HEADER_MINSIZE) - Identity::TOKEN_OVERHEAD) // Identity::AES128_BLOCKSIZE) * Identity::AES128_BLOCKSIZE) - 1

Maximum Data Unit: largest plaintext payload that fits in an encrypted link packet. ─── MDU ─────────────────────────────────────────────────────────

MODE_AES128_CBC = 0_u8

Symmetric encryption modes negotiated during link establishment. ─── Encryption modes ────────────────────────────────────────────

MODE_AES256_CBC = 1_u8
MODE_AES256_GCM = 2_u8
MODE_BYTEMASK = 224_u8
MODE_DEFAULT = MODE_AES256_CBC
MODE_DESCRIPTIONS = {MODE_AES128_CBC => "AES_128_CBC", MODE_AES256_CBC => "AES_256_CBC", MODE_AES256_GCM => "MODE_AES256_GCM", MODE_OTP_RESERVED => "MODE_OTP_RESERVED", MODE_PQ_RESERVED_1 => "MODE_PQ_RESERVED_1", MODE_PQ_RESERVED_2 => "MODE_PQ_RESERVED_2", MODE_PQ_RESERVED_3 => "MODE_PQ_RESERVED_3", MODE_PQ_RESERVED_4 => "MODE_PQ_RESERVED_4"}
MODE_OTP_RESERVED = 3_u8
MODE_PQ_RESERVED_1 = 4_u8
MODE_PQ_RESERVED_2 = 5_u8
MODE_PQ_RESERVED_3 = 6_u8
MODE_PQ_RESERVED_4 = 7_u8
MTU_BYTEMASK = 2097151_u32

Bitmasks for encoding MTU and encryption mode into signalling bytes. ─── Byte masks for MTU signalling ───────────────────────────────

PENDING = 0_u8

Link lifecycle states: PENDING -> HANDSHAKE -> ACTIVE -> STALE -> CLOSED. ─── Link states ─────────────────────────────────────────────────

RESOURCE_STRATEGIES = [ACCEPT_NONE, ACCEPT_APP, ACCEPT_ALL]
RESPONSE_MAX_GRACE_TIME = 10.0
STALE = 3_u8
STALE_FACTOR = 2
STALE_GRACE = 5.0
STALE_TIME = STALE_FACTOR * KEEPALIVE
TIMEOUT = 1_u8

Reason codes recorded when a link is torn down. ─── Teardown reasons ────────────────────────────────────────────

TRAFFIC_TIMEOUT_FACTOR = 6
TRAFFIC_TIMEOUT_MIN_MS = 5
WATCHDOG_MAX_SLEEP = 5.0

Constructors

Class methods

mode_from_lp_packet(packet : Packet) : UInt8
Source
mode_from_lr_packet(packet : Packet) : UInt8
Source
mtu_from_lp_packet(packet : Packet) : Int32 | Nil
Source
mtu_from_lr_packet(packet : Packet) : Int32 | Nil
Source
signalling_bytes(mtu : UInt32, mode : UInt8) : Bytes
Source

Instance methods

activated_at
Source
activated_at=(activated_at : Float64 | Nil)
Source
attached_interface
Source
attached_interface=(attached_interface : Interface | Nil)
Source
callbacks
Source
callbacks=(callbacks : LinkCallbacks)
Source
cancel_incoming_resource(resource_hash : Bytes)
Source
cancel_outgoing_resource(resource_hash : Bytes)
Source
decrypt_data(ciphertext : Bytes) : Bytes | Nil

Decrypts ciphertext using the link's derived symmetric key. Returns nil on failure.

Source
derived_key

Test accessors for internal state verification

Source
destination
Source
destination_hash
Source
do_handshake

Performs ECDH key exchange and derives symmetric encryption keys via HKDF.

Source
encrypt(plaintext : Bytes) : Bytes
Source
encrypt_data(plaintext : Bytes) : Bytes

Encrypts plaintext using the link's derived symmetric key via the Token cipher.

Source
establishment_cost
Source
establishment_cost=(establishment_cost : Int32)
Source
establishment_rate
Source
establishment_rate=(establishment_rate : Float64 | Nil)
Source
establishment_timeout=(value : Float64)
Source
expected_hops
Source
expected_rate
Source
expected_rate=(expected_rate : Float64 | Nil)
Source
get_age
Source
get_channel
Source
get_context
Source
get_establishment_rate
Source
get_expected_rate
Source
get_last_resource_eifr
Source
get_last_resource_window
Source
get_mdu
Source
get_mode
Source
get_mtu
Source
get_q
Source
get_remote_identity
Source
get_rssi
Source
get_salt
Source
get_snr
Source
had_outbound(is_keepalive : Bool = false)
Source
handle_request(request_id : Bytes, unpacked_request : Array(MessagePack::Any))
Source
handle_response(request_id : Bytes, response_data : MessagePack::Any)
Source
has_incoming_resource?(resource_hash : Bytes) : Bool
Source
hash

Generates an UInt64 hash value for this object.

This method must have the property that a == b implies a.hash == b.hash.

The hash value is used along with == by the Hash class to determine if two objects reference the same hash key.

Subclasses must not override this method. Instead, they must define hash(hasher), though usually the macro def_hash can be used to generate this method.

Source
identify(identity : Identity)

Reveals the initiator's identity to the responder by sending a signed identity proof.

Source
inactive_for
Source
incoming_resources
Source
incoming_resources=(incoming_resources : Array(Resource))
Source
initiator?

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

Source
keepalive
Source
keepalive=(keepalive : Float64)
Source
keepalive_timeout_factor
Source
keepalive_timeout_factor=(keepalive_timeout_factor : Int32)
Source
last_data
Source
last_data=(last_data : Float64)
Source
last_inbound
Source
last_inbound=(last_inbound : Float64)
Source
last_keepalive
Source
last_keepalive=(last_keepalive : Float64)
Source
last_outbound
Source
last_outbound=(last_outbound : Float64)
Source
last_proof
Source
last_proof=(last_proof : Float64)
Source
last_resource_eifr
Source
last_resource_eifr=(last_resource_eifr : Float64 | Nil)
Source
last_resource_window
Source
last_resource_window=(last_resource_window : Int32 | Nil)
Source
load_peer(peer_pub_bytes : Bytes, peer_sig_pub_bytes : Bytes)

Loads the remote peer's X25519 and Ed25519 public keys from raw bytes.

Source
mdu=(mdu : Int32)
Source
mode
Source
mode=(mode : UInt8)
Source
mtu=(mtu : Int32)
Source
no_data_for
Source
no_inbound_for
Source
no_outbound_for
Source
outgoing_resources
Source
outgoing_resources=(outgoing_resources : Array(Resource))
Source
pending_requests
Source
pending_requests=(pending_requests : Array(RequestReceipt))
Source
prove

Constructs and sends a signed link proof packet from the responder to the initiator.

Source
prove_packet(packet : Packet)
Source
prv_key
Source
pub_bytes
Source
pub_key
Source
q=(q : Float64 | Nil)
Source
ready_for_new_resource?
Source
receive(packet : Packet)

Processes an incoming packet on this link, dispatching by context (data, identify, request, keepalive, etc.).

Source
register_incoming_resource(resource : Resource)
Source
register_outgoing_resource(resource : Resource)
Source
request(path : String, data : Bytes | Nil = nil, response_callback : Proc(RequestReceipt, Nil) | Nil = nil, failed_callback : Proc(RequestReceipt, Nil) | Nil = nil, progress_callback : Proc(RequestReceipt, Nil) | Nil = nil, timeout : Float64 | Nil = nil) : RequestReceipt | Nil

Sends a request to the remote destination on path and returns a RequestReceipt to track the response.

Source
request_resource_concluded(resource : Resource)

Called when an incoming request resource transfer concludes. Unpacks the request data and dispatches it to handle_request.

Source
request_time
Source
request_time=(request_time : Float64 | Nil)
Source
resource_concluded(resource : Resource, resource_size : Int64, started_transferring : Float64, window : Int32 | Nil = nil, eifr : Float64 | Nil = nil, incoming : Bool = true)
Source
resource_strategy
Source
resource_strategy=(resource_strategy : UInt8)
Source
response_resource_concluded(resource : Resource)

Called when an outgoing response resource transfer concludes.

Source
rssi
Source
rssi=(rssi : Float64 | Nil)
Source
rtt=(rtt : Float64 | Nil)
Source
rtt_packet(packet : Packet)

Handles an RTT measurement packet on the responder side, activating the link.

Source
rx=(rx : Int64)
Source
rxbytes
Source
rxbytes=(rxbytes : Int64)
Source
send(data : Bytes, packet_type : UInt8 = Packet::DATA, context : UInt8 = Packet::NONE) : Packet | Nil

Sends data over the link as an encrypted packet. Returns nil if the link is closed or if no interface could process the packet.

Source
send_keepalive
Source
set_destination(dest : Destination | Nil)
Source
set_initiator(value : Bool)
Source
set_packet_callback(callback : Proc(Bytes, Packet, Nil))
Source
set_resource_callback(callback : Proc(ResourceAdvertisement, Bool))
Source
set_resource_concluded_callback(callback : Proc(Resource, Nil))
Source
set_resource_started_callback(callback : Proc(Resource, Nil))
Source
set_resource_strategy(strategy : UInt8)
Source
shared_key
Source
sign(message : Bytes) : Bytes

Signs a message using this link's Ed25519 private key.

Source
snr=(snr : Float64 | Nil)
Source
stale_time
Source
stale_time=(stale_time : Float64)
Source
start_watchdog
Source
status
Source
status=(value : UInt8)
Source
teardown

Tears down the link, sending a close packet to the peer and purging keys.

Source
teardown_packet(packet : Packet)
Source
teardown_reason
Source
teardown_reason=(teardown_reason : UInt8 | Nil)
Source
to_s(io : IO)

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
to_s

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.

Source
track_phy_stats(track : Bool)
Source
traffic_timeout_factor
Source
traffic_timeout_factor=(traffic_timeout_factor : Int32)
Source
tx=(tx : Int64)
Source
txbytes
Source
txbytes=(txbytes : Int64)
Source
type
Source
update_keepalive
Source
update_mdu
Source
validate(signature : Bytes, message : Bytes) : Bool

Validates a signature against a message using the peer's Ed25519 public key.

Source
validate_proof(packet : Packet)

Validates a link proof received by the initiator, completing the handshake and activating the link.

Source