From 2d5016bac3f2871cff8af730f3ff46998b1518a9 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Mon, 25 Aug 2025 23:45:50 +1200 Subject: [PATCH 1/3] add ability to remove neighbour via cli --- examples/simple_repeater/main.cpp | 11 +++++++++++ src/helpers/CommonCLI.cpp | 11 +++++++++++ src/helpers/CommonCLI.h | 1 + 3 files changed, 23 insertions(+) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 622a05543..ea3f7de62 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -719,6 +719,17 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { *dp = 0; // null terminator } + void removeNeighbor(const uint8_t* pubkey, int key_len) override { +#if MAX_NEIGHBOURS + for (int i = 0; i < MAX_NEIGHBOURS; i++) { + NeighbourInfo* neighbour = &neighbours[i]; + if(memcmp(neighbour->id.pub_key, pubkey, key_len) == 0){ + neighbours[i] = {}; // clear neighbour entry + } + } +#endif + } + mesh::LocalIdentity& getSelfId() override { return self_id; } void clearStats() override { diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 2abb4f7c6..083fe2b76 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -165,6 +165,17 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch } } else if (memcmp(command, "neighbors", 9) == 0) { _callbacks->formatNeighborsReply(reply); + } else if (memcmp(command, "neighbor.remove ", 16) == 0) { + const char* hex = &command[16]; + uint8_t pubkey[PUB_KEY_SIZE]; + int hex_len = min(strlen(hex), PUB_KEY_SIZE*2); + int pubkey_len = hex_len / 2; + if (mesh::Utils::fromHex(pubkey, pubkey_len, hex)) { + _callbacks->removeNeighbor(pubkey, pubkey_len); + strcpy(reply, "OK"); + } else { + strcpy(reply, "ERR: bad pubkey"); + } } else if (memcmp(command, "tempradio ", 10) == 0) { strcpy(tmp, &command[10]); const char *parts[5]; diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 92deb7186..3bf71b5aa 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -43,6 +43,7 @@ class CommonCLICallbacks { virtual void dumpLogFile() = 0; virtual void setTxPower(uint8_t power_dbm) = 0; virtual void formatNeighborsReply(char *reply) = 0; + virtual void removeNeighbor(const uint8_t* pubkey, int key_len) = 0; virtual mesh::LocalIdentity& getSelfId() = 0; virtual void clearStats() = 0; virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0; From c49ecc121e4228e35636fedac73c28d791d58084 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Fri, 29 Aug 2025 18:08:06 +1200 Subject: [PATCH 2/3] use new instance of neighbour info object when removing neighbour --- examples/simple_repeater/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index ea3f7de62..81c4d4555 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -724,7 +724,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { for (int i = 0; i < MAX_NEIGHBOURS; i++) { NeighbourInfo* neighbour = &neighbours[i]; if(memcmp(neighbour->id.pub_key, pubkey, key_len) == 0){ - neighbours[i] = {}; // clear neighbour entry + neighbours[i] = NeighbourInfo(); // clear neighbour entry } } #endif From 9ee01520845599a3820f0a1f0eb6ee1e0afe4f7c Mon Sep 17 00:00:00 2001 From: liamcottle Date: Fri, 29 Aug 2025 18:17:01 +1200 Subject: [PATCH 3/3] add default no op implementation for remove neighbor function --- src/helpers/CommonCLI.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/CommonCLI.h b/src/helpers/CommonCLI.h index 3bf71b5aa..d1e498730 100644 --- a/src/helpers/CommonCLI.h +++ b/src/helpers/CommonCLI.h @@ -43,7 +43,9 @@ class CommonCLICallbacks { virtual void dumpLogFile() = 0; virtual void setTxPower(uint8_t power_dbm) = 0; virtual void formatNeighborsReply(char *reply) = 0; - virtual void removeNeighbor(const uint8_t* pubkey, int key_len) = 0; + virtual void removeNeighbor(const uint8_t* pubkey, int key_len) { + // no op by default + }; virtual mesh::LocalIdentity& getSelfId() = 0; virtual void clearStats() = 0; virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;