expand relay_node and utilize to improve coverage knowledge

This commit is contained in:
medentem 2025-01-08 19:34:35 -06:00
parent 25a58003c7
commit 4a60761af5
6 changed files with 18 additions and 23 deletions

View File

@ -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)

View File

@ -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<NodeNum> 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<NodeNum> 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<NodeNum> 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) {

View File

@ -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;

View File

@ -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__));

View File

@ -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

View File

@ -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. */