fairness: limity podle reálného provozu, 00/ff odesílatelé nejsou rezervovaní

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-06 22:33:05 +02:00
1 parent f79ea79a13
commit 4cc830e70b
3 files changed
+33 -36

No files matched your search

-20
View File
@@ -35,11 +35,6 @@ void FairnessLimiter::refillGroup() {
}
uint8_t FairnessLimiter::peekSenderNormal(const uint8_t* hash) {
// Always zero as 0x00 and 0xFF are reserved
if (hash[0] == 0x00 || hash[0] == 0xFF) {
return 0;
}
auto i = sender_normal_idx(hash);
if (i >= SENDER_NORMAL_MAP_SIZE) {
return 0;
@@ -48,11 +43,6 @@ uint8_t FairnessLimiter::peekSenderNormal(const uint8_t* hash) {
}
bool FairnessLimiter::takeSenderNormal(const uint8_t* hash) {
// Always false as 0x00 and 0xFF are reserved
if (hash[0] == 0x00 || hash[0] == 0xFF) {
return false;
}
auto i = sender_normal_idx(hash);
bool allow = false;
if (i < SENDER_NORMAL_MAP_SIZE && sender_normal_map[i] > 0) {
@@ -75,11 +65,6 @@ void FairnessLimiter::refillSenderNormal() {
}
uint8_t FairnessLimiter::peekSenderLow(const uint8_t* hash) {
// Always zero as 0x00 and 0xFF are reserved
if (hash[0] == 0x00 || hash[0] == 0xFF) {
return 0;
}
auto i = sender_low_idx(hash);
if (i >= SENDER_LOW_MAP_SIZE) {
return 0;
@@ -88,11 +73,6 @@ uint8_t FairnessLimiter::peekSenderLow(const uint8_t* hash) {
}
bool FairnessLimiter::takeSenderLow(const uint8_t* hash) {
// Always false as 0x00 and 0xFF are reserved
if (hash[0] == 0x00 || hash[0] == 0xFF) {
return false;
}
auto i = sender_low_idx(hash);
bool allow = false;
if (i < SENDER_LOW_MAP_SIZE && sender_low_map[i] > 0) {
+20 -9
View File
@@ -19,8 +19,10 @@
#include <Packet.h>
#include <stdint.h>
// For senders 0x00 and 0xFF are reserved (Identity.cpp rejects them as path
// hash prefixes). Group channel hashes are pure sha256, so no reserved values.
// Sender hashes 0x00 and 0xFF are NOT special here: repeaters, room servers
// and sensors re-roll such identities, but companions do not, so real users
// send with them (~1 in 128). Denying them always (as the original branch did)
// dropped every flood DM/PATH/REQ of those users.
// Note: mask, cap and refill interval are highly connected parameters.
#define GROUP_MASK 0b00011111 // 5-bit address
#define SENDER_NORMAL_MASK 0b00111111 // 6-bit address
@@ -28,25 +30,34 @@
// Refill intervals: ONE token per bucket per interval. Steady-state rate is
// 1/interval, cap bounds the burst. Overridable per env from platformio ini.
//
// Sized from real traffic (6 Sep - 6 Oct 2026: 207k floods heard on the CZ
// mesh at one-site, replayed through this limiter). The zero-loss frontier
// over those 30 days was group 60 s/cap 60, sender 10 s/cap 60, advert 600 s/
// cap 12; the defaults below keep about 2x headroom on top. The busiest
// legitimate channel runs ~26 msg/h around the clock, so the limiter is a net
// for runaway floods (the bot that prompted it sent ~330 msg/h), not a quota.
// The earlier defaults (cap 20/30/4, refill 180 s/240 s/7200 s) would have
// shed 9 % of channel messages, 15 % of sender-keyed traffic and 15 % of adverts.
#ifndef FAIRNESS_GROUP_REFILL_MS
#define FAIRNESS_GROUP_REFILL_MS (3 * 60 * 1000)
#define FAIRNESS_GROUP_REFILL_MS (30 * 1000)
#endif
#ifndef FAIRNESS_SENDER_NORMAL_REFILL_MS
#define FAIRNESS_SENDER_NORMAL_REFILL_MS (4 * 60 * 1000)
#define FAIRNESS_SENDER_NORMAL_REFILL_MS (10 * 1000)
#endif
#ifndef FAIRNESS_SENDER_LOW_REFILL_MS
#define FAIRNESS_SENDER_LOW_REFILL_MS (120 * 60 * 1000)
#define FAIRNESS_SENDER_LOW_REFILL_MS (10 * 60 * 1000)
#endif
// Capacity (max burst) per bucket.
// Capacity (max burst) per bucket. uint8_t, so at most 255.
#ifndef FAIRNESS_GROUP_CAP
#define FAIRNESS_GROUP_CAP 20
#define FAIRNESS_GROUP_CAP 100
#endif
#ifndef FAIRNESS_SENDER_NORMAL_CAP
#define FAIRNESS_SENDER_NORMAL_CAP 30
#define FAIRNESS_SENDER_NORMAL_CAP 150
#endif
#ifndef FAIRNESS_SENDER_LOW_CAP
#define FAIRNESS_SENDER_LOW_CAP 4
#define FAIRNESS_SENDER_LOW_CAP 30
#endif
// Simply allow all direct messages?