From b11f43987b2a423c13bec1c701d5fa340dad58ae Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Fri, 16 May 2025 19:57:09 +1000 Subject: [PATCH] * companion: fix for importContact(). Now removes the packet-hash from table, before 'replaying' --- src/Mesh.h | 1 + src/helpers/BaseChatMesh.cpp | 1 + src/helpers/SimpleMeshTables.h | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/Mesh.h b/src/Mesh.h index cb81f8de..9649187c 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -16,6 +16,7 @@ public: class MeshTables { public: virtual bool hasSeen(const Packet* packet) = 0; + virtual void clear(const Packet* packet) = 0; // remove this packet hash from table }; /** diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index b6be2582..36ddcbb4 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -373,6 +373,7 @@ bool BaseChatMesh::importContact(const uint8_t src_buf[], uint8_t len) { if (pkt) { if (pkt->readFrom(src_buf, len) && pkt->getPayloadType() == PAYLOAD_TYPE_ADVERT) { pkt->header |= ROUTE_TYPE_FLOOD; // simulate it being received flood-mode + getTables()->clear(pkt); // remove packet hash from table, so we can receive/process it again _pendingLoopback = pkt; // loop-back, as if received over radio return true; // success } else { diff --git a/src/helpers/SimpleMeshTables.h b/src/helpers/SimpleMeshTables.h index 910b8071..2f8af52a 100644 --- a/src/helpers/SimpleMeshTables.h +++ b/src/helpers/SimpleMeshTables.h @@ -80,6 +80,30 @@ public: return false; } + void clear(const mesh::Packet* packet) override { + if (packet->getPayloadType() == PAYLOAD_TYPE_ACK) { + uint32_t ack; + memcpy(&ack, packet->payload, 4); + for (int i = 0; i < MAX_PACKET_ACKS; i++) { + if (ack == _acks[i]) { + _acks[i] = 0; + break; + } + } + } else { + uint8_t hash[MAX_HASH_SIZE]; + packet->calculatePacketHash(hash); + + 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) { + memset(sp, 0, MAX_HASH_SIZE); + break; + } + } + } + } + uint32_t getNumDirectDups() const { return _direct_dups; } uint32_t getNumFloodDups() const { return _flood_dups; }