Update lox distributor to use most recent rdsys_backend

The structure of the ResourceDiff has been changed, so the lox
distributor has to modify how it parses the diff.
This commit is contained in:
Cecylia Bocovich 2023-06-29 10:17:11 -04:00
parent aa785419d8
commit 7a24fdfa06
No known key found for this signature in database
GPG Key ID: 009DE379FD9B7B90
4 changed files with 77 additions and 58 deletions

2
Cargo.lock generated
View File

@ -1397,7 +1397,7 @@ dependencies = [
[[package]] [[package]]
name = "rdsys_backend" name = "rdsys_backend"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"bytes", "bytes",
"chrono", "chrono",

View File

@ -26,8 +26,8 @@ zkp = "0.8.0"
lox-library = { path = "../lox-library", version = "0.1.0"} lox-library = { path = "../lox-library", version = "0.1.0"}
lox_utils = { path = "../lox-utils", version = "0.1.0"} lox_utils = { path = "../lox-utils", version = "0.1.0"}
rdsys_backend = { path = "../rdsys-backend-api", version = "0.1.0"} rdsys_backend = { path = "../rdsys-backend-api", version = "0.2"}
[dependencies.chrono] [dependencies.chrono]
version = "0.4.19" version = "0.4.19"
features = ["serde"] features = ["serde"]

View File

@ -129,35 +129,43 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
for pt in new_resources { for pt in new_resources {
println!("A NEW RESOURCE: {:?}", pt); println!("A NEW RESOURCE: {:?}", pt);
for resource in pt.1 { if let Some(resources) = pt.1 {
let bridgeline = parse_resource(resource); for resource in resources {
println!("Now it's a bridgeline: {:?}", bridgeline); let bridgeline = parse_resource(resource);
if context.unreplaced_bridges.lock().unwrap().len() > 0 { println!("Now it's a bridgeline: {:?}", bridgeline);
println!("BridgeLine to be replaced: {:?}", bridgeline); if context.unreplaced_bridges.lock().unwrap().len() > 0 {
let res = context.replace_with_new(bridgeline); println!("BridgeLine to be replaced: {:?}", bridgeline);
if res == lox_library::ReplaceSuccess::NotFound { let res = context.replace_with_new(bridgeline);
println!( if res == lox_library::ReplaceSuccess::NotFound {
println!(
"BridgeLine not found in bridge_table, already updated {:?}", "BridgeLine not found in bridge_table, already updated {:?}",
bridgeline bridgeline
); );
} else if res == lox_library::ReplaceSuccess::Replaced { } else if res == lox_library::ReplaceSuccess::Replaced {
println!("BridgeLine successfully replaced: {:?}", bridgeline); println!(
"BridgeLine successfully replaced: {:?}",
bridgeline
);
} else {
assert!(
res == lox_library::ReplaceSuccess::NotReplaced,
"ReplaceSuccess incorrectly set somehow"
);
// Add the bridge to the list of unreplaced bridges in the Lox context and try
// again to replace at the next update (nothing changes in the Lox Authority)
println!("'Gone' BridgeLine NOT replaced, saved for next update! : {:?}", bridgeline);
context.new_unreplaced_bridge(bridgeline);
}
} else if count < MAX_BRIDGES_PER_BUCKET {
bucket[count] = bridgeline;
count += 1;
} else { } else {
assert!(res == lox_library::ReplaceSuccess::NotReplaced, "ReplaceSuccess incorrectly set somehow"); // TODO: Decide the circumstances under which a bridge is allocated to an open_inv or spare bucket,
// Add the bridge to the list of unreplaced bridges in the Lox context and try // eventually also do some more fancy grouping of new resources, i.e., by type or region
// again to replace at the next update (nothing changes in the Lox Authority) context.add_openinv_bucket(bucket);
println!("'Gone' BridgeLine NOT replaced, saved for next update! : {:?}", bridgeline); count = 0;
context.new_unreplaced_bridge(bridgeline); bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
} }
} else if count < MAX_BRIDGES_PER_BUCKET {
bucket[count] = bridgeline;
count += 1;
} else {
// TODO: Decide the circumstances under which a bridge is allocated to an open_inv or spare bucket,
// eventually also do some more fancy grouping of new resources, i.e., by type or region
context.add_openinv_bucket(bucket);
count = 0;
bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
} }
} }
} }
@ -178,19 +186,21 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
if let Some(changed_resources) = resourcediff.changed { if let Some(changed_resources) = resourcediff.changed {
for pt in changed_resources { for pt in changed_resources {
println!("A NEW CHANGED RESOURCE: {:?}", pt); println!("A NEW CHANGED RESOURCE: {:?}", pt);
for resource in pt.1 { if let Some(resources) = pt.1 {
let bridgeline = parse_resource(resource); for resource in resources {
println!("BridgeLine to be changed: {:?}", bridgeline); let bridgeline = parse_resource(resource);
let res = context.update_bridge(bridgeline); println!("BridgeLine to be changed: {:?}", bridgeline);
if res { let res = context.update_bridge(bridgeline);
println!("BridgeLine successfully updated: {:?}", bridgeline); if res {
} else { println!("BridgeLine successfully updated: {:?}", bridgeline);
println!("BridgeLine: {:?} not found in Lox's Bridgetable. Save it as a new resource for now!", bridgeline);
if context.extra_bridges.lock().unwrap().len() < 2 {
context.append_extra_bridges(bridgeline);
} else { } else {
let bucket = context.remove_extra_bridges(); println!("BridgeLine: {:?} not found in Lox's Bridgetable. Save it as a new resource for now!", bridgeline);
context.add_spare_bucket(bucket); if context.extra_bridges.lock().unwrap().len() < 2 {
context.append_extra_bridges(bridgeline);
} else {
let bucket = context.remove_extra_bridges();
context.add_spare_bucket(bucket);
}
} }
} }
} }
@ -205,27 +215,33 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
if let Some(gone_resources) = resourcediff.gone { if let Some(gone_resources) = resourcediff.gone {
for pt in gone_resources { for pt in gone_resources {
println!("A NEW GONE RESOURCE: {:?}", pt); println!("A NEW GONE RESOURCE: {:?}", pt);
for resource in pt.1 { if let Some(resources) = pt.1 {
// If resource last passed tests 3 hours ago, it should be replaced with a working for resource in resources {
// resource and be removed from the bridgetable. If it has been gone for more than 7 hours, // If resource last passed tests 3 hours ago, it should be replaced with a working
// we should stop trying to remove it from the bridge table and assume it has successfully been // resource and be removed from the bridgetable. If it has been gone for more than 7 hours,
// removed already // we should stop trying to remove it from the bridge table and assume it has successfully been
if resource.last_passed < (Utc::now() - chrono::Duration::hours(3)) // removed already
|| resource.last_passed > (Utc::now() - chrono::Duration::hours(7)) if resource.last_passed < (Utc::now() - chrono::Duration::hours(3))
{ || resource.last_passed
let bridgeline = parse_resource(resource); > (Utc::now() - chrono::Duration::hours(7))
println!("BridgeLine to be replaced: {:?}", bridgeline); {
let res = context.replace_with_new(bridgeline); let bridgeline = parse_resource(resource);
if res == lox_library::ReplaceSuccess::Replaced { println!("BridgeLine to be replaced: {:?}", bridgeline);
println!("BridgeLine successfully replaced: {:?}", bridgeline); let res = context.replace_with_new(bridgeline);
} else if res == lox_library::ReplaceSuccess::NotReplaced { if res == lox_library::ReplaceSuccess::Replaced {
// Add the bridge to the list of unreplaced bridges in the Lox context and try println!(
// again to replace at the next update (nothing changes in the Lox Authority) "BridgeLine successfully replaced: {:?}",
println!( bridgeline
);
} else if res == lox_library::ReplaceSuccess::NotReplaced {
// Add the bridge to the list of unreplaced bridges in the Lox context and try
// again to replace at the next update (nothing changes in the Lox Authority)
println!(
"'Gone' BridgeLine NOT replaced, saved for next update! : {:?}", "'Gone' BridgeLine NOT replaced, saved for next update! : {:?}",
bridgeline bridgeline
); );
context.new_unreplaced_bridge(bridgeline); context.new_unreplaced_bridge(bridgeline);
}
} }
} }
} }

View File

@ -252,7 +252,10 @@ mod tests {
self.context.advance_days_test(days) self.context.advance_days_test(days)
} }
fn simulate_blocking(&mut self, cred: lox_library::cred::Lox) -> (lox_library::cred::Lox, u32, [u8; 16]) { fn simulate_blocking(
&mut self,
cred: lox_library::cred::Lox,
) -> (lox_library::cred::Lox, u32, [u8; 16]) {
let (id, key) = bridge_table::from_scalar(cred.bucket).unwrap(); let (id, key) = bridge_table::from_scalar(cred.bucket).unwrap();
let mut bdb = self.context.db.lock().unwrap(); let mut bdb = self.context.db.lock().unwrap();
let mut lox_auth = self.context.ba.lock().unwrap(); let mut lox_auth = self.context.ba.lock().unwrap();