Add configurable max hops filter for auto-add contacts - #1900
Conversation
Filter auto-add of new contacts by hop count (issues meshcore-dev#1533, meshcore-dev#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>
|
Hey, Thanks for the PR! This looks pretty good to me, nice and simple. Currently, the PR uses zero to indicate no limit, since the preferences are always initialized to zero by default. We could possibly fetch the value from prefs, and if it's 1 or higher, we know we have a limit set, but, subtract 1 from that value to indicate what the limit is. This would allow for enforcing auto add of direct/zero hop contacts too, as well as any other hop limit is desired. Options would be:
Since it's a protocol/companion level thing, it's up to the clients/apps to know that it works this way. Ideally, we would use something like -1 or 255 as no limit, and 0 as 0-hop and 1 as 1-hop, but this is just a limitation in the firmware where all values are zero by default. |
- Change > to >= so stored value 1 means direct/0-hop only (liamcottle) - Clamp max_hops to 63 on write since getPathHashCount() caps at 63 (robekl) - Update comments to reflect encoding: 0=no limit, 1=direct only, N=up to N-1 hops Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Thanks! Good call - implemented. The encoding is now: 0 = no limit |
65bbab9 to
1d190ad
Compare
Add configurable max hops filter for auto-add contacts
Closes #1533, relates to #1546
Problem
Devices auto-add every contact they hear, regardless of distance. In dense or wide meshes this fills the contact list with far-away nodes that are unreliable to reach, pushing out closer, more useful contacts.
Solution
Add a
autoadd_max_hopssetting that filters auto-add by hop count. Only new contacts within the configured hop limit are auto-added. Value0means no limit (current behavior, the default).onDiscoveredContact()is called so the companion app UI can show them, they just aren't persisted to the contact listCMD_SET/GET_AUTOADD_CONFIGprotocol with an optional 3rd byteProtocol change
CMD_SET_AUTOADD_CONFIG(0x3A):[cmd] [config_bitmask](2 bytes)[cmd] [config_bitmask] [max_hops](3 bytes, 3rd byte optional)CMD_GET_AUTOADD_CONFIGresponse:[resp_code] [config_bitmask](2 bytes)[resp_code] [config_bitmask] [max_hops](3 bytes)Backwards compatible — old companion apps send 2 bytes (max_hops stays 0), and ignore the extra response byte per the length-prefixed frame protocol.
Files changed
src/helpers/BaseChatMesh.hvirtual getAutoAddMaxHops()(default 0)src/helpers/BaseChatMesh.cpponAdvertRecv()for new contactsexamples/companion_radio/NodePrefs.hautoadd_max_hopsfieldexamples/companion_radio/DataStore.cppexamples/companion_radio/MyMesh.hexamples/companion_radio/MyMesh.cppTesting
heltec_v4_companion_radio_usb(ESP32-S3)file.read()fails silently, field stays 0 viamemsetin constructor