blepwr/fairness: opravy z review-three
- `blepwr` parsuje striktně (strtol + kontrola celého argumentu a platné hodnoty) — `atoi` udělal z „216" −40 a z „abc" 0, a teď se to ukládá. Stará syntaxe `blepwr -20 hold` skončí ERR místo tichého uložení −20. - „saved" jen když zápis do InternalFS opravdu prošel, jinak „NOT saved". - mast-three env: RPT_BLE_CONN_TX_POWER=8, aby po flashi nenaběhl na 0 dBm, na kterých most z bridge-host přes zavřené okno padá. - FairnessLimiter: opravené odůvodnění 0x00/0xFF — náš companion identitu přegeneruje, ale na CZ meshi za 30 dní prošlo 50 floodů od takových odesílatelů a u ANON_REQ je payload[1] bajt náhodného klíče (2/256 všech). Test přejmenován (cap 100 je teď pod defaultem). - tools/fairness_replay.py: přehrání floodů z CoreScope přes model limiteru, odkud jsou výchozí hodnoty; pro přepočet, až se provoz změní. Ověřeno na x1: 216/264/abc/„-20 hold"/1 → ERR; 6 → saved → reboot → 6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29ef420486
commit
2386504e2d
4 files changed
+37
-15
No files matched your search
@@ -483,11 +483,15 @@ bool identHandleCommand(const char* command, char* reply) {
|
||||
|| (p >= 2 && p <= 8);
|
||||
}
|
||||
|
||||
static void bleConnTxPowerPersist(int8_t p) {
|
||||
// true when the value will come back after a reboot
|
||||
static bool bleConnTxPowerPersist(int8_t p) {
|
||||
InternalFS.remove(BLE_PWR_FILE); // FILE_O_WRITE appends; start clean
|
||||
if (p == RPT_BLE_CONN_TX_POWER) return; // default needs no file
|
||||
if (p == RPT_BLE_CONN_TX_POWER) return true; // default needs no file
|
||||
auto f = InternalFS.open(BLE_PWR_FILE, Adafruit_LittleFS_Namespace::FILE_O_WRITE);
|
||||
if (f) { f.write((uint8_t)p); f.close(); }
|
||||
if (!f) return false;
|
||||
bool ok = f.write((uint8_t)p) == 1;
|
||||
f.close();
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int8_t bleConnTxPowerLoad() {
|
||||
@@ -543,20 +547,28 @@ bool identHandleCommand(const char* command, char* reply) {
|
||||
// rejects anything else, hence the applied/failed count in the reply.
|
||||
if (memcmp(command, "blepwr", 6) == 0 && (command[6] == 0 || command[6] == ' ')) {
|
||||
if (command[6] == ' ') {
|
||||
int8_t p = (int8_t) atoi(&command[7]);
|
||||
// strict parse: now that the value is saved, a typo must not become
|
||||
// permanent (atoi turned "216" into -40 and "abc" into 0)
|
||||
char* end;
|
||||
long v = strtol(&command[7], &end, 10);
|
||||
if (end == &command[7] || *end != 0 || !bleConnTxPowerValid((int) v)) {
|
||||
strcpy(reply, "ERR - blepwr <dBm>: -40,-20,-16,-12,-8,-4,0,2..8");
|
||||
return true;
|
||||
}
|
||||
int8_t p = (int8_t) v;
|
||||
int live = 0;
|
||||
int ok = bleApplyConnTxPower(p, &live);
|
||||
// only latch a value the radio actually accepted, otherwise the next
|
||||
// reconnect would silently re-apply a bogus one
|
||||
bool applied = (live == 0 || ok > 0);
|
||||
// with no live connection nothing has vetted the value yet
|
||||
if (live == 0 && !bleConnTxPowerValid(p)) applied = false;
|
||||
bool saved = false;
|
||||
if (applied) {
|
||||
ble_conn_tx_power = p;
|
||||
bleConnTxPowerPersist(p);
|
||||
saved = bleConnTxPowerPersist(p);
|
||||
}
|
||||
sprintf(reply, "%s - BLE conn tx %d dBm (%d/%d conn)%s",
|
||||
applied ? "OK" : "ERR", (int) p, ok, live, applied ? ", saved" : "");
|
||||
applied ? "OK" : "ERR", (int) p, ok, live,
|
||||
applied ? (saved ? ", saved" : ", NOT saved") : "");
|
||||
} else {
|
||||
sprintf(reply, "BLE conn tx: %d dBm, adv tx: %d dBm",
|
||||
(int) ble_conn_tx_power, (int) Bluefruit.getTxPower());
|
||||
|
||||
Reference in new issue
Block a user