fix(mesh): nuclear clear-all wipes state files + shared secrets
Clear All now deletes messages.json, mesh-contacts.json, sessions.json, mesh-outbox.json and clears shared secrets for a truly clean slate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
dbafa12596
commit
cd8763f468
@ -216,38 +216,36 @@ impl RpcHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// mesh.clear-all — Clear all peers, messages, contacts, and presence data.
|
/// mesh.clear-all — Nuclear reset: wipe all mesh state files and restart
|
||||||
/// Resets the mesh state to a fresh start while keeping the device connected.
|
/// the service for a completely clean slate.
|
||||||
pub(in crate::api::rpc) async fn handle_mesh_clear_all(&self) -> Result<serde_json::Value> {
|
pub(in crate::api::rpc) async fn handle_mesh_clear_all(&self) -> Result<serde_json::Value> {
|
||||||
|
let data_dir = self.config.data_dir.clone();
|
||||||
|
// Delete all mesh state files
|
||||||
|
for filename in &[
|
||||||
|
"messages.json",
|
||||||
|
"mesh-contacts.json",
|
||||||
|
"sessions.json",
|
||||||
|
"mesh-outbox.json",
|
||||||
|
] {
|
||||||
|
let _ = tokio::fs::remove_file(data_dir.join(filename)).await;
|
||||||
|
}
|
||||||
|
// Clear in-memory state
|
||||||
let service = self.mesh_service.read().await;
|
let service = self.mesh_service.read().await;
|
||||||
if let Some(svc) = service.as_ref() {
|
if let Some(svc) = service.as_ref() {
|
||||||
let state = svc.state();
|
let state = svc.state();
|
||||||
// Clear peers (except synthetic federation peers)
|
|
||||||
state.peers.write().await.clear();
|
state.peers.write().await.clear();
|
||||||
// Clear all messages
|
|
||||||
state.messages.write().await.clear();
|
state.messages.write().await.clear();
|
||||||
// Clear contacts
|
|
||||||
state.contacts.write().await.clear();
|
state.contacts.write().await.clear();
|
||||||
// Clear presence
|
|
||||||
state.presence.write().await.clear();
|
state.presence.write().await.clear();
|
||||||
// Clear chunk buffer
|
|
||||||
state.chunk_buffer.write().await.clear();
|
state.chunk_buffer.write().await.clear();
|
||||||
|
state.shared_secrets.write().await.clear();
|
||||||
// Re-seed federation peers
|
// Re-seed federation peers
|
||||||
let data_dir = self.config.data_dir.clone();
|
|
||||||
crate::mesh::seed_federation_peers_into_mesh(state, &data_dir).await;
|
crate::mesh::seed_federation_peers_into_mesh(state, &data_dir).await;
|
||||||
// Delete persisted messages file
|
|
||||||
let msg_file = data_dir.join("messages.json");
|
|
||||||
let _ = tokio::fs::remove_file(&msg_file).await;
|
|
||||||
// Delete persisted contacts file
|
|
||||||
let contacts_file = data_dir.join("mesh-contacts.json");
|
|
||||||
let _ = tokio::fs::remove_file(&contacts_file).await;
|
|
||||||
// Trigger a contact refresh from the radio device
|
// Trigger a contact refresh from the radio device
|
||||||
let _ = state.send_cmd(
|
let _ = state.send_cmd(
|
||||||
crate::mesh::listener::MeshCommand::RefreshContacts,
|
crate::mesh::listener::MeshCommand::RefreshContacts,
|
||||||
).await;
|
).await;
|
||||||
Ok(serde_json::json!({ "status": "cleared" }))
|
|
||||||
} else {
|
|
||||||
Ok(serde_json::json!({ "status": "no_service" }))
|
|
||||||
}
|
}
|
||||||
|
Ok(serde_json::json!({ "status": "cleared" }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user