mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-07-16 21:02:21 +00:00
hasSeen() was simultaneously a predicate and a mutator — it inserted the packet hash on every miss, making five call sites that only wanted to mark a packet as sent call it with the return value discarded. Split into: - wasSeen() — pure predicate, no side effects - markSeen() — explicit insert All query sites now call markSeen() immediately after wasSeen() returns false, preserving identical runtime behaviour. The five mark-only send sites (sendFlood, sendDirect, sendZeroHop x2) now call markSeen directly. Also fixes three bridge sites (BridgeBase, ESPNowBridge, RS232Bridge) that had the same query+implicit-insert pattern. Tests: add test/test_mesh_tables/ covering wasSeen purity, markSeen, dup stats, and clear. Update SHA256 mock to produce deterministic output (previously finalize() was a no-op). Add Packet.cpp to native build filter.
36 lines
994 B
C++
36 lines
994 B
C++
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
// Mock SHA256 for native testing — deterministic but not cryptographic.
|
|
// finalize() writes real (non-garbage) output so calculatePacketHash() produces
|
|
// distinguishable results for packets with different payloads.
|
|
#include <string.h>
|
|
|
|
class SHA256 {
|
|
uint8_t _state[32];
|
|
size_t _len;
|
|
public:
|
|
SHA256() : _len(0) { memset(_state, 0, sizeof(_state)); }
|
|
|
|
void update(const void* data, size_t len) {
|
|
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
|
for (size_t i = 0; i < len; i++) {
|
|
uint8_t b = bytes[i];
|
|
_state[_len % 32] ^= b;
|
|
_state[(_len + 1) % 32] += (uint8_t)((b >> 1) | (b << 7));
|
|
_len++;
|
|
}
|
|
}
|
|
|
|
void finalize(uint8_t* hash, size_t hashLen) {
|
|
for (size_t i = 0; i < hashLen; i++) {
|
|
hash[i] = _state[i % 32];
|
|
}
|
|
}
|
|
|
|
void resetHMAC(const uint8_t* key, size_t keyLen) {}
|
|
void finalizeHMAC(const uint8_t* key, size_t keyLen, uint8_t* hash, size_t hashLen) {}
|
|
};
|