Update examples/simple_repeater/MyMesh.cpp

Fix pow() and rand() are calculated for every forwarded packet, but we only need it for flood advert. Also fixes 'paket' typo.

Co-authored-by: Wessel <wessel@weebl.me>
This commit is contained in:
mattzzw
2026-03-05 08:22:22 +01:00
committed by Matthias Wientapper
parent 1b922cdaf4
commit c0d19a007d

View File

@@ -436,12 +436,13 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
} }
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1) // Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
// https://github.com/meshcore-dev/MeshCore/issues/1223 // https://github.com/meshcore-dev/MeshCore/issues/1223
double_t roll_dice = (double)rand() / RAND_MAX; if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood()) {
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1); double roll_dice = (double)rand() / RAND_MAX;
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob) double forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
return false; if (roll_dice > forw_prob)
return false;
}
// all other packets
return true; return true;
} }