Fix sending duplicate packets to PhoneAPI/MQTT (#5315)

* Fix potential duplicate packets to PhoneAPI/MQTT

* Fix include error for STM32

* Fix cppcheck error
This commit is contained in:
GUVWAF
2024-11-12 00:54:05 +01:00
committed by GitHub
parent eb8d38a7e9
commit 40bc04b521
7 changed files with 34 additions and 14 deletions

View File

@@ -16,7 +16,7 @@ PacketHistory::PacketHistory()
/**
* Update recentBroadcasts and return true if we have already seen this packet
*/
bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate)
bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpdate, bool *isRepeated)
{
if (p->id == 0) {
LOG_DEBUG("Ignore message with zero id");
@@ -41,7 +41,12 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd
/* If the original transmitter is doing retransmissions (hopStart equals hopLimit) for a reliable transmission, e.g., when the
ACK got lost, we will handle the packet again to make sure it gets an ACK/response to its packet. */
if (seenRecently && p->hop_start > 0 && p->hop_start == p->hop_limit) {
LOG_DEBUG("Repeated reliable tx");
if (withUpdate)
LOG_DEBUG("Repeated reliable tx");
if (isRepeated)
*isRepeated = true;
seenRecently = false;
}
@@ -54,7 +59,7 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd
recentPackets.erase(found); // as unsorted_set::iterator is const (can't update timestamp - so re-insert..)
}
recentPackets.insert(r);
printPacket("Add packet record", p);
LOG_DEBUG("Add packet record fr=0x%x, id=0x%x", p->from, p->id);
}
// Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity