Skip to content

Commit d012dc7

Browse files
authored
Merge pull request #663 from liamcottle/feature/remove-neighbour
Add CLI command to remove neighbour
2 parents f9f1c2e + 9ee0152 commit d012dc7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

examples/simple_repeater/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,17 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
719719
*dp = 0; // null terminator
720720
}
721721

722+
void removeNeighbor(const uint8_t* pubkey, int key_len) override {
723+
#if MAX_NEIGHBOURS
724+
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
725+
NeighbourInfo* neighbour = &neighbours[i];
726+
if(memcmp(neighbour->id.pub_key, pubkey, key_len) == 0){
727+
neighbours[i] = NeighbourInfo(); // clear neighbour entry
728+
}
729+
}
730+
#endif
731+
}
732+
722733
mesh::LocalIdentity& getSelfId() override { return self_id; }
723734

724735
void clearStats() override {

src/helpers/CommonCLI.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
165165
}
166166
} else if (memcmp(command, "neighbors", 9) == 0) {
167167
_callbacks->formatNeighborsReply(reply);
168+
} else if (memcmp(command, "neighbor.remove ", 16) == 0) {
169+
const char* hex = &command[16];
170+
uint8_t pubkey[PUB_KEY_SIZE];
171+
int hex_len = min(strlen(hex), PUB_KEY_SIZE*2);
172+
int pubkey_len = hex_len / 2;
173+
if (mesh::Utils::fromHex(pubkey, pubkey_len, hex)) {
174+
_callbacks->removeNeighbor(pubkey, pubkey_len);
175+
strcpy(reply, "OK");
176+
} else {
177+
strcpy(reply, "ERR: bad pubkey");
178+
}
168179
} else if (memcmp(command, "tempradio ", 10) == 0) {
169180
strcpy(tmp, &command[10]);
170181
const char *parts[5];

src/helpers/CommonCLI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class CommonCLICallbacks {
4343
virtual void dumpLogFile() = 0;
4444
virtual void setTxPower(uint8_t power_dbm) = 0;
4545
virtual void formatNeighborsReply(char *reply) = 0;
46+
virtual void removeNeighbor(const uint8_t* pubkey, int key_len) {
47+
// no op by default
48+
};
4649
virtual mesh::LocalIdentity& getSelfId() = 0;
4750
virtual void clearStats() = 0;
4851
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;

0 commit comments

Comments
 (0)