Browse Source

ignore leading zero path padding for flood max

pull/2745/head
Jukka Vaisanen 4 days ago
parent
commit
7dee23fa0d
  1. 7
      examples/simple_repeater/MyMesh.cpp
  2. 7
      examples/simple_room_server/MyMesh.cpp
  3. 2
      examples/simple_sensor/SensorMesh.cpp
  4. 18
      src/Packet.cpp
  5. 1
      src/Packet.h

7
examples/simple_repeater/MyMesh.cpp

@ -429,9 +429,10 @@ void MyMesh::sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, ui
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
if (_prefs.disable_fwd) return false;
if (packet->isRouteFlood()) {
if (packet->getPathHashCount() >= _prefs.flood_max) return false;
if (packet->getRouteType() == ROUTE_TYPE_FLOOD && packet->getPathHashCount() >= _prefs.flood_max_unscoped) return false;
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->getPathHashCount() >= _prefs.flood_max_advert) return false;
uint8_t flood_hops = packet->getPathHashCountExcludingLeadingZeros();
if (flood_hops >= _prefs.flood_max) return false;
if (packet->getRouteType() == ROUTE_TYPE_FLOOD && flood_hops >= _prefs.flood_max_unscoped) return false;
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && flood_hops >= _prefs.flood_max_advert) return false;
}
if (packet->isRouteFlood() && recv_pkt_region == NULL) {
MESH_DEBUG_PRINTLN("allowPacketForward: unknown transport code, or wildcard not allowed for FLOOD packet");

7
examples/simple_room_server/MyMesh.cpp

@ -283,9 +283,10 @@ uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
if (_prefs.disable_fwd) return false;
if (packet->isRouteFlood()) {
if (packet->getPathHashCount() >= _prefs.flood_max) return false;
if (packet->getRouteType() == ROUTE_TYPE_FLOOD && packet->getPathHashCount() >= _prefs.flood_max_unscoped) return false;
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->getPathHashCount() >= _prefs.flood_max_advert) return false;
uint8_t flood_hops = packet->getPathHashCountExcludingLeadingZeros();
if (flood_hops >= _prefs.flood_max) return false;
if (packet->getRouteType() == ROUTE_TYPE_FLOOD && flood_hops >= _prefs.flood_max_unscoped) return false;
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && flood_hops >= _prefs.flood_max_advert) return false;
}
return true;
}

2
examples/simple_sensor/SensorMesh.cpp

@ -303,7 +303,7 @@ float SensorMesh::getAirtimeBudgetFactor() const {
bool SensorMesh::allowPacketForward(const mesh::Packet* packet) {
if (_prefs.disable_fwd) return false;
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
if (packet->isRouteFlood() && packet->getPathHashCountExcludingLeadingZeros() >= _prefs.flood_max) return false;
return true;
}

18
src/Packet.cpp

@ -34,6 +34,22 @@ uint8_t Packet::copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
return path_len;
}
uint8_t Packet::getPathHashCountExcludingLeadingZeros() const {
uint8_t hash_count = getPathHashCount();
uint8_t hash_size = getPathHashSize();
if (hash_size > 3) return hash_count;
if (hash_count == 0 || path[0] != 0) return hash_count;
uint8_t path_byte_len = hash_count * hash_size;
uint8_t zero_bytes = 1;
while (zero_bytes < path_byte_len && path[zero_bytes] == 0) {
zero_bytes++;
}
uint8_t padding_count = zero_bytes / hash_size;
return hash_count - padding_count;
}
int Packet::getRawLength() const {
return 2 + getPathByteLen() + payload_len + (hasTransportCodes() ? 4 : 0);
}
@ -84,4 +100,4 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
return true; // success
}
}
}

1
src/Packet.h

@ -78,6 +78,7 @@ public:
uint8_t getPathHashSize() const { return (path_len >> 6) + 1; }
uint8_t getPathHashCount() const { return path_len & 63; }
uint8_t getPathHashCountExcludingLeadingZeros() const;
uint8_t getPathByteLen() const { return getPathHashCount() * getPathHashSize(); }
void setPathHashCount(uint8_t n) { path_len &= ~63; path_len |= n; }
void setPathHashSizeAndCount(uint8_t sz, uint8_t n) { path_len = ((sz - 1) << 6) | (n & 63); }

Loading…
Cancel
Save