keyvaluedb

This commit is contained in:
John Smith 2023-05-17 21:51:42 -04:00
parent 24bd401c90
commit 9f22e90fbc
8 changed files with 45 additions and 60 deletions

2
external/keyvaluedb vendored

@ -1 +1 @@
Subproject commit 3408e0b2ae3df0088e0714bc23fb33c82a58e22c
Subproject commit 1ec47c11f6319153e219d5f18ddbd9e026c9342e

View File

@ -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"];

View File

@ -11,3 +11,5 @@ pub use table_store::*;
#[cfg(target_os = "android")]
pub mod android;
pub mod network_interfaces;
use super::*;

View File

@ -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(())
}

View File

@ -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);
}
}
}

View File

@ -7,3 +7,5 @@ pub use block_store::*;
pub use protected_store::*;
pub use system::*;
pub use table_store::*;
use super::*;

View File

@ -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(())
}

View File

@ -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);
}
}
}