fix(mesh): markSeen je zase idempotentní, jinak si send path ujídá dedup okno
1.17 rozdělil původní `hasSeen()` -- který hash vkládal jen tehdy, když v tabulce nebyl -- na `wasSeen()` + `markSeen()`, a ten druhý vkládá bezpodmínečně. Na příjmu se nic nezměnilo, tam je každé volání pod `!wasSeen()`. Jenže SEND cesty (`Mesh::sendFlood`, `sendDirect`, `sendZeroHop`) volají `markSeen()` bez brzdy, takže každé opakované odeslání téhož paketu zabere další slot ze 160položkového kruhu. Dopady jsou dva. Kruh se plní rychleji, takže se zkracuje dedup okno pro všechno ostatní a pozdní echo vlastního floodu se může přečíst jako nový provoz -- na repeateru to znamená, že ho přepošle. A `clear()` maže jen první nález, takže paket zapsaný dvakrát po jednom `clear()` zůstane "viděný". Cena je jeden sken 160x8 B navíc při odeslání, což je proti airtime nic. Testy pokrývají obojí a bez téhle změny oba padají. Převzato z ALLFATHER-BV/meshcomod e62be9b (MIT). Upstream to pořád má; tamní issues #35 a #53 (duplicitní zprávy) na to sedí. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cbf4cb3c4a
commit
a6288f63cf
2 files changed
+49
No files matched your search
@@ -52,6 +52,23 @@ public:
|
|||||||
void markSeen(const mesh::Packet* packet) override {
|
void markSeen(const mesh::Packet* packet) override {
|
||||||
uint8_t hash[MAX_HASH_SIZE];
|
uint8_t hash[MAX_HASH_SIZE];
|
||||||
packet->calculatePacketHash(hash);
|
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);
|
memcpy(&_hashes[_next_idx * MAX_HASH_SIZE], hash, MAX_HASH_SIZE);
|
||||||
_next_idx = (_next_idx + 1) % MAX_PACKET_HASHES;
|
_next_idx = (_next_idx + 1) % MAX_PACKET_HASHES;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,38 @@ TEST(SimpleMeshTables, Clear_RemovesSeenPacket) {
|
|||||||
EXPECT_FALSE(t.wasSeen(&p));
|
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) {
|
int main(int argc, char** argv) {
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
Reference in new issue
Block a user