mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
48 lines
1 KiB
C++
48 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <Mesh.h>
|
|
|
|
#ifdef ESP32
|
|
#include <FS.h>
|
|
#endif
|
|
|
|
#define MAX_PACKET_HASHES 128
|
|
|
|
class SimpleMeshTables : public mesh::MeshTables {
|
|
uint8_t _hashes[MAX_PACKET_HASHES*MAX_HASH_SIZE];
|
|
int _next_idx;
|
|
|
|
public:
|
|
SimpleMeshTables() {
|
|
memset(_hashes, 0, sizeof(_hashes));
|
|
_next_idx = 0;
|
|
}
|
|
|
|
#ifdef ESP32
|
|
void restoreFrom(File f) {
|
|
f.read(_hashes, sizeof(_hashes));
|
|
f.read((uint8_t *) &_next_idx, sizeof(_next_idx));
|
|
}
|
|
void saveTo(File f) {
|
|
f.write(_hashes, sizeof(_hashes));
|
|
f.write((const uint8_t *) &_next_idx, sizeof(_next_idx));
|
|
}
|
|
#endif
|
|
|
|
bool hasSeen(const mesh::Packet* packet) override {
|
|
uint8_t hash[MAX_HASH_SIZE];
|
|
packet->calculatePacketHash(hash);
|
|
|
|
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 true;
|
|
}
|
|
|
|
memcpy(&_hashes[_next_idx*MAX_HASH_SIZE], hash, MAX_HASH_SIZE);
|
|
_next_idx = (_next_idx + 1) % MAX_PACKET_HASHES; // cyclic table
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
};
|