WIP: Progress toward Link support with example app

This commit is contained in:
Chad Attermann committed 2025-08-23 14:12:13 -06:00
1 parent 11155b5829
commit c3edde10e9
44 files changed
+1608 -939

No files matched your search

+56 -49
View File
@@ -221,7 +221,7 @@ using namespace RNS::Utilities;
}
// TODO
/*
/*p
// Synthesize tunnels for any interfaces wanting it
for interface in Transport.interfaces:
interface.tunnel_id = None
@@ -632,7 +632,7 @@ using namespace RNS::Utilities;
//if hasattr(interface, "ifac_identity") and interface.ifac_identity != None:
if (interface.ifac_identity()) {
// TODO
/*
/*p
// Calculate packet access code
ifac = interface.ifac_identity.sign(raw)[-interface.ifac_size:]
@@ -919,7 +919,7 @@ using namespace RNS::Utilities;
if (packet.hops() > 0) {
// TODO
/*
/*p
if not hasattr(interface, "announce_cap"):
interface.announce_cap = RNS.Reticulum.ANNOUNCE_CAP
@@ -949,7 +949,7 @@ using namespace RNS::Utilities;
bool should_queue = true;
for (auto& entry : interface.announce_queue()) {
if (entry._destination == packet.destination_hash()) {
double emission_timestamp = announce_emitted(packet);
uint64_t emission_timestamp = announce_emitted(packet);
should_queue = false;
if (emission_timestamp > entry._emitted) {
entry._time = outbound_time;
@@ -1160,7 +1160,7 @@ using namespace RNS::Utilities;
}
}
// TODO
/*
/*p
// If interface access codes are enabled,
// we must authenticate each packet.
//if len(raw) > 2:
@@ -1254,7 +1254,7 @@ using namespace RNS::Utilities;
packet.hops(packet.hops() + 1);
// TODO
/*
/*p
if (interface) {
if hasattr(interface, "r_stat_rssi"):
if interface.r_stat_rssi != None:
@@ -1651,7 +1651,7 @@ using namespace RNS::Utilities;
// First, check that the announce is not for a destination
// local to this system, and that hops are less than the max
// CBA TODO determine why packet desitnation hash is being searched in destinations again since we entered this logic becuase it did not exist above
// CBA TODO determine why packet destination hash is being searched in destinations again since we entered this logic becuase it did not exist above
//if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
#if defined(DESTINATIONS_SET)
bool found_local = false;
@@ -1666,7 +1666,7 @@ using namespace RNS::Utilities;
auto iter = _destinations.find(packet.destination_hash());
if (iter == _destinations.end() && packet.hops() < (PATHFINDER_M+1)) {
#endif
double announce_emitted = Transport::announce_emitted(packet);
uint64_t announce_emitted = Transport::announce_emitted(packet);
//p random_blob = packet.data[RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8:RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8+10]
Bytes random_blob = packet.data().mid(Type::Identity::KEYSIZE/8 + Type::Identity::NAME_HASH_LENGTH/8, Type::Identity::RANDOM_HASH_LENGTH/8);
@@ -1704,11 +1704,10 @@ using namespace RNS::Utilities;
double now = OS::time();
double path_expires = destination_entry._expires;
double path_announce_emitted = 0;
uint64_t path_announce_emitted = 0;
for (const Bytes& path_random_blob : random_blobs) {
//p path_announce_emitted = max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"))
// CBA TODO
//z path_announce_emitted = std::max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"));
path_announce_emitted = std::max(path_announce_emitted, OS::from_bytes_big_endian(path_random_blob.data() + 5, 5));
if (path_announce_emitted >= announce_emitted) {
break;
}
@@ -1753,7 +1752,7 @@ using namespace RNS::Utilities;
bool rate_blocked = false;
// TODO
/*
/*p
if packet.context != RNS.Packet.PATH_RESPONSE and packet.receiving_interface.announce_rate_target != None:
if not packet.destination_hash in Transport.announce_rate_table:
rate_entry = { "last": now, "rate_violations": 0, "blocked_until": 0, "timestamps": [now]}
@@ -2019,7 +2018,7 @@ using namespace RNS::Utilities;
}
}
if (execute_callback) {
// CBA TODO Why does app data come from recall instead of from this annuonce packet?
// CBA TODO Why does app data come from recall instead of from this announce packet?
handler->received_announce(
packet.destination_hash(),
announce_identity,
@@ -2140,6 +2139,7 @@ using namespace RNS::Utilities;
// This is a link request proof, check if it
// needs to be transported
if ((Reticulum::transport_enabled() || for_local_client_link || from_local_client) && _link_table.find(packet.destination_hash()) != _link_table.end()) {
TRACE("Handling link request proof...");
LinkEntry link_entry = (*_link_table.find(packet.destination_hash())).second;
if (packet.receiving_interface() == link_entry._outbound_interface) {
try {
@@ -2181,10 +2181,15 @@ using namespace RNS::Utilities;
else {
// Check if we can deliver it to a local
// pending link
for (auto& link : _pending_links) {
TRACEF("Handling proof for link request %s", packet.destination_hash().toHex().c_str());
// CBA Must make a copy of _pending_links before traversing since it gets modified
//for (auto link : _pending_links) {
std::set<Link> pending_links(_pending_links);
for (auto& link : pending_links) {
TRACEF("Checking for link request handling by pending link %s", link.link_id().toHex().c_str());
if (link.link_id() == packet.destination_hash()) {
// TODO
//z link.validate_proof(packet);
TRACE("Requesting pending link to validate proof");
const_cast<Link&>(link).validate_proof(packet);
}
}
}
@@ -2193,8 +2198,7 @@ using namespace RNS::Utilities;
TRACE("Transport::inbound: Packet is RESOURCE PROOF");
for (auto& link : _active_links) {
if (link.link_id() == packet.destination_hash()) {
// TODO
//z link.receive(packet);
const_cast<Link&>(link).receive(packet);
}
}
}
@@ -2275,7 +2279,7 @@ using namespace RNS::Utilities;
/*static*/ void Transport::synthesize_tunnel(const Interface& interface) {
// TODO
/*
/*p
Bytes interface_hash = interface.get_hash();
Bytes public_key = _identity.get_public_key();
Bytes random_hash = Identity::get_random_hash();
@@ -2299,7 +2303,7 @@ using namespace RNS::Utilities;
/*static*/ void Transport::tunnel_synthesize_handler(const Bytes& data, const Packet& packet) {
// TODO
/*
/*p
try:
expected_length = RNS.Identity.KEYSIZE//8+RNS.Identity.HASHLENGTH//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8+RNS.Identity.SIGLENGTH//8
if len(data) == expected_length:
@@ -2326,7 +2330,7 @@ using namespace RNS::Utilities;
/*static*/ void Transport::handle_tunnel(const Bytes& tunnel_id, const Interface& interface) {
// TODO
/*
/*p
expires = time.time() + Transport.DESTINATION_TIMEOUT
if not tunnel_id in Transport.tunnels:
RNS.log("Tunnel endpoint "+RNS.prettyhexrep(tunnel_id)+" established.", RNS.LOG_DEBUG)
@@ -2388,7 +2392,7 @@ using namespace RNS::Utilities;
#elif defined(INTERFACES_MAP)
_interfaces.insert({interface.get_hash(), interface});
#endif
// CBA TODO set or add transport as listener on interface to receive incoming packets
// CBA TODO set or add transport as listener on interface to receive incoming packets?
}
/*static*/ void Transport::deregister_interface(const Interface& interface) {
@@ -2489,9 +2493,7 @@ using namespace RNS::Utilities;
#endif
}
/*static*/ void Transport::register_link(const Link& link) {
// TODO
/*
/*static*/ void Transport::register_link(Link& link) {
TRACE("Transport: Registering link " + link.toString());
if (link.initiator()) {
// CBA ACCUMULATES
@@ -2501,16 +2503,13 @@ using namespace RNS::Utilities;
// CBA ACCUMULATES
_active_links.insert(link);
}
*/
}
/*static*/ void Transport::activate_link(Link& link) {
// TODO
/*
TRACE("Transport: Activating link " + link.toString());
if (_pending_links.find(link) != _pending_links.end()) {
if (link.status() != Type::Link::ACTIVE) {
throw std::runtime_error("Invalid link state for link activation: " + link.status_string());
throw std::runtime_error("Invalid link state for link activation: " + std::to_string(link.status()));
}
_pending_links.erase(link);
// CBA ACCUMULATES
@@ -2520,7 +2519,6 @@ using namespace RNS::Utilities;
else {
ERROR("Attempted to activate a link that was not in the pending table");
}
*/
}
/*
@@ -2776,7 +2774,18 @@ Deregisters an announce handler.
return interface.bitrate();
}
else {
0;
return 0;
}
}
/*static*/ uint16_t Transport::next_hop_interface_hw_mtu(const Bytes& destination_hash) {
const Interface& interface = next_hop_interface(destination_hash);
if (interface) {
if (interface.AUTOCONFIGURE_MTU() || interface.FIXED_MTU()) return interface.HW_MTU();
else return 0;
}
else {
return 0;
}
}
@@ -2879,7 +2888,7 @@ will announce it.
///*static*/ void Transport::request_path(const Bytes& destination_hash, const Interface& on_interface /*= {Type::NONE}*/, const Bytes& tag /*= {}*/, bool recursive /*= false*/) {
/*static*/ void Transport::request_path(const Bytes& destination_hash, const Interface& on_interface, const Bytes& tag /*= {}*/, bool recursive /*= false*/) {
Bytes request_tag;
if (tag) {
if (!tag) {
request_tag = Identity::get_random_hash();
}
else {
@@ -2899,7 +2908,7 @@ will announce it.
if (on_interface && recursive) {
// TODO
/*
/*p
if not hasattr(on_interface, "announce_cap"):
on_interface.announce_cap = RNS.Reticulum.ANNOUNCE_CAP
@@ -3247,7 +3256,7 @@ will announce it.
/*static*/ void Transport::detach_interfaces() {
// TODO
/*
/*p
detachable_interfaces = []
for interface in Transport.interfaces:
@@ -3275,7 +3284,7 @@ will announce it.
/*static*/ void Transport::shared_connection_disappeared() {
// TODO
/*
/*p
for link in Transport.active_links:
link.teardown()
@@ -3294,7 +3303,7 @@ will announce it.
/*static*/ void Transport::shared_connection_reappeared() {
// TODO
/*
/*p
if Transport.owner.is_connected_to_shared_instance:
for registered_destination in Transport.destinations:
if registered_destination.type == RNS.Destination.SINGLE:
@@ -3304,7 +3313,7 @@ will announce it.
/*static*/ void Transport::drop_announce_queues() {
// TODO
/*
/*p
for interface in Transport.interfaces:
if hasattr(interface, "announce_queue") and interface.announce_queue != None:
na = len(interface.announce_queue)
@@ -3319,22 +3328,20 @@ will announce it.
*/
}
/*static*/ bool Transport::announce_emitted(const Packet& packet) {
// TODO
/*
random_blob = packet.data[RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8:RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8+10]
announce_emitted = int.from_bytes(random_blob[5:10], "big")
return announce_emitted
*/
// MOCK
return false;
/*static*/ uint64_t Transport::announce_emitted(const Packet& packet) {
//p random_blob = packet.data[RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8:RNS.Identity.KEYSIZE//8+RNS.Identity.NAME_HASH_LENGTH//8+10]
//p announce_emitted = int.from_bytes(random_blob[5:10], "big")
Bytes random_blob = packet.data().mid(RNS::Type::Identity::KEYSIZE/8+RNS::Type::Identity::NAME_HASH_LENGTH/8, 10);
if (random_blob) {
return OS::from_bytes_big_endian(random_blob.data() + 5, 5);
}
return 0;
}
/*static*/ void Transport::write_packet_hashlist() {
#if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS)
// TODO
/*
/*p
if not Transport.owner.is_connected_to_shared_instance:
if hasattr(Transport, "saving_packet_hashlist"):
wait_interval = 0.2
@@ -3713,7 +3720,7 @@ TRACE("Transport::write_path_table: buffer size " + std::to_string(Persistence::
/*static*/ void Transport::write_tunnel_table() {
#if defined(RNS_USE_FS) && defined(RNS_PERSIST_PATHS)
// TODO
/*
/*p
if not Transport.owner.is_connected_to_shared_instance:
if hasattr(Transport, "saving_tunnel_table"):
wait_interval = 0.2