Fix: Traceroute through MQTT misses uplink node if MQTT is encrypted (#9798)

* Attempt to fix issue 9713

* Code formatting issue.

* Remade the fix to follow Copilot observations on PR

* Rebuild after AI and GUVWAF

* Update src/mesh/Router.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/mesh/Router.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* trunk fmt

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
This commit is contained in:
Fernando Nunes
2026-03-16 19:48:29 +00:00
committed by GitHub
parent 53c21eb30d
commit ac7a58cd45

View File

@@ -802,8 +802,32 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
p_encrypted->pki_encrypted = true;
// After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet
if ((decodedState == DecodeState::DECODE_SUCCESS || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled &&
!isFromUs(p) && mqtt)
!isFromUs(p) && mqtt) {
if (decodedState == DecodeState::DECODE_SUCCESS && p->decoded.portnum == meshtastic_PortNum_TRACEROUTE_APP &&
moduleConfig.mqtt.encryption_enabled) {
// For TRACEROUTE_APP packets release the original encrypted packet and encrypt a new from the changed packet
// Only release the original after successful allocation to avoid losing an incomplete but valid packet
auto *p_encrypted_new = packetPool.allocCopy(*p);
if (p_encrypted_new) {
auto encodeResult = perhapsEncode(p_encrypted_new);
if (encodeResult != meshtastic_Routing_Error_NONE) {
// Encryption failed, release the new packet and fall back to sending the original encrypted packet to
// MQTT
LOG_WARN("Encryption of new TR packet failed, sending original TR to MQTT");
packetPool.release(p_encrypted_new);
p_encrypted_new = nullptr;
} else {
// Successfully re-encrypted, release the original encrypted packet and use the new one for MQTT
packetPool.release(p_encrypted);
p_encrypted = p_encrypted_new;
}
} else {
// Allocation failed, log a warning and fall back to sending the original encrypted packet to MQTT
LOG_WARN("Failed to allocate new encrypted packet for TR, sending original TR to MQTT");
}
}
mqtt->onSend(*p_encrypted, *p, p->channel);
}
}
#endif
}