Update examples/simple_room_server/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
69ee28491a
commit
7f3442c13e
@@ -278,14 +278,15 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
||||
if (_prefs.disable_fwd) return false;
|
||||
if (packet->isRouteFlood() && packet->getPathHashCount() >= _prefs.flood_max) return false;
|
||||
|
||||
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
|
||||
// Limit flood advert packet forwarding using a probabilistic reduction defined by P(h) = base^(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