mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-22 23:10:38 +00:00
Cherry-pick 6 upstream transport and allocator fixes (attermann PRs #32-36, constexpr)
- Fix MTU clamp to zero when previous-hop interface has no HW_MTU (PR #32) - Send immediate PATH_RESPONSE for local client path requests (PR #33) - Fix LinkEntry copy-vs-reference: active links were culled after 15 min (PR #34) - Defer packet hashlist insertion for link-table and LRPROOF packets (PR #35) - Fix memory leaks in _pending_local_path_requests and _path_requests (PR #36) - Add constexpr to pool_info constructor to prevent zero-size init race Note: GPS time display needs further investigation — not showing on device after flash, likely unrelated to these changes (fresh NVS has no stored epoch).
This commit is contained in:
1 parent
dd7c749ea3
commit
c877730b91
3 files changed
+70
-7
No files matched your search
+68
-5
@@ -625,6 +625,22 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
ERRORF("jobs: failed to cull discovery path requests: %s", e.what());
|
||||
}
|
||||
|
||||
// Cull the path requests table
|
||||
try {
|
||||
std::vector<Bytes> stale_path_requests;
|
||||
for (const auto& [destination_hash, timestamp] : _path_requests) {
|
||||
if (OS::time() > (timestamp + DESTINATION_TIMEOUT)) {
|
||||
stale_path_requests.push_back(destination_hash);
|
||||
}
|
||||
}
|
||||
for (const Bytes& destination_hash : stale_path_requests) {
|
||||
_path_requests.erase(destination_hash);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
ERRORF("jobs: failed to cull path requests: %s", e.what());
|
||||
}
|
||||
|
||||
// Cull the tunnel table
|
||||
try {
|
||||
count = 0;
|
||||
@@ -1360,8 +1376,25 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
}
|
||||
if (accept) {
|
||||
TRACE("Transport::inbound: Packet accepted by filter");
|
||||
// CBA ACCUMULATES
|
||||
_packet_hashlist.insert(packet.packet_hash());
|
||||
|
||||
// Defer hashlist insertion for packets belonging to links in
|
||||
// our link table, and for LRPROOF packets. On shared-medium
|
||||
// interfaces (e.g. LoRa), a packet may arrive on the "wrong"
|
||||
// interface first. Premature hash insertion would cause the
|
||||
// correct arrival to be filtered as a duplicate.
|
||||
// Reference: Python Transport.py lines 1362-1373
|
||||
bool remember_packet_hash = true;
|
||||
if (_link_table.find(packet.destination_hash()) != _link_table.end()) {
|
||||
remember_packet_hash = false;
|
||||
}
|
||||
if (packet.packet_type() == Type::Packet::PROOF && packet.context() == Type::Packet::LRPROOF) {
|
||||
remember_packet_hash = false;
|
||||
}
|
||||
if (remember_packet_hash) {
|
||||
// CBA ACCUMULATES
|
||||
_packet_hashlist.insert(packet.packet_hash());
|
||||
}
|
||||
|
||||
cache_packet(packet);
|
||||
|
||||
// Check special conditions for local clients connected
|
||||
@@ -1385,7 +1418,7 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
}
|
||||
auto link_iter = _link_table.find(packet.destination_hash());
|
||||
if (link_iter != _link_table.end()) {
|
||||
LinkEntry link_entry = (*link_iter).second;
|
||||
LinkEntry& link_entry = (*link_iter).second;
|
||||
if (_local_client_interfaces.find(link_entry._receiving_interface) != _local_client_interfaces.end()) {
|
||||
// Destined for a local link
|
||||
for_local_client_link = true;
|
||||
@@ -1545,7 +1578,7 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
else {
|
||||
if (nh_mtu < path_mtu || (ph_mtu != 0 && ph_mtu < path_mtu)) {
|
||||
try {
|
||||
path_mtu = std::min(nh_mtu, ph_mtu);
|
||||
path_mtu = std::min(nh_mtu, (ph_mtu > 0) ? ph_mtu : nh_mtu);
|
||||
Bytes clamped_mtu = Link::signalling_bytes(path_mtu, mode);
|
||||
DEBUGF("Clamping link MTU to %u", path_mtu);
|
||||
new_raw = new_raw.left(new_raw.size()-Type::Link::LINK_MTU_SIZE)+clamped_mtu;
|
||||
@@ -1607,7 +1640,7 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
auto link_iter = _link_table.find(packet.destination_hash());
|
||||
if (link_iter != _link_table.end()) {
|
||||
TRACE("Transport::inbound: Found link entry, handling link transport");
|
||||
LinkEntry link_entry = (*link_iter).second;
|
||||
LinkEntry& link_entry = (*link_iter).second;
|
||||
// If receiving and outbound interface is
|
||||
// the same for this link, direction doesn't
|
||||
// matter, and we simply send the packet on.
|
||||
@@ -1653,6 +1686,8 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
new_raw << packet.raw().mid(2);
|
||||
transmit(outbound_interface, new_raw);
|
||||
link_entry._timestamp = OS::time();
|
||||
// Deferred hashlist insertion for link transport packets
|
||||
_packet_hashlist.insert(packet.packet_hash());
|
||||
}
|
||||
else {
|
||||
//p pass
|
||||
@@ -1922,6 +1957,7 @@ Transport::DestinationEntry empty_destination_entry;
|
||||
if (iter != _pending_local_path_requests.end()) {
|
||||
//p desiring_interface = Transport.pending_local_path_requests.pop(packet.destination_hash)
|
||||
//const Interface& desiring_interface = (*iter).second;
|
||||
_pending_local_path_requests.erase(iter);
|
||||
retransmit_timeout = now;
|
||||
retries = PATHFINDER_R;
|
||||
|
||||
@@ -3184,6 +3220,33 @@ TRACEF("announce_packet str: %s", announce_packet.toString().c_str());
|
||||
_announce_table.insert({announce_packet.destination_hash(), announce_entry});
|
||||
// CBA IMMEDIATE CULL
|
||||
cull_announce_table();
|
||||
|
||||
// Send PATH_RESPONSE immediately for local client requests
|
||||
// rather than waiting for the jobs() loop. On resource-
|
||||
// constrained platforms (e.g. ESP32), continuous TCP backbone
|
||||
// data can starve the cooperative jobs() loop for many
|
||||
// seconds, causing path discovery timeouts for local clients.
|
||||
if (is_from_local_client) {
|
||||
Identity imm_identity(Identity::recall(announce_packet.destination_hash()));
|
||||
if (imm_identity) {
|
||||
Destination imm_destination(imm_identity, Type::Destination::OUT, Type::Destination::SINGLE, announce_packet.destination_hash());
|
||||
Packet imm_packet(
|
||||
imm_destination,
|
||||
attached_interface,
|
||||
announce_packet.data(),
|
||||
Type::Packet::ANNOUNCE,
|
||||
Type::Packet::PATH_RESPONSE,
|
||||
Type::Transport::TRANSPORT,
|
||||
Type::Packet::HEADER_2,
|
||||
_identity.hash(),
|
||||
true,
|
||||
announce_packet.context_flag()
|
||||
);
|
||||
imm_packet.hops(announce_hops);
|
||||
imm_packet.send();
|
||||
_announce_table.erase(announce_packet.destination_hash());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // else (announce_packet valid)
|
||||
|
||||
@@ -81,7 +81,7 @@ using namespace RNS::Utilities;
|
||||
}
|
||||
#elif defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_NRF52_ADAFRUIT)
|
||||
heap_pool_info.contiguous_size = dbgHeapFree();
|
||||
altheap_pool_info.buffer_size = dbgHeapFree();
|
||||
altheap_pool_info.contiguous_size = dbgHeapFree();
|
||||
TRACEF("TLSF: contiguous_size: %u", pool_info.contiguous_size);
|
||||
if (pool_info.buffer_size == 0) {
|
||||
pool_info.buffer_size = (size_t)(pool_info.contiguous_size * BUFFER_FRACTION);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace RNS { namespace Utilities {
|
||||
private:
|
||||
|
||||
struct pool_info {
|
||||
pool_info(uint8_t t, size_t s) : type(t), buffer_size(s) {}
|
||||
constexpr pool_info(uint8_t t, size_t s) : type(t), buffer_size(s) {}
|
||||
uint8_t type = 0;
|
||||
bool pool_init = false;
|
||||
size_t buffer_size = 0;
|
||||
|
||||
Reference in new issue
Block a user