From 2f7ff01805eabb11aef59c519e4dd79396d46b2d Mon Sep 17 00:00:00 2001 From: James L Date: Sat, 7 Mar 2026 21:53:27 -0500 Subject: [PATCH] fix: defer packet hashlist insertion for link-table and LRPROOF packets The C++ code unconditionally adds every accepted packet's hash to _packet_hashlist immediately, before link transport or proof handling runs. The Python reference implementation (Transport.py lines 1362-1373) defers insertion for two cases: 1. Packets whose destination_hash is in link_table (link data packets) 2. LRPROOF packets (type=PROOF, context=LRPROOF) For link data, the hash is added later, inside the link transport forwarding block, only after a valid outbound direction is confirmed (Transport.py line 1544). For LRPROOF, the hash is never added (allowing duplicate proofs to be processed on multiple interfaces). On shared-medium interfaces (e.g. LoRa), a packet belonging to a link that transports through this node may arrive on the wrong interface first (e.g. received on LoRa before it arrives via TCP backbone). The premature hash insertion causes the correct arrival to be filtered as a duplicate, breaking link transport for non-resource contexts. --- src/Transport.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Transport.cpp b/src/Transport.cpp index 05def93..b75c5ce 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -1332,8 +1332,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 @@ -1625,6 +1642,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