From 8b8fffda81ef1dc1211955c9d0ff66225ef8abb9 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:12:22 +0100 Subject: [PATCH] Drop packets if `toPhoneQueue` is full, unless it's text/RangeTest (#2918) --- src/mesh/MeshService.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 038861937..44094f1bb 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -267,14 +267,22 @@ void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) void MeshService::sendToPhone(meshtastic_MeshPacket *p) { + perhapsDecode(p); + if (toPhoneQueue.numFree() == 0) { - LOG_WARN("ToPhone queue is full, discarding oldest\n"); - meshtastic_MeshPacket *d = toPhoneQueue.dequeuePtr(0); - if (d) - releaseToPool(d); + if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP || + p->decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP) { + LOG_WARN("ToPhone queue is full, discarding oldest\n"); + meshtastic_MeshPacket *d = toPhoneQueue.dequeuePtr(0); + if (d) + releaseToPool(d); + } else { + LOG_WARN("ToPhone queue is full, dropping packet.\n"); + releaseToPool(p); + return; + } } - perhapsDecode(p); assert(toPhoneQueue.enqueue(p, 0)); fromNum++; }