mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* repeater: new "get/set loop.detect {off | minimal | moderate | strict }"
This commit is contained in:
parent
3031deb980
commit
e233346bf0
4 changed files with 72 additions and 2 deletions
|
|
@ -396,6 +396,23 @@ File MyMesh::openAppend(const char *fname) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static uint8_t max_loop_minimal[] = { 0, /* 1-byte */ 4, /* 2-byte */ 2, /* 3-byte */ 1 };
|
||||
static uint8_t max_loop_moderate[] = { 0, /* 1-byte */ 2, /* 2-byte */ 1, /* 3-byte */ 1 };
|
||||
static uint8_t max_loop_strict[] = { 0, /* 1-byte */ 1, /* 2-byte */ 1, /* 3-byte */ 1 };
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
return n >= max_counters[hash_size];
|
||||
}
|
||||
|
||||
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
||||
if (_prefs.disable_fwd) return false;
|
||||
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
|
||||
|
|
@ -403,6 +420,20 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
|||
MESH_DEBUG_PRINTLN("allowPacketForward: unknown transport code, or wildcard not allowed for FLOOD packet");
|
||||
return false;
|
||||
}
|
||||
if (packet->isRouteFlood() && _prefs.loop_detect != LOOP_DETECT_OFF) {
|
||||
const uint8_t* maximums;
|
||||
if (_prefs.loop_detect == LOOP_DETECT_MINIMAL) {
|
||||
maximums = max_loop_minimal;
|
||||
} else if (_prefs.loop_detect == LOOP_DETECT_MINIMAL) {
|
||||
maximums = max_loop_moderate;
|
||||
} else {
|
||||
maximums = max_loop_strict;
|
||||
}
|
||||
if (isLooped(packet, maximums)) {
|
||||
MESH_DEBUG_PRINTLN("allowPacketForward: FLOOD packet loop detected!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||
mesh::Packet* createSelfAdvert();
|
||||
|
||||
File openAppend(const char* fname);
|
||||
bool isLooped(const mesh::Packet* packet, const uint8_t max_counters[]);
|
||||
|
||||
protected:
|
||||
float getAirtimeBudgetFactor() const override {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue