Skip to content

Commit 87c78a9

Browse files
author
realtag
committed
discover.neighbors sends a tagged repeater discovery request and only accepts matching repeater responses
1 parent e8785dd commit 87c78a9

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

examples/simple_repeater/MyMesh.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,16 @@ void MyMesh::onControlDataRecv(mesh::Packet* packet) {
748748
return;
749749
}
750750

751+
if (pending_discover_tag == 0 || millisHasNowPassed(pending_discover_until)) {
752+
pending_discover_tag = 0;
753+
return;
754+
}
755+
uint32_t tag;
756+
memcpy(&tag, &packet->payload[2], 4);
757+
if (tag != pending_discover_tag) {
758+
return;
759+
}
760+
751761
mesh::Identity id(&packet->payload[6]);
752762
if (id.matches(self_id)) {
753763
return;
@@ -763,6 +773,8 @@ void MyMesh::sendNodeDiscoverReq() {
763773
data[0] = CTL_TYPE_NODE_DISCOVER_REQ; // prefix_only=0
764774
data[1] = (1 << ADV_TYPE_REPEATER);
765775
getRNG()->random(&data[2], 4); // tag
776+
memcpy(&pending_discover_tag, &data[2], 4);
777+
pending_discover_until = futureMillis(30000);
766778
uint32_t since = 0;
767779
memcpy(&data[6], &since, 4);
768780

@@ -832,6 +844,9 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
832844
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;
833845

834846
_prefs.adc_multiplier = 0.0f; // 0.0f means use default board multiplier
847+
848+
pending_discover_tag = 0;
849+
pending_discover_until = 0;
835850
}
836851

837852
void MyMesh::begin(FILESYSTEM *fs) {
@@ -1199,11 +1214,11 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
11991214
} else {
12001215
strcpy(reply, "Err - ??");
12011216
}
1202-
} else if (memcmp(command, "discover", 8) == 0) {
1203-
const char* sub = command + 8;
1217+
} else if (memcmp(command, "discover.neighbors", 18) == 0) {
1218+
const char* sub = command + 18;
12041219
while (*sub == ' ') sub++;
12051220
if (*sub != 0) {
1206-
strcpy(reply, "Err - discover has no options");
1221+
strcpy(reply, "Err - discover.neighbors has no options");
12071222
} else {
12081223
sendNodeDiscoverReq();
12091224
strcpy(reply, "OK - Discover sent");

examples/simple_repeater/MyMesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
9797
RegionEntry* load_stack[8];
9898
RegionEntry* recv_pkt_region;
9999
RateLimiter discover_limiter, anon_limiter;
100+
uint32_t pending_discover_tag;
101+
unsigned long pending_discover_until;
100102
bool region_load_active;
101103
unsigned long dirty_contacts_expiry;
102104
#if MAX_NEIGHBOURS

0 commit comments

Comments
 (0)