fix(repeater/bot): cooldown per sender, not per channel
Reported symptom: "!link arrived only on the second try". Cause was the throttle itself -- one global 10 s window per channel, so a second person asking inside it got silence. That reads as a broken bot rather than "wait ten seconds", and it happened twice while testing. Now each sender has its own window, keyed on the "<name>: " prefix, over an 8-slot LRU. Spoofable by design and that is fine: this is politeness throttling, and a channel message carries no identity beyond that prefix anyway. The airtime guarantee that the global window used to provide is kept explicitly as BOT_MIN_GAP_MS (2.5 s floor between any two replies, whoever asked), so N senders can no longer produce N simultaneous transmissions. Without that, going per-sender would have quietly traded politeness for responsiveness. `bot` now reports both numbers plus a throttled counter, so a suppressed reply is visible instead of looking like a dead node. Bench-verified on the discriminating case, which is the whole point: sender A asking twice in 3.5 s gets one answer, while sender B asking INSIDE A's window gets answered -- 3/3. Note on how that was measured, because it bit me: reading the console counter costs ~2.4 s (the CDC needs a settle delay), so a probe pair with a counter read between them is ~15 s apart and the 10 s window has legitimately expired. The first run of this test "failed" for exactly that reason. Read counters only before and after a pair, never inside it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
27f1339ac9
commit
fc32a1a0a8
2 files changed
+64
-6
No files matched your search
@@ -211,11 +211,19 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
uint8_t pktfeed_stage_len; // 0 = nothing staged
|
||||
#endif
|
||||
#ifdef BOT_CHANNEL_PSK
|
||||
// Default zde, ne az v ChannelBot.h -- ten se includuje na konci MyMesh.cpp,
|
||||
// tedy dlouho po teto deklaraci pole.
|
||||
#ifndef BOT_PEER_SLOTS
|
||||
#define BOT_PEER_SLOTS 8
|
||||
#endif
|
||||
mesh::GroupChannel bot_channel; // 1 B hash + 32 B secret, derived from BOT_CHANNEL_PSK
|
||||
bool bot_channel_valid; // false = PSK malformed, bot silently off
|
||||
unsigned long bot_next_reply_at; // cooldown gate, 0 = not armed
|
||||
uint32_t bot_replies_sent;
|
||||
uint32_t bot_ignored; // zprav zahozenych podle BOT_IGNORE_SENDERS
|
||||
uint32_t bot_throttled; // odpovedi potlacenych cooldownem
|
||||
struct BotPeer { uint32_t name_hash; unsigned long next_at; };
|
||||
BotPeer bot_peers[BOT_PEER_SLOTS]; // per-odesilatel okno, LRU
|
||||
uint32_t bot_last_reply_secs; // RTC time of the last reply, 0 = never
|
||||
#endif
|
||||
CayenneLPP telemetry;
|
||||
@@ -257,6 +265,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
int botCommandReply(char* out, int max_len, const char* cmd, const mesh::Packet* pkt);
|
||||
int botScanCommands(char* out, int max_len, const char* text, const mesh::Packet* pkt);
|
||||
void botSendReply(const mesh::Packet* pkt, const char* text);
|
||||
bool botPeerAllowed(const char* name);
|
||||
bool botHandleCommand(const char* command, char* reply);
|
||||
#endif
|
||||
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
||||
|
||||
Reference in new issue
Block a user