Skip to content

Commit 6a64e84

Browse files
committed
Add cli config flood.advert.base
0 = forwarding flood adverts off 1 = forwarding flood adverts on (unrestricted) 0.308 (default) = prob. forwarding according to #1338
1 parent 27b030c commit 6a64e84

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
327327
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
328328
// https://github.com/meshcore-dev/MeshCore/issues/1223
329329
double_t roll_dice = (double)rand() / RAND_MAX;
330-
double_t forw_prob = pow(0.308, packet->path_len - 1);
330+
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
331331
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob)
332332
return false;
333333

@@ -713,6 +713,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
713713
_prefs.tx_power_dbm = LORA_TX_POWER;
714714
_prefs.advert_interval = 1; // default to 2 minutes for NEW installs
715715
_prefs.flood_advert_interval = 12; // 12 hours
716+
_prefs.flood_advert_base = 0.308f;
716717
_prefs.flood_max = 64;
717718
_prefs.interference_threshold = 0; // disabled
718719

examples/simple_room_server/MyMesh.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
279279
// Limit flood advert paket forwarding using a probabilistic reduction defined by P(h) = 0.308^(hops-1)
280280
// https://github.com/meshcore-dev/MeshCore/issues/1223
281281
double_t roll_dice = (double)rand() / RAND_MAX;
282-
double_t forw_prob = pow(0.308, packet->path_len - 1);
282+
double_t forw_prob = pow(_prefs.flood_advert_base, packet->path_len - 1);
283283
if (packet->getPayloadType() == PAYLOAD_TYPE_ADVERT && packet->isRouteFlood() && roll_dice > forw_prob)
284284
return false;
285285

@@ -622,6 +622,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
622622
_prefs.disable_fwd = 1;
623623
_prefs.advert_interval = 1; // default to 2 minutes for NEW installs
624624
_prefs.flood_advert_interval = 12; // 12 hours
625+
_prefs.flood_advert_base = 0.308f;
625626
_prefs.flood_max = 64;
626627
_prefs.interference_threshold = 0; // disabled
627628
#ifdef ROOM_PASSWORD

src/helpers/CommonCLI.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
7171
file.read((uint8_t *)&_prefs->gps_interval, sizeof(_prefs->gps_interval)); // 157
7272
file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161
7373
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
74-
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
75-
// 170
74+
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
75+
file.read((uint8_t *)&_prefs->flood_advert_base, sizeof(_prefs->flood_advert_base)); // 170
76+
// 174
7677

7778
// sanitise bad pref values
7879
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
@@ -99,6 +100,8 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
99100
_prefs->gps_enabled = constrain(_prefs->gps_enabled, 0, 1);
100101
_prefs->advert_loc_policy = constrain(_prefs->advert_loc_policy, 0, 2);
101102

103+
_prefs->flood_advert_base = constrain(_prefs->flood_advert_base, 0, 1);
104+
102105
file.close();
103106
}
104107
}
@@ -155,7 +158,9 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
155158
file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161
156159
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
157160
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
158-
// 170
161+
file.write((uint8_t *)&_prefs->flood_advert_base, sizeof(_prefs->flood_advert_base)); // 170
162+
163+
// 174
159164

160165
file.close();
161166
}
@@ -345,6 +350,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
345350
} else {
346351
sprintf(reply, "> %.3f", adc_mult);
347352
}
353+
} else if (memcmp(config, "flood.advert.base", 17) == 0) {
354+
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->flood_advert_base));
348355
} else {
349356
sprintf(reply, "??: %s", config);
350357
}
@@ -550,6 +557,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
550557
_prefs->adc_multiplier = 0.0f;
551558
strcpy(reply, "Error: unsupported by this board");
552559
};
560+
} else if (memcmp(config, "flood.advert.base ", 18) == 0) {
561+
float f = atof(&config[18]);
562+
if((f > 0) || (f<1)) {
563+
_prefs->flood_advert_base = f;
564+
savePrefs();
565+
strcpy(reply, "OK");
566+
} else {
567+
strcpy(reply, "Error: base must be between 0 and 1");
568+
}
553569
} else {
554570
sprintf(reply, "unknown config: %s", config);
555571
}

src/helpers/CommonCLI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct NodePrefs { // persisted to file
3535
uint8_t flood_max;
3636
uint8_t interference_threshold;
3737
uint8_t agc_reset_interval; // secs / 4
38+
float flood_advert_base;
3839
// Bridge settings
3940
uint8_t bridge_enabled; // boolean
4041
uint16_t bridge_delay; // milliseconds (default 500 ms)

0 commit comments

Comments
 (0)