mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Add configurable max hops filter for auto-add contacts
Filter auto-add of new contacts by hop count (issues #1533, #1546). Setting is configurable from the companion app via extended CMD_SET/GET_AUTOADD_CONFIG protocol (0 = no limit, 1-63 = max hops). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
06ab9f7f6b
commit
00566741f6
6 changed files with 23 additions and 1 deletions
|
|
@ -229,6 +229,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
||||||
file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
file.read((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
||||||
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
file.read((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
||||||
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
file.read((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
||||||
|
file.read((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
@ -265,6 +266,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
||||||
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
file.write((uint8_t *)&_prefs.gps_enabled, sizeof(_prefs.gps_enabled)); // 85
|
||||||
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
file.write((uint8_t *)&_prefs.gps_interval, sizeof(_prefs.gps_interval)); // 86
|
||||||
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
file.write((uint8_t *)&_prefs.autoadd_config, sizeof(_prefs.autoadd_config)); // 87
|
||||||
|
file.write((uint8_t *)&_prefs.autoadd_max_hops, sizeof(_prefs.autoadd_max_hops)); // 88
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,10 @@ bool MyMesh::shouldOverwriteWhenFull() const {
|
||||||
return (_prefs.autoadd_config & AUTO_ADD_OVERWRITE_OLDEST) != 0;
|
return (_prefs.autoadd_config & AUTO_ADD_OVERWRITE_OLDEST) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t MyMesh::getAutoAddMaxHops() const {
|
||||||
|
return _prefs.autoadd_max_hops;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
|
||||||
if (_serial->isConnected()) {
|
if (_serial->isConnected()) {
|
||||||
|
|
@ -1785,12 +1789,16 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||||
}
|
}
|
||||||
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) {
|
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) {
|
||||||
_prefs.autoadd_config = cmd_frame[1];
|
_prefs.autoadd_config = cmd_frame[1];
|
||||||
|
if (len >= 3) {
|
||||||
|
_prefs.autoadd_max_hops = cmd_frame[2];
|
||||||
|
}
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
} else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) {
|
} else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
out_frame[i++] = RESP_CODE_AUTOADD_CONFIG;
|
out_frame[i++] = RESP_CODE_AUTOADD_CONFIG;
|
||||||
out_frame[i++] = _prefs.autoadd_config;
|
out_frame[i++] = _prefs.autoadd_config;
|
||||||
|
out_frame[i++] = _prefs.autoadd_max_hops;
|
||||||
_serial->writeFrame(out_frame, i);
|
_serial->writeFrame(out_frame, i);
|
||||||
} else if (cmd_frame[0] == CMD_GET_ALLOWED_REPEAT_FREQ) {
|
} else if (cmd_frame[0] == CMD_GET_ALLOWED_REPEAT_FREQ) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,7 @@ protected:
|
||||||
bool isAutoAddEnabled() const override;
|
bool isAutoAddEnabled() const override;
|
||||||
bool shouldAutoAddContactType(uint8_t type) const override;
|
bool shouldAutoAddContactType(uint8_t type) const override;
|
||||||
bool shouldOverwriteWhenFull() const override;
|
bool shouldOverwriteWhenFull() const override;
|
||||||
|
uint8_t getAutoAddMaxHops() const override;
|
||||||
void onContactsFull() override;
|
void onContactsFull() override;
|
||||||
void onContactOverwrite(const uint8_t* pub_key) override;
|
void onContactOverwrite(const uint8_t* pub_key) override;
|
||||||
bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
bool onContactPathRecv(ContactInfo& from, uint8_t* in_path, uint8_t in_path_len, uint8_t* out_path, uint8_t out_path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,5 @@ struct NodePrefs { // persisted to file
|
||||||
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
||||||
uint8_t client_repeat;
|
uint8_t client_repeat;
|
||||||
uint8_t path_hash_mode; // which path mode to use when sending
|
uint8_t path_hash_mode; // which path mode to use when sending
|
||||||
|
uint8_t autoadd_max_hops; // 0 = no limit, 1-63 = max hops for auto-add
|
||||||
};
|
};
|
||||||
|
|
@ -141,6 +141,15 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check hop limit for new contacts (0 = no limit)
|
||||||
|
uint8_t max_hops = getAutoAddMaxHops();
|
||||||
|
if (max_hops > 0 && packet->getPathHashCount() > max_hops) {
|
||||||
|
ContactInfo ci;
|
||||||
|
populateContactFromAdvert(ci, id, parser, timestamp);
|
||||||
|
onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
from = allocateContactSlot();
|
from = allocateContactSlot();
|
||||||
if (from == NULL) {
|
if (from == NULL) {
|
||||||
ContactInfo ci;
|
ContactInfo ci;
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ protected:
|
||||||
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; }
|
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; }
|
||||||
virtual void onContactsFull() {};
|
virtual void onContactsFull() {};
|
||||||
virtual bool shouldOverwriteWhenFull() const { return false; }
|
virtual bool shouldOverwriteWhenFull() const { return false; }
|
||||||
|
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1-63 = max hops for auto-add
|
||||||
virtual void onContactOverwrite(const uint8_t* pub_key) {};
|
virtual void onContactOverwrite(const uint8_t* pub_key) {};
|
||||||
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
|
||||||
virtual ContactInfo* processAck(const uint8_t *data) = 0;
|
virtual ContactInfo* processAck(const uint8_t *data) = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue