fix(mesh): markSeen je zase idempotentní, jinak si send path ujídá dedup okno
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f6e47f062b
commit
5230f5efb2
2 files changed
+49
No files matched your search
@@ -52,6 +52,23 @@ public:
|
||||
void markSeen(const mesh::Packet* packet) override {
|
||||
uint8_t hash[MAX_HASH_SIZE];
|
||||
packet->calculatePacketHash(hash);
|
||||
|
||||
// CUSTOM (TeTeHacko): idempotent, the way the single hasSeen() this replaced
|
||||
// was -- that one inserted only when the hash was absent. 1.17 split it into
|
||||
// wasSeen() + markSeen(), and while every receive-side caller still gates on
|
||||
// !wasSeen(), the SEND paths (Mesh::sendFlood, sendDirect, sendZeroHop) call
|
||||
// this one unguarded. Every re-send of the same packet then occupies another
|
||||
// slot of a fixed 160-entry ring, which shortens the dedup window and lets a
|
||||
// late echo of our own flood read as new traffic -- and on a repeater that
|
||||
// means rebroadcasting it.
|
||||
//
|
||||
// Cost is one extra 160x8 byte scan per send, which is nothing against LoRa
|
||||
// airtime. Fix taken from ALLFATHER-BV/meshcomod e62be9b (MIT).
|
||||
const uint8_t* sp = _hashes;
|
||||
for (int i = 0; i < MAX_PACKET_HASHES; i++, sp += MAX_HASH_SIZE) {
|
||||
if (memcmp(hash, sp, MAX_HASH_SIZE) == 0) return; // already recorded
|
||||
}
|
||||
|
||||
memcpy(&_hashes[_next_idx * MAX_HASH_SIZE], hash, MAX_HASH_SIZE);
|
||||
_next_idx = (_next_idx + 1) % MAX_PACKET_HASHES;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,38 @@ TEST(SimpleMeshTables, Clear_RemovesSeenPacket) {
|
||||
EXPECT_FALSE(t.wasSeen(&p));
|
||||
}
|
||||
|
||||
// ── markSeen is idempotent ───────────────────────────────────────────
|
||||
//
|
||||
// The send paths (Mesh::sendFlood, sendDirect, sendZeroHop) call markSeen()
|
||||
// without a wasSeen() gate, so a packet sent more than once must not occupy more
|
||||
// than one slot of the fixed ring -- that would shorten the dedup window for
|
||||
// every other packet and let a late echo of our own flood read as new traffic.
|
||||
|
||||
TEST(SimpleMeshTables, MarkSeen_Repeated_DoesNotEvictOlderEntries) {
|
||||
SimpleMeshTables t;
|
||||
Packet older = makeFloodPacket(0x01);
|
||||
Packet resent = makeFloodPacket(0x02);
|
||||
|
||||
t.markSeen(&older);
|
||||
for (int i = 0; i < MAX_PACKET_HASHES * 2; i++) {
|
||||
t.markSeen(&resent); // one packet, sent over and over
|
||||
}
|
||||
|
||||
EXPECT_TRUE(t.wasSeen(&older)); // must not have been pushed out of the ring
|
||||
EXPECT_TRUE(t.wasSeen(&resent));
|
||||
}
|
||||
|
||||
TEST(SimpleMeshTables, MarkSeen_Repeated_StillClearsInOneCall) {
|
||||
SimpleMeshTables t;
|
||||
Packet p = makeFloodPacket(0x01);
|
||||
|
||||
t.markSeen(&p);
|
||||
t.markSeen(&p);
|
||||
t.clear(&p); // clear() removes the first match only
|
||||
|
||||
EXPECT_FALSE(t.wasSeen(&p));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
||||
Reference in new issue
Block a user