From 4a60761af549cd4798b90ea0e405bdff0ee2e0b2 Mon Sep 17 00:00:00 2001 From: medentem Date: Wed, 8 Jan 2025 19:34:35 -0600 Subject: [PATCH] expand relay_node and utilize to improve coverage knowledge --- src/mesh/MeshTypes.h | 7 +++---- src/mesh/NodeDB.cpp | 20 +++++++------------ src/mesh/RadioInterface.cpp | 4 ++-- src/mesh/RadioInterface.h | 2 +- src/mesh/generated/meshtastic/deviceonly.pb.h | 4 +++- src/mesh/generated/meshtastic/mesh.pb.h | 4 ++-- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index 07b95f78b..0d301156b 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -37,12 +37,11 @@ enum RxSource { **/ #ifdef USERPREFS_USE_COVERAGE_FILTER - #define HOP_MAX 15 +#define HOP_MAX 15 #else - #define HOP_MAX 7 +#define HOP_MAX 7 #endif - /// We normally just use max 3 hops for sending reliable messages #define HOP_RELIABLE 3 @@ -53,7 +52,7 @@ enum RxSource { #define STALE_COVERAGE_SECONDS 60 * 60 * 0.5 // 1 hour // Size of the Bloom filter in bytes (128 bits) -#define BLOOM_FILTER_SIZE_BYTES 16 +#define BLOOM_FILTER_SIZE_BYTES 13 // Size of the Bloom filter in bits (128 bits) #define BLOOM_FILTER_SIZE_BITS (BLOOM_FILTER_SIZE_BYTES * 8) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 9b67f26fa..34192df78 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -498,7 +498,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) #else config.lora.hop_limit = HOP_RELIABLE; #endif -LOG_DEBUG("Hop Limit set to %x", config.lora.hop_limit); + LOG_DEBUG("Hop Limit set to %x", config.lora.hop_limit); #ifdef USERPREFS_CONFIG_LORA_IGNORE_MQTT config.lora.ignore_mqtt = USERPREFS_CONFIG_LORA_IGNORE_MQTT; #else @@ -835,17 +835,12 @@ bool NodeDB::isValidCandidateForCoverage(const meshtastic_NodeInfoLite &node) LOG_DEBUG("Node 0x%x is not valid for coverage: Ignored", node.num); return false; } - // 3) Exclude nodes that aren't direct neighbors - if (!node.has_hops_away || node.hops_away != 0) { - LOG_DEBUG("Node 0x%x is not valid for coverage: Not Direct Neighbor", node.num); - return false; - } - // 4) Exclude MQTT-based nodes if desired + // 3) Exclude MQTT-based nodes if desired if (node.via_mqtt) { LOG_DEBUG("Node 0x%x is not valid for coverage: MQTT", node.num); return false; } - // 5) Must have last_heard + // 4) Must have last_heard if (node.last_heard == 0) { LOG_DEBUG("Node 0x%x is not valid for coverage: Missing Last Heard", node.num); return false; @@ -869,7 +864,6 @@ bool NodeDB::isValidCandidateForCoverage(const meshtastic_NodeInfoLite &node) std::vector NodeDB::getCoveredNodes(uint32_t timeWindowSecs) { uint32_t now = getTime(); - NodeNum localNode = getNodeNum(); // We'll collect (nodeNum, last_heard, snr) for both main DB + ephemeral struct NodeCandidate { @@ -891,7 +885,7 @@ std::vector NodeDB::getCoveredNodes(uint32_t timeWindowSecs) uint32_t age = now - node.last_heard; if (age <= timeWindowSecs) { - allCandidates.push_back(NodeCandidate{node.num, node.last_heard, node.snr}); + allCandidates.push_back(NodeCandidate{node.relay_node, node.last_heard, node.snr}); } } @@ -903,9 +897,9 @@ std::vector NodeDB::getCoveredNodes(uint32_t timeWindowSecs) uint32_t age = now - node.last_heard; if (age <= timeWindowSecs) { - allCandidates.push_back(NodeCandidate{node.num, node.last_heard, node.snr}); + allCandidates.push_back(NodeCandidate{node.relay_node, node.last_heard, node.snr}); } else { - LOG_DEBUG("Node 0x%x is not valid for coverage: Aged Out", node.num); + LOG_DEBUG("Node 0x%x is not valid for coverage: Aged Out", node.relay_node); } } @@ -960,7 +954,7 @@ void NodeDB::cleanupMeshDB() for (int i = 0; i < numMeshNodes; i++) { if (meshNodes->at(i).has_user) { - if (meshNodes->at(i).has_hops_away && meshNodes->at(i).hops_away == 0 && meshNodes->at(i).last_heard > maxLastHeardDirectNeighbor_) { + if (meshNodes->at(i).last_heard > maxLastHeardDirectNeighbor_) { maxLastHeardDirectNeighbor_ = meshNodes->at(i).last_heard; } if (meshNodes->at(i).user.public_key.size > 0) { diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 786f9107b..849a5bad8 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -637,8 +637,8 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p) radioBuffer.header.to = p->to; radioBuffer.header.id = p->id; radioBuffer.header.channel = p->channel; - radioBuffer.header.next_hop = 0; // *** For future use *** - radioBuffer.header.relay_node = 0; // *** For future use *** + radioBuffer.header.next_hop = 0; // *** For future use *** + radioBuffer.header.relay_node = nodeDB->getNodeNum(); // *** For future use *** if (p->hop_limit > HOP_MAX) { LOG_WARN("hop limit %d is too high, setting to %d", p->hop_limit, HOP_RELIABLE); p->hop_limit = HOP_RELIABLE; diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 6d6065b4a..652515ab3 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -42,7 +42,7 @@ typedef struct { uint8_t next_hop; // ***For future use*** Last byte of the NodeNum of the node that will relay/relayed this packet - uint8_t relay_node; + NodeNum relay_node; // A 16-byte Bloom filter that tracks coverage of the current node. uint8_t coverage_filter[BLOOM_FILTER_SIZE_BYTES] __attribute__((__aligned__)); diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index c0a0fee91..097ff5b11 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -92,6 +92,8 @@ typedef struct _meshtastic_NodeInfoLite { bool is_ignored; /* Last byte of the node number of the node that should be used as the next hop to reach this node. */ uint8_t next_hop; + /* Node id of the relaying node. */ + uint32_t relay_node; } meshtastic_NodeInfoLite; /* This message is never sent over the wire, but it is used for serializing DB @@ -296,4 +298,4 @@ extern const pb_msgdesc_t meshtastic_ChannelFile_msg; } /* extern "C" */ #endif -#endif +#endif \ No newline at end of file diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index c303db9e5..588ebe401 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -690,7 +690,7 @@ typedef struct _meshtastic_MqttClientProxyMessage { typedef PB_BYTES_ARRAY_T(256) meshtastic_MeshPacket_encrypted_t; typedef PB_BYTES_ARRAY_T(32) meshtastic_MeshPacket_public_key_t; -typedef PB_BYTES_ARRAY_T(16) meshtastic_MeshPacket_coverage_filter_t; +typedef PB_BYTES_ARRAY_T(13) meshtastic_MeshPacket_coverage_filter_t; /* A packet envelope sent/received over the mesh only payload_variant is sent in the payload portion of the LORA packet. The other fields are either not sent at all, or sent in the special 16 byte LORA header. */ @@ -770,7 +770,7 @@ typedef struct _meshtastic_MeshPacket { uint8_t next_hop; /* Last byte of the node number of the node that will relay/relayed this packet. Set by the firmware internally, clients are not supposed to set this. */ - uint8_t relay_node; + uint32_t relay_node; /* *Never* sent over the radio links. Timestamp after which this packet may be sent. Set by the firmware internally, clients are not supposed to set this. */