Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,21 @@ static uint8_t max_loop_strict[] = { 0, /* 1-byte */ 1, /* 2-byte */ 1, /* 3

bool MyMesh::isLooped(const mesh::Packet* packet, const uint8_t max_counters[]) {
uint8_t hash_size = packet->getPathHashSize();
uint8_t hash_count = packet->getPathHashCount();
uint8_t n = 0;
uint8_t path_byte_len = packet->getPathByteLen();
uint8_t limit = max_counters[hash_size];
const uint8_t* path = packet->path;
while (hash_count > 0) { // count how many times this node is already in the path
if (self_id.isHashMatch(path, hash_size)) n++;
hash_count--;
path += hash_size;

for (uint8_t i = 0; i < path_byte_len; i += hash_size) {
uint8_t n = 0;

if (self_id.isHashMatch(&path[i], hash_size)) n++;

for (uint8_t j = i + hash_size; j < path_byte_len; j += hash_size) {
if (memcmp(&path[i], &path[j], hash_size) == 0) n++;
}
if (n >= limit) return true;
}
return n >= max_counters[hash_size];
return false;
}

bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
Expand Down