more table store work for password protecting encryption key, also fix unit tests hang in routing table test

This commit is contained in:
John Smith 2023-05-26 20:39:35 +01:00
parent e8392013c3
commit 8001017338
3 changed files with 49 additions and 21 deletions

View File

@ -41,31 +41,35 @@ pub async fn test_routingtable_buckets_round_trip() {
) )
.unwrap(); .unwrap();
let original_inner = &*original.inner.read(); // Wrap to close lifetime of 'inner' which is borrowed here so terminate() can succeed
let copy_inner = &*copy.inner.read(); // (it also .write() locks routing table inner)
{
let original_inner = &*original.inner.read();
let copy_inner = &*copy.inner.read();
let routing_table_keys: Vec<_> = original_inner.buckets.keys().clone().collect(); let routing_table_keys: Vec<_> = original_inner.buckets.keys().clone().collect();
let copy_keys: Vec<_> = copy_inner.buckets.keys().clone().collect(); let copy_keys: Vec<_> = copy_inner.buckets.keys().clone().collect();
assert_eq!(routing_table_keys.len(), copy_keys.len()); assert_eq!(routing_table_keys.len(), copy_keys.len());
for crypto in routing_table_keys { for crypto in routing_table_keys {
// The same keys are present in the original and copy RoutingTables. // The same keys are present in the original and copy RoutingTables.
let original_buckets = original_inner.buckets.get(&crypto).unwrap(); let original_buckets = original_inner.buckets.get(&crypto).unwrap();
let copy_buckets = copy_inner.buckets.get(&crypto).unwrap(); let copy_buckets = copy_inner.buckets.get(&crypto).unwrap();
// Recurse into RoutingTable.inner.buckets // Recurse into RoutingTable.inner.buckets
for (left_buckets, right_buckets) in original_buckets.iter().zip(copy_buckets.iter()) { for (left_buckets, right_buckets) in original_buckets.iter().zip(copy_buckets.iter()) {
// Recurse into RoutingTable.inner.buckets.entries // Recurse into RoutingTable.inner.buckets.entries
for ((left_crypto, left_entries), (right_crypto, right_entries)) in for ((left_crypto, left_entries), (right_crypto, right_entries)) in
left_buckets.entries().zip(right_buckets.entries()) left_buckets.entries().zip(right_buckets.entries())
{ {
assert_eq!(left_crypto, right_crypto); assert_eq!(left_crypto, right_crypto);
assert_eq!( assert_eq!(
format!("{:?}", left_entries), format!("{:?}", left_entries),
format!("{:?}", right_entries) format!("{:?}", right_entries)
); );
}
} }
} }
} }

View File

@ -421,6 +421,15 @@ impl TableStore {
/// existing TableDB's column count, the database will be upgraded to add the missing columns /// existing TableDB's column count, the database will be upgraded to add the missing columns
pub async fn open(&self, name: &str, column_count: u32) -> VeilidAPIResult<TableDB> { pub async fn open(&self, name: &str, column_count: u32) -> VeilidAPIResult<TableDB> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
let table_name = self.name_get_or_create(name).await?; let table_name = self.name_get_or_create(name).await?;
// See if this table is already opened // See if this table is already opened
@ -477,6 +486,14 @@ impl TableStore {
/// Delete a TableDB table by name /// Delete a TableDB table by name
pub async fn delete(&self, name: &str) -> VeilidAPIResult<bool> { pub async fn delete(&self, name: &str) -> VeilidAPIResult<bool> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
let Some(table_name) = self.name_get(name).await? else { let Some(table_name) = self.name_get(name).await? else {
// Did not exist in name table // Did not exist in name table
return Ok(false); return Ok(false);
@ -510,6 +527,13 @@ impl TableStore {
/// Rename a TableDB table /// Rename a TableDB table
pub async fn rename(&self, old_name: &str, new_name: &str) -> VeilidAPIResult<()> { pub async fn rename(&self, old_name: &str, new_name: &str) -> VeilidAPIResult<()> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
trace!("TableStore::rename {} -> {}", old_name, new_name); trace!("TableStore::rename {} -> {}", old_name, new_name);
self.name_rename(old_name, new_name).await self.name_rename(old_name, new_name).await
} }

View File

@ -296,7 +296,7 @@ pub async fn test_config() {
} }
let inner = vc.get(); let inner = vc.get();
assert_eq!(inner.program_name, String::from("Veilid")); assert_eq!(inner.program_name, String::from("VeilidCoreTests"));
assert_eq!(inner.namespace, String::from("")); assert_eq!(inner.namespace, String::from(""));
assert_eq!(inner.capabilities.protocol_udp, true); assert_eq!(inner.capabilities.protocol_udp, true);
assert_eq!(inner.capabilities.protocol_connect_tcp, true); assert_eq!(inner.capabilities.protocol_connect_tcp, true);