* companion: fix for importContact(). Now removes the packet-hash from table, before 'replaying'

This commit is contained in:
Scott Powell
2025-05-16 19:57:09 +10:00
parent 1680eb29aa
commit b11f43987b
3 changed files with 26 additions and 0 deletions

View File

@@ -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
};
/**

View File

@@ -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 {

View File

@@ -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; }