more table store work for password protecting encryption key, also fix unit tests hang in routing table test
This commit is contained in:
parent
e8392013c3
commit
8001017338
@ -41,31 +41,35 @@ pub async fn test_routingtable_buckets_round_trip() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let original_inner = &*original.inner.read();
|
||||
let copy_inner = &*copy.inner.read();
|
||||
// Wrap to close lifetime of 'inner' which is borrowed here so terminate() can succeed
|
||||
// (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 copy_keys: Vec<_> = copy_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();
|
||||
|
||||
assert_eq!(routing_table_keys.len(), copy_keys.len());
|
||||
assert_eq!(routing_table_keys.len(), copy_keys.len());
|
||||
|
||||
for crypto in routing_table_keys {
|
||||
// The same keys are present in the original and copy RoutingTables.
|
||||
let original_buckets = original_inner.buckets.get(&crypto).unwrap();
|
||||
let copy_buckets = copy_inner.buckets.get(&crypto).unwrap();
|
||||
for crypto in routing_table_keys {
|
||||
// The same keys are present in the original and copy RoutingTables.
|
||||
let original_buckets = original_inner.buckets.get(&crypto).unwrap();
|
||||
let copy_buckets = copy_inner.buckets.get(&crypto).unwrap();
|
||||
|
||||
// Recurse into RoutingTable.inner.buckets
|
||||
for (left_buckets, right_buckets) in original_buckets.iter().zip(copy_buckets.iter()) {
|
||||
// Recurse into RoutingTable.inner.buckets.entries
|
||||
for ((left_crypto, left_entries), (right_crypto, right_entries)) in
|
||||
left_buckets.entries().zip(right_buckets.entries())
|
||||
{
|
||||
assert_eq!(left_crypto, right_crypto);
|
||||
// Recurse into RoutingTable.inner.buckets
|
||||
for (left_buckets, right_buckets) in original_buckets.iter().zip(copy_buckets.iter()) {
|
||||
// Recurse into RoutingTable.inner.buckets.entries
|
||||
for ((left_crypto, left_entries), (right_crypto, right_entries)) in
|
||||
left_buckets.entries().zip(right_buckets.entries())
|
||||
{
|
||||
assert_eq!(left_crypto, right_crypto);
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", left_entries),
|
||||
format!("{:?}", right_entries)
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{:?}", left_entries),
|
||||
format!("{:?}", right_entries)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -421,6 +421,15 @@ impl TableStore {
|
||||
/// 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> {
|
||||
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?;
|
||||
|
||||
// See if this table is already opened
|
||||
@ -477,6 +486,14 @@ impl TableStore {
|
||||
/// Delete a TableDB table by name
|
||||
pub async fn delete(&self, name: &str) -> VeilidAPIResult<bool> {
|
||||
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 {
|
||||
// Did not exist in name table
|
||||
return Ok(false);
|
||||
@ -510,6 +527,13 @@ impl TableStore {
|
||||
/// Rename a TableDB table
|
||||
pub async fn rename(&self, old_name: &str, new_name: &str) -> VeilidAPIResult<()> {
|
||||
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);
|
||||
self.name_rename(old_name, new_name).await
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ pub async fn test_config() {
|
||||
}
|
||||
|
||||
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.capabilities.protocol_udp, true);
|
||||
assert_eq!(inner.capabilities.protocol_connect_tcp, true);
|
||||
|
Loading…
Reference in New Issue
Block a user