Merge pull request #1495 from oltaco/esp32-advblob-removal

Fix unlimited advert blob growth on ESP32
This commit is contained in:
ripplebiz
2026-02-01 13:37:28 +11:00
committed by GitHub
4 changed files with 23 additions and 9 deletions

View File

@@ -560,14 +560,20 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
} }
return false; // error return false; // error
} }
bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
return true; // this is just a stub on NRF52/STM32 platforms
}
#else #else
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) { inline void makeBlobPath(const uint8_t key[], int key_len, char* path, size_t path_size) {
char path[64];
char fname[18]; char fname[18];
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix) if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
mesh::Utils::toHex(fname, key, key_len); mesh::Utils::toHex(fname, key, key_len);
sprintf(path, "/bl/%s", fname); sprintf(path, "/bl/%s", fname);
}
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
char path[64];
makeBlobPath(key, key_len, path, sizeof(path));
if (_fs->exists(path)) { if (_fs->exists(path)) {
File f = openRead(_fs, path); File f = openRead(_fs, path);
@@ -582,11 +588,7 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b
bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len) { bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len) {
char path[64]; char path[64];
char fname[18]; makeBlobPath(key, key_len, path, sizeof(path));
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
mesh::Utils::toHex(fname, key, key_len);
sprintf(path, "/bl/%s", fname);
File f = openWrite(_fs, path); File f = openWrite(_fs, path);
if (f) { if (f) {
@@ -598,4 +600,13 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
} }
return false; // error return false; // error
} }
bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
char path[64];
makeBlobPath(key, key_len, path, sizeof(path));
_fs->remove(path);
return true; // return true even if file did not exist
}
#endif #endif

View File

@@ -42,6 +42,7 @@ public:
void migrateToSecondaryFS(); void migrateToSecondaryFS();
uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]); uint8_t getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]);
bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len); bool putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len);
bool deleteBlobByKey(const uint8_t key[], int key_len);
File openRead(const char* filename); File openRead(const char* filename);
File openRead(FILESYSTEM* fs, const char* filename); File openRead(FILESYSTEM* fs, const char* filename);
bool removeFile(const char* filename); bool removeFile(const char* filename);

View File

@@ -307,6 +307,7 @@ bool MyMesh::shouldOverwriteWhenFull() const {
} }
void MyMesh::onContactOverwrite(const uint8_t* pub_key) { void MyMesh::onContactOverwrite(const uint8_t* pub_key) {
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
if (_serial->isConnected()) { if (_serial->isConnected()) {
out_frame[0] = PUSH_CODE_CONTACT_DELETED; out_frame[0] = PUSH_CODE_CONTACT_DELETED;
memcpy(&out_frame[1], pub_key, PUB_KEY_SIZE); memcpy(&out_frame[1], pub_key, PUB_KEY_SIZE);
@@ -1124,6 +1125,7 @@ void MyMesh::handleCmdFrame(size_t len) {
uint8_t *pub_key = &cmd_frame[1]; uint8_t *pub_key = &cmd_frame[1];
ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE); ContactInfo *recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
if (recipient && removeContact(*recipient)) { if (recipient && removeContact(*recipient)) {
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE);
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
writeOKFrame(); writeOKFrame();
} else { } else {

View File

@@ -131,7 +131,6 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
plen = packet->writeTo(temp_buf); plen = packet->writeTo(temp_buf);
packet->header = save; packet->header = save;
} }
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
bool is_new = false; // true = not in contacts[], false = exists in contacts[] bool is_new = false; // true = not in contacts[], false = exists in contacts[]
if (from == NULL) { if (from == NULL) {
@@ -157,6 +156,7 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
from->shared_secret_valid = false; from->shared_secret_valid = false;
} }
// update // update
putBlobByKey(id.pub_key, PUB_KEY_SIZE, temp_buf, plen);
StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name)); StrHelper::strncpy(from->name, parser.getName(), sizeof(from->name));
from->type = parser.getType(); from->type = parser.getType();
if (parser.hasLatLon()) { if (parser.hasLatLon()) {