From 9b1dd75549c3d1cff9dc14316c7ee78594322210 Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Sat, 14 Oct 2023 17:17:12 +0200 Subject: [PATCH] Short-circuit to FloodingRouter for broadcasts --- src/mesh/NextHopRouter.cpp | 7 ++----- src/mesh/ReliableRouter.cpp | 35 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/mesh/NextHopRouter.cpp b/src/mesh/NextHopRouter.cpp index 68f4ec620..40f34d1fd 100644 --- a/src/mesh/NextHopRouter.cpp +++ b/src/mesh/NextHopRouter.cpp @@ -66,14 +66,11 @@ void NextHopRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtast tosend->hop_limit--; // bump down the hop count NextHopRouter::send(tosend); - } else if (p->next_hop == 0) { + } else if (p->next_hop == NO_NEXT_HOP_PREFERENCE) { // No preference for next hop, use FloodingRouter LOG_DEBUG("No preference for next hop, using FloodingRouter\n"); FloodingRouter::sniffReceived(p, c); - } else if (p->to == NODENUM_BROADCAST) { - // TODO: Smarter way of handling broadcasts - FloodingRouter::sniffReceived(p, c); - } + } // else don't relay } } else { LOG_DEBUG("Not rebroadcasting. Role = Role_ClientMute\n"); diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 70af96d8b..fa85b1af4 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -33,7 +33,7 @@ ErrorCode ReliableRouter::send(meshtastic_MeshPacket *p) } } - return config.lora.next_hop_routing ? NextHopRouter::send(p) : FloodingRouter::send(p); + return (config.lora.next_hop_routing && p->to != NODENUM_BROADCAST) ? NextHopRouter::send(p) : FloodingRouter::send(p); } bool ReliableRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) @@ -132,8 +132,9 @@ void ReliableRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas } } - // handle the packet as normal - config.lora.next_hop_routing ? NextHopRouter::sniffReceived(p, c) : FloodingRouter::sniffReceived(p, c); + // For DMs, we use the NextHopRouter, whereas for broadcasts, we use the FloodingRouter + config.lora.next_hop_routing && (p->to != NODENUM_BROADCAST) ? NextHopRouter::sniffReceived(p, c) + : FloodingRouter::sniffReceived(p, c); } #define NUM_RETRANSMISSIONS 3 @@ -222,22 +223,24 @@ int32_t ReliableRouter::doRetransmissions() LOG_DEBUG("Sending reliable retransmission fr=0x%x,to=0x%x,id=0x%x, tries left=%d\n", p.packet->from, p.packet->to, p.packet->id, p.numRetransmissions); - if (config.lora.next_hop_routing && p.numRetransmissions == 1) { - // Last retransmission, reset next_hop (fallback to FloodingRouter) - p.packet->next_hop = NO_NEXT_HOP_PREFERENCE; - // Also reset it in the nodeDB - meshtastic_NodeInfoLite *sentTo = nodeDB.getMeshNode(p.packet->to); - if (sentTo) { - LOG_DEBUG("Resetting next hop for packet with dest 0x%x\n", p.packet->to); - sentTo->next_hop = NO_NEXT_HOP_PREFERENCE; + if (config.lora.next_hop_routing && p.packet->to != NODENUM_BROADCAST) { + if (p.numRetransmissions == 1) { + // Last retransmission, reset next_hop (fallback to FloodingRouter) + p.packet->next_hop = NO_NEXT_HOP_PREFERENCE; + // Also reset it in the nodeDB + meshtastic_NodeInfoLite *sentTo = nodeDB.getMeshNode(p.packet->to); + if (sentTo) { + LOG_DEBUG("Resetting next hop for packet with dest 0x%x\n", p.packet->to); + sentTo->next_hop = NO_NEXT_HOP_PREFERENCE; + } } + NextHopRouter::send(packetPool.allocCopy(*p.packet)); + } else { + // Note: we call the superclass version because we don't want to have our version of send() add a new + // retransmission record + FloodingRouter::send(packetPool.allocCopy(*p.packet)); } - // Note: we call the superclass version because we don't want to have our version of send() add a new - // retransmission record - config.lora.next_hop_routing ? NextHopRouter::send(packetPool.allocCopy(*p.packet)) - : FloodingRouter::send(packetPool.allocCopy(*p.packet)); - // Queue again --p.numRetransmissions; setNextTx(&p);