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:
committed by
Matthias Wientapper
parent
c1587b5bb6
commit
52ae3c3936
@@ -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)
|
||||
// https://github.com/meshcore-dev/MeshCore/issues/1223
|
||||
double_t roll_dice = (double)rand() / RAND_MAX;
|
||||
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
||||
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob)
|
||||
return false;
|
||||
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood()) {
|
||||
double roll_dice = (double)rand() / RAND_MAX;
|
||||
double forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
|
||||
if (roll_dice > forw_prob)
|
||||
return false;
|
||||
}
|
||||
|
||||
// all other packets
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user