Skip to content

Commit c016db8

Browse files
wbijenclaude
andcommitted
Address PR review: subtract-1 encoding and clamp max_hops
- 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>
1 parent 0056674 commit c016db8

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

examples/companion_radio/MyMesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ void MyMesh::handleCmdFrame(size_t len) {
17901790
} else if (cmd_frame[0] == CMD_SET_AUTOADD_CONFIG) {
17911791
_prefs.autoadd_config = cmd_frame[1];
17921792
if (len >= 3) {
1793-
_prefs.autoadd_max_hops = cmd_frame[2];
1793+
_prefs.autoadd_max_hops = min(cmd_frame[2], (uint8_t)63);
17941794
}
17951795
savePrefs();
17961796
writeOKFrame();

examples/companion_radio/NodePrefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ struct NodePrefs { // persisted to file
3030
uint8_t autoadd_config; // bitmask for auto-add contacts config
3131
uint8_t client_repeat;
3232
uint8_t path_hash_mode; // which path mode to use when sending
33-
uint8_t autoadd_max_hops; // 0 = no limit, 1-63 = max hops for auto-add
33+
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct only, N = up to N-1 hops (max 63)
3434
};

src/helpers/BaseChatMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ void BaseChatMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
141141
return;
142142
}
143143

144-
// check hop limit for new contacts (0 = no limit)
144+
// check hop limit for new contacts (0 = no limit, 1 = direct only, N = up to N-1 hops)
145145
uint8_t max_hops = getAutoAddMaxHops();
146-
if (max_hops > 0 && packet->getPathHashCount() > max_hops) {
146+
if (max_hops > 0 && packet->getPathHashCount() >= max_hops) {
147147
ContactInfo ci;
148148
populateContactFromAdvert(ci, id, parser, timestamp);
149149
onDiscoveredContact(ci, true, packet->path_len, packet->path); // let UI know

src/helpers/BaseChatMesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class BaseChatMesh : public mesh::Mesh {
9898
virtual bool shouldAutoAddContactType(uint8_t type) const { return true; }
9999
virtual void onContactsFull() {};
100100
virtual bool shouldOverwriteWhenFull() const { return false; }
101-
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1-63 = max hops for auto-add
101+
virtual uint8_t getAutoAddMaxHops() const { return 0; } // 0 = no limit, 1 = direct only, N = up to N-1 hops
102102
virtual void onContactOverwrite(const uint8_t* pub_key) {};
103103
virtual void onDiscoveredContact(ContactInfo& contact, bool is_new, uint8_t path_len, const uint8_t* path) = 0;
104104
virtual ContactInfo* processAck(const uint8_t *data) = 0;

0 commit comments

Comments
 (0)