From 7f17747d8c3f60760ee905a725d47217e40661c6 Mon Sep 17 00:00:00 2001 From: Chris Danis Date: Fri, 7 Mar 2025 20:33:23 -0500 Subject: [PATCH] NodeInfo exchange: don't bother if too far away (#6260) When we receive a NodeInfo from a new node, if it is more than 2 hops beyond our configured hop limit away from us, don't bother to send a NodeInfo back to it. In my dense urban environment, I see many nodes that are >= 5 hops away, but sending their NodeInfo with a hopStart of 6 or 7. In most cases I can imagine, this seems like a waste of airtime. --- src/mesh/MeshService.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 0ef21d4ca..3bb1f2776 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -88,8 +88,16 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) } else if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB->getMeshNode(mp->from)->has_user && nodeInfoModule && !isPreferredRebroadcaster && !nodeDB->isFull()) { if (airTime->isTxAllowedChannelUtil(true)) { - LOG_INFO("Heard new node on ch. %d, send NodeInfo and ask for response", mp->channel); - nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); + // Hops used by the request. If somebody in between running modified firmware modified it, ignore it + auto hopStart = mp->hop_start; + auto hopLimit = mp->hop_limit; + uint8_t hopsUsed = hopStart < hopLimit ? config.lora.hop_limit : hopStart - hopLimit; + if (hopsUsed > config.lora.hop_limit + 2) { + LOG_DEBUG("Skip send NodeInfo: %d hops away is too far away", hopsUsed); + } else { + LOG_INFO("Heard new node on ch. %d, send NodeInfo and ask for response", mp->channel); + nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); + } } else { LOG_DEBUG("Skip sending NodeInfo > 25%% ch. util"); }