Browse Source
Merge pull request #1900 from wbijen/feature/contact-filter-by-hops
Add configurable max hops filter for auto-add contacts
pull/1350/head
ripplebiz
3 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
23 additions and
1 deletions
-
examples/companion_radio/DataStore.cpp
-
examples/companion_radio/MyMesh.cpp
-
examples/companion_radio/MyMesh.h
-
examples/companion_radio/NodePrefs.h
-
src/helpers/BaseChatMesh.cpp
-
src/helpers/BaseChatMesh.h
|
|
|
@ -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_interval, sizeof(_prefs.gps_interval)); // 86
|
|
|
|
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(); |
|
|
|
} |
|
|
|
@ -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_interval, sizeof(_prefs.gps_interval)); // 86
|
|
|
|
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(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -318,6 +318,10 @@ bool MyMesh::shouldOverwriteWhenFull() const { |
|
|
|
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) { |
|
|
|
_store->deleteBlobByKey(pub_key, PUB_KEY_SIZE); // delete from storage
|
|
|
|
if (_serial->isConnected()) { |
|
|
|
@ -1785,12 +1789,16 @@ void MyMesh::handleCmdFrame(size_t len) { |
|
|
|
} |
|
|
|
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) { |
|
|
|
_prefs.autoadd_config = cmd_frame[1]; |
|
|
|
if (len >= 3) { |
|
|
|
_prefs.autoadd_max_hops = min(cmd_frame[2], (uint8_t)64); |
|
|
|
} |
|
|
|
savePrefs(); |
|
|
|
writeOKFrame(); |
|
|
|
writeOKFrame(); |
|
|
|
} else if (cmd_frame[0] == CMD_GET_AUTOADD_CONFIG) { |
|
|
|
int i = 0; |
|
|
|
out_frame[i++] = RESP_CODE_AUTOADD_CONFIG; |
|
|
|
out_frame[i++] = _prefs.autoadd_config; |
|
|
|
out_frame[i++] = _prefs.autoadd_max_hops; |
|
|
|
_serial->writeFrame(out_frame, i); |
|
|
|
} else if (cmd_frame[0] == CMD_GET_ALLOWED_REPEAT_FREQ) { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
@ -119,6 +119,7 @@ protected: |
|
|
|
bool isAutoAddEnabled() const override; |
|
|
|
bool shouldAutoAddContactType(uint8_t type) const override; |
|
|
|
bool shouldOverwriteWhenFull() const override; |
|
|
|
uint8_t getAutoAddMaxHops() const override; |
|
|
|
void onContactsFull() 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; |
|
|
|
|
|
|
|
@ -30,4 +30,5 @@ struct NodePrefs { // persisted to file |
|
|
|
uint8_t autoadd_config; // bitmask for auto-add contacts config
|
|
|
|
uint8_t client_repeat; |
|
|
|
uint8_t path_hash_mode; // which path mode to use when sending
|
|
|
|
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops (max 64)
|
|
|
|
}; |
|
|
|
@ -141,6 +141,15 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// check hop limit for new contacts (0 = no limit, 1 = direct (0 hops), N = up to N-1 hops)
|
|
|
|
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(); |
|
|
|
if (from == NULL) { |
|
|
|
ContactInfo ci; |
|
|
|
|
|
|
|
@ -98,6 +98,7 @@ protected: |
|
|
|
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; } |
|
|
|
virtual void onContactsFull() {}; |
|
|
|
virtual bool shouldOverwriteWhenFull() const { return false; } |
|
|
|
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops
|
|
|
|
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 ContactInfo* processAck(const uint8_t *data) = 0; |
|
|
|
|