`fairness advert <hours>|clear`: each origin's flood advert is forwarded at most once per window (0 = off, max 720 h), keyed on the first 4 B of its pubkey in a 256-entry ring (2 KB RAM). Ported from DutchMeshCore's AdvertLimiter (d26421b0); runs ahead of the advert bucket, so a held advert takes no token. Motivation: companion CP1 floods an advert every 60 s since 30. 10. 2026 and still made up 18 % of the adverts our masts forwarded -- the 7-bit advert bucket cannot single it out without hurting the ~8 nodes that share its bucket. `fairness dryrun on|off`: window and buckets count every verdict but forward anyway. `fairness air`: estimated airtime shed per reason. The bucket kill switch (`fairness off`) no longer disables the window. Both new settings persist (fair_advh, fair_dry). Bench 1. 11. 2026 (x3 DUT, x1 spammer + witness, 866.5/SF8, advert every 30 s, echoes counted on the witness): dry-run 6/6 forwarded with 5 counted as held, enforced 1/6, window off 3/3, buckets in dry-run 5/5 with 3 counted; settings survive a reboot. Native tests 26/26 fairness, 119 total. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8ea4144d9
commit
e8d5ab417a
7 files changed
+351
-11
No files matched your search
@@ -737,6 +737,9 @@ bool MyMesh::allowPacketForward(const mesh::Packet *packet) {
|
||||
// `fairness grid` -- busiest deny buckets per category (what we shed).
|
||||
// `fairness cap <group> <sender> <advert>` -- burst caps, 0 = default.
|
||||
// `fairness refill <group_s> <sender_s> <advert_s>` -- refill interval secs, 0 = default.
|
||||
// `fairness advert [<hours>|clear]` -- per-origin advert window (0 = off).
|
||||
// `fairness dryrun [on|off]` -- count verdicts, forward anyway.
|
||||
// `fairness air` -- estimated airtime shed per reason.
|
||||
// All tuning is persisted, so a mast reboot keeps it.
|
||||
bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_max) {
|
||||
if (memcmp(command, "fairness", 8) != 0 || (command[8] != 0 && command[8] != ' ')) return false;
|
||||
@@ -745,11 +748,54 @@ bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_m
|
||||
|
||||
if (strcmp(arg, "on") == 0 || strcmp(arg, "off") == 0) {
|
||||
_prefs.fairness_enabled = (arg[1] == 'n') ? 1 : 0;
|
||||
fairness_limiter.setBucketsEnabled(_prefs.fairness_enabled);
|
||||
savePrefs();
|
||||
snprintf(reply, reply_max, "OK - fairness %s", _prefs.fairness_enabled ? "on" : "off");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(arg, "dryrun") == 0 || strcmp(arg, "dryrun on") == 0 || strcmp(arg, "dryrun off") == 0) {
|
||||
if (arg[6] == ' ') {
|
||||
_prefs.fair_dry_run = (arg[8] == 'n') ? 1 : 0;
|
||||
fairness_limiter.setDryRun(_prefs.fair_dry_run);
|
||||
savePrefs();
|
||||
}
|
||||
snprintf(reply, reply_max, "%sfairness dry-run %s", arg[6] == ' ' ? "OK - " : "",
|
||||
fairness_limiter.dryRun() ? "on" : "off");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(arg, "advert") == 0 || strncmp(arg, "advert ", 7) == 0) {
|
||||
AdvertWindow& w = fairness_limiter.advertWindow();
|
||||
if (strcmp(arg, "advert clear") == 0) {
|
||||
w.clear();
|
||||
} else if (arg[6] == ' ') {
|
||||
char* end = NULL;
|
||||
long h = strtol(arg + 7, &end, 10);
|
||||
if (end == arg + 7 || *end != 0 || h < 0 || h > ADVERT_WINDOW_MAX_HOURS) {
|
||||
snprintf(reply, reply_max, "Err - fairness advert <0-%d hours>|clear", ADVERT_WINDOW_MAX_HOURS);
|
||||
return true;
|
||||
}
|
||||
_prefs.fair_advert_hours = (uint16_t)h;
|
||||
w.setHours(_prefs.fair_advert_hours);
|
||||
savePrefs();
|
||||
}
|
||||
snprintf(reply, reply_max, "advert window %uh%s, held %u (%us air), cache %d/%d, evicted %u",
|
||||
(uint32_t)w.hours(), fairness_limiter.dryRun() ? " DRY-RUN" : "", fairness_limiter.deniedWindow(),
|
||||
fairness_limiter.shedAirtimeMs(FAIR_SHED_WINDOW) / 1000, w.count(), w.capacity(), w.evicted());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(arg, "air") == 0) {
|
||||
snprintf(reply, reply_max, "shed air%s: group %us sender %us advert %us window %us",
|
||||
fairness_limiter.dryRun() ? " (dry-run, would be)" : "",
|
||||
fairness_limiter.shedAirtimeMs(FAIR_SHED_GROUP) / 1000,
|
||||
fairness_limiter.shedAirtimeMs(FAIR_SHED_SENDER) / 1000,
|
||||
fairness_limiter.shedAirtimeMs(FAIR_SHED_ADVERT) / 1000,
|
||||
fairness_limiter.shedAirtimeMs(FAIR_SHED_WINDOW) / 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(arg, "grid") == 0) {
|
||||
char grid[180];
|
||||
fairness_limiter.formatGrid(grid, sizeof(grid));
|
||||
@@ -799,16 +845,16 @@ bool MyMesh::fairnessHandleCommand(const char *command, char *reply, int reply_m
|
||||
}
|
||||
|
||||
if (arg[0] != 0) {
|
||||
strcpy(reply, "Err - fairness [on|off|grid|cap ...|refill ...]");
|
||||
strcpy(reply, "Err - fairness [on|off|grid|cap|refill|advert|dryrun|air]");
|
||||
return true;
|
||||
}
|
||||
|
||||
// bare `fairness` -- stats + current caps/refills
|
||||
snprintf(reply, reply_max,
|
||||
"fairness: %s, denied group %u/sender %u/advert %u; cap %u/%u/%u; refill %u/%u/%us",
|
||||
_prefs.fairness_enabled ? "on" : "OFF",
|
||||
"fairness: %s%s, denied group %u/sender %u/advert %u/window %u; cap %u/%u/%u; refill %u/%u/%us",
|
||||
_prefs.fairness_enabled ? "on" : "OFF", fairness_limiter.dryRun() ? " DRY-RUN" : "",
|
||||
fairness_limiter.deniedGroup(), fairness_limiter.deniedSenderNormal(),
|
||||
fairness_limiter.deniedSenderLow(),
|
||||
fairness_limiter.deniedSenderLow(), fairness_limiter.deniedWindow(),
|
||||
(uint32_t)fairness_limiter.groupCap(), (uint32_t)fairness_limiter.senderNormalCap(),
|
||||
(uint32_t)fairness_limiter.senderLowCap(),
|
||||
(uint32_t)(fairGroupRefillMs() / 1000), (uint32_t)(fairSenderRefillMs() / 1000),
|
||||
@@ -1404,6 +1450,9 @@ void MyMesh::begin(FILESYSTEM *fs) {
|
||||
fairness_limiter.setGroupCap(_prefs.fair_group_cap);
|
||||
fairness_limiter.setSenderNormalCap(_prefs.fair_sender_cap);
|
||||
fairness_limiter.setSenderLowCap(_prefs.fair_advert_cap);
|
||||
fairness_limiter.setBucketsEnabled(_prefs.fairness_enabled);
|
||||
fairness_limiter.setDryRun(_prefs.fair_dry_run);
|
||||
fairness_limiter.advertWindow().setHours(_prefs.fair_advert_hours);
|
||||
|
||||
// Fairness buckets start with just ONE token (not the full cap): a repeater
|
||||
// stuck in a crash loop must not hand out a fresh burst on every boot.
|
||||
|
||||
Reference in new issue
Block a user