Fix up convoluted function

This commit is contained in:
onyinyang 2023-07-10 15:03:37 -04:00
parent d2d09bccc1
commit 3c88f4471b
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
3 changed files with 28 additions and 12 deletions

View File

@ -571,7 +571,7 @@ mod tests {
let redeemed_cred_resp = body_to_string(new_redeem_invite_response).await;
let redeemed_cred_resp_obj = serde_json::from_str(&redeemed_cred_resp).unwrap();
let redeemed_cred_result = match proto::redeem_invite::handle_response(
let _redeemed_cred_result = match proto::redeem_invite::handle_response(
new_invite.1,
redeemed_cred_resp_obj,
&pubkeys_obj.lox_pub,

View File

@ -291,14 +291,14 @@ impl BridgeTable {
// This function looks for and removes buckets so their indexes can be reused
// This should include buckets that have been blocked for a sufficiently long period
// that we no longer want to allow migration to the, or else, open-entry buckets that
// that we no longer want to allow migration to, or else, open-entry buckets that
// have been unblocked long enough to become trusted and who's users' credentials
// would have expired (after 511 days)
fn clean_up_expired_buckets(&mut self) {
// Consider including migration tables and check age of from buckets
// If an open-invitation bucket is more than 511 days old, it should be recycled
// If a blocked bridge is more than ?? 511 (the maximum validity of a credential in days)? days old, it should also be recycled
// If a blocked bridge is more than 511 (the maximum validity of a credential in days) days old, it should also be recycled
// First check if there are any blocked indexes that are old enough to be replaced
if !self.blocked_keys.is_empty()
@ -312,17 +312,33 @@ impl BridgeTable {
.partition(|&x| x.1 > self.today() + 511);
for item in expired {
let new_item = item.0;
// get the single bridge line and remove the open entry index from the reachable bridges
let bridge_line = self.buckets.get(&new_item).unwrap();
for item in self.reachable.get(bridge_line) {}
// check each single bridge line and ensure none are still marked as reachable.
// if any are still reachable, remove from reachable bridges.
// When syncing resources, we will likely have to reallocate this bridge but if it hasn't already been
// blocked, this might be fine?
let bridgelines = self.buckets.get(&new_item).unwrap();
for bridgeline in bridgelines {
// If the bridge hasn't been set to default, assume it's still reachable
if bridgeline.port > 0 {
// Move to unallocated bridges
self.unallocated_bridges.push(*bridgeline);
// Check if it's still in the reachable bridges. It should be if we've gotten this far.
if let Some(_reachable_indexes_for_bridgeline) = self.reachable.get(bridgeline) {
// and remove it until it's reallocated
self.reachable.remove(bridgeline);
}
}
}
// Then remove the bucket and keys at the specified index
self.buckets.remove(&new_item);
self.keys.remove(&new_item);
//and add them to the recyclable keys
self.recycleable_keys.push(new_item);
}
// update the blocked_keys vector to only include the fresh keys
// Finally, update the blocked_keys vector to only include the fresh keys
self.blocked_keys = fresh
}
// Next do the same for open_invitations buckets
// First check if there are any open invitation indexes that are old enough to be replaced
if !self.open_inv_keys.is_empty()
&& self.open_inv_keys.iter().any(|&x| x.1 > self.today() + 511)
@ -350,7 +366,7 @@ impl BridgeTable {
// of recycleable lookup keys from buckets that have been removed and prioritize
// this list before increasing the counter
fn find_next_available_key(&mut self) -> u32 {
self.clean_up_expired_buckets();
self.clean_up_expired_buckets(); //This function probably should be moved to lib.rs to handle trustup and migration tables too
if self.recycleable_keys.is_empty() {
let mut test_index = 1;
let mut test_counter = self.counter.wrapping_add(test_index);

View File

@ -151,8 +151,8 @@ impl BridgeDb {
}
/// Remove an open-invitation bucket from the set
pub fn remove_openinv(&mut self, bucket: u32) {
self.openinv_buckets.remove(&bucket);
pub fn remove_openinv(&mut self, bucket: &u32) {
self.openinv_buckets.remove(bucket);
}
/// Produce an open invitation. In this example code, we just
@ -531,7 +531,7 @@ impl BridgeAuth {
// Count how many bridges in this bucket are reachable
let mut bucket = match self.bridge_table.buckets.get(bucketnum) {
Some(bridgelines) => *bridgelines,
None => return false,
None => return false, // This should not happen
};
let numreachable = bucket
.iter()
@ -544,7 +544,7 @@ impl BridgeAuth {
// Is this bucket an open-invitation bucket?
if bdb.openinv_buckets.contains(bucketnum) {
bdb.openinv_buckets.remove(bucketnum);
bdb.remove_openinv(bucketnum);
self.trustup_migration_table.table.remove(bucketnum);
continue;
}