From d64c5528651ebd986b402284ac5c7a32dbc6d792 Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Mon, 1 Aug 2022 23:59:50 +0200 Subject: [PATCH] Rebroadcast direct message until (implicit) ACK (#1578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ben Meadors Co-authored-by: Thomas Göttgens --- src/mesh/FloodingRouter.cpp | 8 ++++++-- src/mesh/ReliableRouter.cpp | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index e01863de1..5e3126f77 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -29,8 +29,12 @@ bool FloodingRouter::shouldFilterReceived(MeshPacket *p) void FloodingRouter::sniffReceived(const MeshPacket *p, const Routing *c) { - - if ((p->to == NODENUM_BROADCAST) && (p->hop_limit > 0) && (getFrom(p) != getNodeNum())) { + PacketId ackId = ((c && c->error_reason == Routing_Error_NONE) || !c) ? p->decoded.request_id : 0; + if (ackId && p->to != getNodeNum()) { + // do not flood direct message that is ACKed + DEBUG_MSG("Receiving an ACK not for me, but don't need to rebroadcast this direct message anymore.\n"); + Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM + } else if ((p->to != getNodeNum()) && (p->hop_limit > 0) && (getFrom(p) != getNodeNum())) { if (p->id != 0) { if (config.device.role != Config_DeviceConfig_Role_ClientMute) { MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index a23adfa7d..9a65823ec 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -16,7 +16,7 @@ ErrorCode ReliableRouter::send(MeshPacket *p) // If someone asks for acks on broadcast, we need the hop limit to be at least one, so that first node that receives our // message will rebroadcast. But asking for hop_limit 0 in that context means the client app has no preference on hop // counts and we want this message to get through the whole mesh, so use the default. - if (p->to == NODENUM_BROADCAST && p->hop_limit == 0) { + if (p->hop_limit == 0) { if (config.lora.hop_limit && config.lora.hop_limit <= HOP_MAX) { p->hop_limit = (config.lora.hop_limit >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; } else { @@ -34,7 +34,7 @@ ErrorCode ReliableRouter::send(MeshPacket *p) bool ReliableRouter::shouldFilterReceived(MeshPacket *p) { // Note: do not use getFrom() here, because we want to ignore messages sent from phone - if (p->to == NODENUM_BROADCAST && p->from == getNodeNum()) { + if (p->from == getNodeNum()) { printPacket("Rx someone rebroadcasting for us", p); // We are seeing someone rebroadcast one of our broadcast attempts. @@ -231,4 +231,4 @@ void ReliableRouter::setNextTx(PendingPacket *pending) DEBUG_MSG("Setting next retransmission in %u msecs: ", d); printPacket("", pending->packet); setReceivedMessage(); // Run ASAP, so we can figure out our correct sleep time -} \ No newline at end of file +}