This commit is contained in:
Ford Jones 2025-10-26 10:44:50 +13:00 committed by GitHub
commit 1f808b59bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 8 deletions

@ -1 +1 @@
Subproject commit bf149bbdcce45ba7cd8643db7cb25e5c8815072b Subproject commit 83ddaf8b24e1e9b372b1e2c72df51d44848b3a71

View File

@ -978,12 +978,25 @@ void NodeDB::installDefaultChannels()
channelFile.version = DEVICESTATE_CUR_VER; channelFile.version = DEVICESTATE_CUR_VER;
} }
void NodeDB::resetNodes() void NodeDB::resetNodes(bool keepFavorites)
{ {
if (!config.position.fixed_position) if (!config.position.fixed_position)
clearLocalPosition(); clearLocalPosition();
numMeshNodes = 1; numMeshNodes = 1;
std::fill(nodeDatabase.nodes.begin() + 1, nodeDatabase.nodes.end(), meshtastic_NodeInfoLite()); if (keepFavorites) {
LOG_INFO("Clearing node database - preserving favorites");
for (size_t i = 0; i < meshNodes->size(); i++) {
meshtastic_NodeInfoLite &node = meshNodes->at(i);
if (i > 0 && !node.is_favorite) {
node = meshtastic_NodeInfoLite();
} else {
numMeshNodes += 1;
}
};
} else {
LOG_INFO("Clearing node database - removing favorites");
std::fill(nodeDatabase.nodes.begin() + 1, nodeDatabase.nodes.end(), meshtastic_NodeInfoLite());
}
devicestate.has_rx_text_message = false; devicestate.has_rx_text_message = false;
devicestate.has_rx_waypoint = false; devicestate.has_rx_waypoint = false;
saveNodeDatabaseToDisk(); saveNodeDatabaseToDisk();

View File

@ -229,7 +229,8 @@ class NodeDB
*/ */
size_t getNumOnlineMeshNodes(bool localOnly = false); size_t getNumOnlineMeshNodes(bool localOnly = false);
void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(), removeNodeByNum(NodeNum nodeNum); void initConfigIntervals(), initModuleConfigIntervals(), resetNodes(bool keepFavorites = false),
removeNodeByNum(NodeNum nodeNum);
bool factoryReset(bool eraseBleBonds = false); bool factoryReset(bool eraseBleBonds = false);

View File

@ -272,8 +272,9 @@ typedef struct _meshtastic_AdminMessage {
int32_t shutdown_seconds; int32_t shutdown_seconds;
/* Tell the node to factory reset config; all device state and configuration will be returned to factory defaults; BLE bonds will be preserved. */ /* Tell the node to factory reset config; all device state and configuration will be returned to factory defaults; BLE bonds will be preserved. */
int32_t factory_reset_config; int32_t factory_reset_config;
/* Tell the node to reset the nodedb. */ /* Tell the node to reset the nodedb.
int32_t nodedb_reset; When true, favorites are preserved through reset. */
bool nodedb_reset;
}; };
/* The node generates this key and sends it with any get_x_response packets. /* The node generates this key and sends it with any get_x_response packets.
The client MUST include the same key with any set_x commands. Key expires after 300 seconds. The client MUST include the same key with any set_x commands. Key expires after 300 seconds.
@ -459,7 +460,7 @@ X(a, STATIC, ONEOF, BOOL, (payload_variant,exit_simulator,exit_simulato
X(a, STATIC, ONEOF, INT32, (payload_variant,reboot_seconds,reboot_seconds), 97) \ X(a, STATIC, ONEOF, INT32, (payload_variant,reboot_seconds,reboot_seconds), 97) \
X(a, STATIC, ONEOF, INT32, (payload_variant,shutdown_seconds,shutdown_seconds), 98) \ X(a, STATIC, ONEOF, INT32, (payload_variant,shutdown_seconds,shutdown_seconds), 98) \
X(a, STATIC, ONEOF, INT32, (payload_variant,factory_reset_config,factory_reset_config), 99) \ X(a, STATIC, ONEOF, INT32, (payload_variant,factory_reset_config,factory_reset_config), 99) \
X(a, STATIC, ONEOF, INT32, (payload_variant,nodedb_reset,nodedb_reset), 100) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,nodedb_reset,nodedb_reset), 100) \
X(a, STATIC, SINGULAR, BYTES, session_passkey, 101) X(a, STATIC, SINGULAR, BYTES, session_passkey, 101)
#define meshtastic_AdminMessage_CALLBACK NULL #define meshtastic_AdminMessage_CALLBACK NULL
#define meshtastic_AdminMessage_DEFAULT NULL #define meshtastic_AdminMessage_DEFAULT NULL

View File

@ -280,7 +280,12 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
case meshtastic_AdminMessage_nodedb_reset_tag: { case meshtastic_AdminMessage_nodedb_reset_tag: {
disableBluetooth(); disableBluetooth();
LOG_INFO("Initiate node-db reset"); LOG_INFO("Initiate node-db reset");
nodeDB->resetNodes(); // CLIENT_BASE, ROUTER and ROUTER_LATE are able to preserve the remaining hop count when relaying a packet via a
// favorited node, so ensure that their favorites are kept on reset
bool rolePreference =
isOneOf(config.device.role, meshtastic_Config_DeviceConfig_Role_CLIENT_BASE,
meshtastic_Config_DeviceConfig_Role_ROUTER, meshtastic_Config_DeviceConfig_Role_ROUTER_LATE);
nodeDB->resetNodes(rolePreference ? rolePreference : r->nodedb_reset);
reboot(DEFAULT_REBOOT_SECONDS); reboot(DEFAULT_REBOOT_SECONDS);
break; break;
} }