From 9f22e90fbc70c646e9863eeda7ce14c72b3c5da8 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 17 May 2023 21:51:42 -0400 Subject: [PATCH] keyvaluedb --- external/keyvaluedb | 2 +- veilid-core/src/intf/mod.rs | 14 +++++++++ veilid-core/src/intf/native/mod.rs | 2 ++ .../src/intf/native/protected_store.rs | 20 +++++------- veilid-core/src/intf/native/table_store.rs | 31 +++++-------------- veilid-core/src/intf/wasm/mod.rs | 2 ++ veilid-core/src/intf/wasm/protected_store.rs | 20 +++++------- veilid-core/src/intf/wasm/table_store.rs | 14 +++------ 8 files changed, 45 insertions(+), 60 deletions(-) diff --git a/external/keyvaluedb b/external/keyvaluedb index 3408e0b2..1ec47c11 160000 --- a/external/keyvaluedb +++ b/external/keyvaluedb @@ -1 +1 @@ -Subproject commit 3408e0b2ae3df0088e0714bc23fb33c82a58e22c +Subproject commit 1ec47c11f6319153e219d5f18ddbd9e026c9342e diff --git a/veilid-core/src/intf/mod.rs b/veilid-core/src/intf/mod.rs index 842e5351..6c1ae9f3 100644 --- a/veilid-core/src/intf/mod.rs +++ b/veilid-core/src/intf/mod.rs @@ -1,4 +1,5 @@ mod table_db; +use super::*; #[cfg(target_arch = "wasm32")] mod wasm; @@ -8,3 +9,16 @@ pub use wasm::*; mod native; #[cfg(not(target_arch = "wasm32"))] pub use native::*; + +pub static KNOWN_TABLE_NAMES: [&'static str; 7] = [ + "crypto_caches", + "RouteSpecStore", + "routing_table", + "local_records", + "local_subkeys", + "remote_records", + "remote_subkeys", +]; + +pub static KNOWN_PROTECTED_STORE_KEYS: [&'static str; 4] = + ["node_id", "node_id_secret", "_test_key", "RouteSpecStore"]; diff --git a/veilid-core/src/intf/native/mod.rs b/veilid-core/src/intf/native/mod.rs index 786b2dd1..6f2b8791 100644 --- a/veilid-core/src/intf/native/mod.rs +++ b/veilid-core/src/intf/native/mod.rs @@ -11,3 +11,5 @@ pub use table_store::*; #[cfg(target_os = "android")] pub mod android; pub mod network_interfaces; + +use super::*; diff --git a/veilid-core/src/intf/native/protected_store.rs b/veilid-core/src/intf/native/protected_store.rs index 40d566a4..d8e46918 100644 --- a/veilid-core/src/intf/native/protected_store.rs +++ b/veilid-core/src/intf/native/protected_store.rs @@ -1,4 +1,4 @@ -use crate::*; +use super::*; use data_encoding::BASE64URL_NOPAD; use keyring_manager::*; use std::path::Path; @@ -29,18 +29,12 @@ impl ProtectedStore { #[instrument(level = "trace", skip(self), err)] pub async fn delete_all(&self) -> EyreResult<()> { - // Delete all known keys - if self.remove_user_secret("node_id").await? { - debug!("deleted protected_store key 'node_id'"); - } - if self.remove_user_secret("node_id_secret").await? { - debug!("deleted protected_store key 'node_id_secret'"); - } - if self.remove_user_secret("_test_key").await? { - debug!("deleted protected_store key '_test_key'"); - } - if self.remove_user_secret("RouteSpecStore").await? { - debug!("deleted protected_store key 'RouteSpecStore'"); + for kpsk in &KNOWN_PROTECTED_STORE_KEYS { + if let Err(e) = self.remove_user_secret(kpsk).await { + error!("failed to delete '{}': {}", kpsk, e); + } else { + debug!("deleted table '{}'", kpsk); + } } Ok(()) } diff --git a/veilid-core/src/intf/native/table_store.rs b/veilid-core/src/intf/native/table_store.rs index cd9ebff9..376b8efa 100644 --- a/veilid-core/src/intf/native/table_store.rs +++ b/veilid-core/src/intf/native/table_store.rs @@ -1,6 +1,6 @@ +use super::*; use crate::intf::table_db::TableDBInner; pub use crate::intf::table_db::{TableDB, TableDBTransaction}; -use crate::*; use keyvaluedb_sqlite::*; use std::path::PathBuf; @@ -31,29 +31,12 @@ impl TableStore { /// Delete all known tables pub async fn delete_all(&self) { - if let Err(e) = self.delete("crypto_caches").await { - error!("failed to delete 'crypto_caches': {}", e); - } - if let Err(e) = self.delete("RouteSpecStore").await { - error!("failed to delete 'RouteSpecStore': {}", e); - } - if let Err(e) = self.delete("routing_table").await { - error!("failed to delete 'routing_table': {}", e); - } - if let Err(e) = self.delete("routing_table").await { - error!("failed to delete 'routing_table': {}", e); - } - if let Err(e) = self.delete("local_records").await { - error!("failed to delete 'local_records': {}", e); - } - if let Err(e) = self.delete("local_subkeys").await { - error!("failed to delete 'local_subkeys': {}", e); - } - if let Err(e) = self.delete("remote_records").await { - error!("failed to delete 'remote_records': {}", e); - } - if let Err(e) = self.delete("remote_subkeys").await { - error!("failed to delete 'remote_subkeys': {}", e); + for ktn in &KNOWN_TABLE_NAMES { + if let Err(e) = self.delete(ktn).await { + error!("failed to delete '{}': {}", ktn, e); + } else { + debug!("deleted table '{}'", ktn); + } } } diff --git a/veilid-core/src/intf/wasm/mod.rs b/veilid-core/src/intf/wasm/mod.rs index 53faa230..a2b0f374 100644 --- a/veilid-core/src/intf/wasm/mod.rs +++ b/veilid-core/src/intf/wasm/mod.rs @@ -7,3 +7,5 @@ pub use block_store::*; pub use protected_store::*; pub use system::*; pub use table_store::*; + +use super::*; diff --git a/veilid-core/src/intf/wasm/protected_store.rs b/veilid-core/src/intf/wasm/protected_store.rs index 126d2b7c..39c9bacd 100644 --- a/veilid-core/src/intf/wasm/protected_store.rs +++ b/veilid-core/src/intf/wasm/protected_store.rs @@ -1,4 +1,4 @@ -use crate::*; +use super::*; use data_encoding::BASE64URL_NOPAD; use rkyv::{ bytecheck::CheckBytes, Archive as RkyvArchive, Deserialize as RkyvDeserialize, @@ -19,18 +19,12 @@ impl ProtectedStore { #[instrument(level = "trace", skip(self), err)] pub async fn delete_all(&self) -> EyreResult<()> { - // Delete all known keys - if self.remove_user_secret("node_id").await? { - debug!("deleted protected_store key 'node_id'"); - } - if self.remove_user_secret("node_id_secret").await? { - debug!("deleted protected_store key 'node_id_secret'"); - } - if self.remove_user_secret("_test_key").await? { - debug!("deleted protected_store key '_test_key'"); - } - if self.remove_user_secret("RouteSpecStore").await? { - debug!("deleted protected_store key 'RouteSpecStore'"); + for kpsk in &KNOWN_PROTECTED_STORE_KEYS { + if let Err(e) = self.remove_user_secret(kpsk).await { + error!("failed to delete '{}': {}", kpsk, e); + } else { + debug!("deleted table '{}'", kpsk); + } } Ok(()) } diff --git a/veilid-core/src/intf/wasm/table_store.rs b/veilid-core/src/intf/wasm/table_store.rs index f401220d..3d8cd513 100644 --- a/veilid-core/src/intf/wasm/table_store.rs +++ b/veilid-core/src/intf/wasm/table_store.rs @@ -1,6 +1,6 @@ +use super::*; use crate::intf::table_db::TableDBInner; pub use crate::intf::table_db::{TableDB, TableDBTransaction}; -use crate::*; use keyvaluedb_web::*; struct TableStoreInner { @@ -30,14 +30,10 @@ impl TableStore { /// Delete all known tables pub async fn delete_all(&self) { - if let Err(e) = self.delete("crypto_caches").await { - error!("failed to delete 'crypto_caches': {}", e); - } - if let Err(e) = self.delete("RouteSpecStore").await { - error!("failed to delete 'RouteSpecStore': {}", e); - } - if let Err(e) = self.delete("routing_table").await { - error!("failed to delete 'routing_table': {}", e); + for ktn in &KNOWN_TABLE_NAMES { + if let Err(e) = self.delete(ktn).await { + error!("failed to delete '{}': {}", ktn, e); + } } }