From 5d917885df0cdb9489a0660a010281eda08d3fda Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 16 Nov 2023 06:57:22 -0600 Subject: [PATCH] Added Remove node by nodenum admin message (#2941) * Remove node by nodenum * It were backerds! DERP --- protobufs | 2 +- src/mesh/NodeDB.cpp | 14 ++++++++++++++ src/mesh/NodeDB.h | 2 +- src/mesh/generated/meshtastic/admin.pb.h | 4 ++++ src/mesh/generated/meshtastic/config.pb.h | 6 +++--- src/mesh/generated/meshtastic/deviceonly.pb.h | 2 +- src/mesh/generated/meshtastic/localonly.pb.h | 2 +- src/modules/AdminModule.cpp | 6 ++++++ 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/protobufs b/protobufs index 59a67810c..c845b7848 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 59a67810ca07b731839cf1b44b142778fa55b5bf +Subproject commit c845b7848eebb11150ca0427773303bf8758e533 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 2046c2cea..151888746 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -323,6 +323,20 @@ void NodeDB::resetNodes() neighborInfoModule->resetNeighbors(); } +void NodeDB::removeNodeByNum(uint nodeNum) +{ + int newPos = 0, removed = 0; + for (int i = 0; i < *numMeshNodes; i++) { + if (meshNodes[i].num != nodeNum) + meshNodes[newPos++] = meshNodes[i]; + else + removed++; + } + *numMeshNodes -= removed; + LOG_DEBUG("NodeDB::removeNodeByNum purged %d entries. Saving changes...\n", removed); + saveDeviceStateToDisk(); +} + void NodeDB::cleanupMeshDB() { int newPos = 0, removed = 0; diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 5fca0e440..5e4dc4885 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -111,7 +111,7 @@ class NodeDB /// Return the number of nodes we've heard from recently (within the last 2 hrs?) size_t getNumOnlineMeshNodes(); - void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(); + void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(), removeNodeByNum(uint nodeNum); bool factoryReset(); diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index 38248d94a..9978c5591 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -145,6 +145,8 @@ typedef struct _meshtastic_AdminMessage { char set_canned_message_module_messages[201]; /* Set the ringtone for ExternalNotification. */ char set_ringtone_message[231]; + /* Remove the node by the specified node-num from the NodeDB on the device */ + uint32_t remove_by_nodenum; /* Begins an edit transaction for config, module config, owner, and channel settings changes This will delay the standard *implicit* save to the file system and subsequent reboot behavior until committed (commit_edit_settings) */ bool begin_edit_settings; @@ -226,6 +228,7 @@ extern "C" { #define meshtastic_AdminMessage_set_module_config_tag 35 #define meshtastic_AdminMessage_set_canned_message_module_messages_tag 36 #define meshtastic_AdminMessage_set_ringtone_message_tag 37 +#define meshtastic_AdminMessage_remove_by_nodenum_tag 38 #define meshtastic_AdminMessage_begin_edit_settings_tag 64 #define meshtastic_AdminMessage_commit_edit_settings_tag 65 #define meshtastic_AdminMessage_reboot_ota_seconds_tag 95 @@ -262,6 +265,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34) X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_module_config,set_module_config), 35) \ X(a, STATIC, ONEOF, STRING, (payload_variant,set_canned_message_module_messages,set_canned_message_module_messages), 36) \ X(a, STATIC, ONEOF, STRING, (payload_variant,set_ringtone_message,set_ringtone_message), 37) \ +X(a, STATIC, ONEOF, UINT32, (payload_variant,remove_by_nodenum,remove_by_nodenum), 38) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,begin_edit_settings,begin_edit_settings), 64) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,commit_edit_settings,commit_edit_settings), 65) \ X(a, STATIC, ONEOF, INT32, (payload_variant,reboot_ota_seconds,reboot_ota_seconds), 95) \ diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 9dcc14940..53e92a948 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -343,7 +343,7 @@ typedef struct _meshtastic_Config_NetworkConfig { acquire an address via DHCP */ char wifi_ssid[33]; /* If set, will be use to authenticate to the named wifi */ - char wifi_psk[64]; + char wifi_psk[65]; /* NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` */ char ntp_server[33]; /* Enable Ethernet */ @@ -790,10 +790,10 @@ extern const pb_msgdesc_t meshtastic_Config_BluetoothConfig_msg; #define meshtastic_Config_DisplayConfig_size 28 #define meshtastic_Config_LoRaConfig_size 77 #define meshtastic_Config_NetworkConfig_IpV4Config_size 20 -#define meshtastic_Config_NetworkConfig_size 195 +#define meshtastic_Config_NetworkConfig_size 196 #define meshtastic_Config_PositionConfig_size 60 #define meshtastic_Config_PowerConfig_size 40 -#define meshtastic_Config_size 198 +#define meshtastic_Config_size 199 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 56924bb82..ace142773 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -316,7 +316,7 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; #define meshtastic_DeviceState_size 16854 #define meshtastic_NodeInfoLite_size 151 #define meshtastic_NodeRemoteHardwarePin_size 29 -#define meshtastic_OEMStore_size 3230 +#define meshtastic_OEMStore_size 3231 #define meshtastic_PositionLite_size 28 #ifdef __cplusplus diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index fe9c9e70a..7dc96e79a 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -174,7 +174,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; #define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_LocalConfig_size 463 +#define meshtastic_LocalConfig_size 464 #define meshtastic_LocalModuleConfig_size 621 #ifdef __cplusplus diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index fc1221a83..dce33ad48 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -182,6 +182,12 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } break; } + case meshtastic_AdminMessage_remove_by_nodenum_tag: { + LOG_INFO("Client is receiving a remove_nodenum command.\n"); + nodeDB.removeNodeByNum(r->remove_by_nodenum); + reboot(DEFAULT_REBOOT_SECONDS); + break; + } #ifdef ARCH_PORTDUINO case meshtastic_AdminMessage_exit_simulator_tag: LOG_INFO("Exiting simulator\n");