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:
parent
aa785419d8
commit
7a24fdfa06
|
@ -1397,7 +1397,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rdsys_backend"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"chrono",
|
||||
|
|
|
@ -26,8 +26,8 @@ zkp = "0.8.0"
|
|||
|
||||
lox-library = { path = "../lox-library", 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]
|
||||
version = "0.4.19"
|
||||
features = ["serde"]
|
||||
features = ["serde"]
|
||||
|
|
|
@ -129,35 +129,43 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
|
|||
let mut bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
||||
for pt in new_resources {
|
||||
println!("A NEW RESOURCE: {:?}", pt);
|
||||
for resource in pt.1 {
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("Now it's a bridgeline: {:?}", bridgeline);
|
||||
if context.unreplaced_bridges.lock().unwrap().len() > 0 {
|
||||
println!("BridgeLine to be replaced: {:?}", bridgeline);
|
||||
let res = context.replace_with_new(bridgeline);
|
||||
if res == lox_library::ReplaceSuccess::NotFound {
|
||||
println!(
|
||||
if let Some(resources) = pt.1 {
|
||||
for resource in resources {
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("Now it's a bridgeline: {:?}", bridgeline);
|
||||
if context.unreplaced_bridges.lock().unwrap().len() > 0 {
|
||||
println!("BridgeLine to be replaced: {:?}", bridgeline);
|
||||
let res = context.replace_with_new(bridgeline);
|
||||
if res == lox_library::ReplaceSuccess::NotFound {
|
||||
println!(
|
||||
"BridgeLine not found in bridge_table, already updated {:?}",
|
||||
bridgeline
|
||||
);
|
||||
} else if res == lox_library::ReplaceSuccess::Replaced {
|
||||
println!("BridgeLine successfully replaced: {:?}", bridgeline);
|
||||
} else if res == lox_library::ReplaceSuccess::Replaced {
|
||||
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 {
|
||||
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);
|
||||
// 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];
|
||||
}
|
||||
} 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 {
|
||||
for pt in changed_resources {
|
||||
println!("A NEW CHANGED RESOURCE: {:?}", pt);
|
||||
for resource in pt.1 {
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("BridgeLine to be changed: {:?}", bridgeline);
|
||||
let res = context.update_bridge(bridgeline);
|
||||
if res {
|
||||
println!("BridgeLine successfully updated: {:?}", bridgeline);
|
||||
} else {
|
||||
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);
|
||||
if let Some(resources) = pt.1 {
|
||||
for resource in resources {
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("BridgeLine to be changed: {:?}", bridgeline);
|
||||
let res = context.update_bridge(bridgeline);
|
||||
if res {
|
||||
println!("BridgeLine successfully updated: {:?}", bridgeline);
|
||||
} else {
|
||||
let bucket = context.remove_extra_bridges();
|
||||
context.add_spare_bucket(bucket);
|
||||
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 {
|
||||
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 {
|
||||
for pt in gone_resources {
|
||||
println!("A NEW GONE RESOURCE: {:?}", pt);
|
||||
for resource in pt.1 {
|
||||
// If resource last passed tests 3 hours ago, it should be replaced with a working
|
||||
// resource and be removed from the bridgetable. If it has been gone for more than 7 hours,
|
||||
// we should stop trying to remove it from the bridge table and assume it has successfully been
|
||||
// removed already
|
||||
if resource.last_passed < (Utc::now() - chrono::Duration::hours(3))
|
||||
|| resource.last_passed > (Utc::now() - chrono::Duration::hours(7))
|
||||
{
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("BridgeLine to be replaced: {:?}", bridgeline);
|
||||
let res = context.replace_with_new(bridgeline);
|
||||
if res == lox_library::ReplaceSuccess::Replaced {
|
||||
println!("BridgeLine successfully replaced: {:?}", 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!(
|
||||
if let Some(resources) = pt.1 {
|
||||
for resource in resources {
|
||||
// If resource last passed tests 3 hours ago, it should be replaced with a working
|
||||
// resource and be removed from the bridgetable. If it has been gone for more than 7 hours,
|
||||
// we should stop trying to remove it from the bridge table and assume it has successfully been
|
||||
// removed already
|
||||
if resource.last_passed < (Utc::now() - chrono::Duration::hours(3))
|
||||
|| resource.last_passed
|
||||
> (Utc::now() - chrono::Duration::hours(7))
|
||||
{
|
||||
let bridgeline = parse_resource(resource);
|
||||
println!("BridgeLine to be replaced: {:?}", bridgeline);
|
||||
let res = context.replace_with_new(bridgeline);
|
||||
if res == lox_library::ReplaceSuccess::Replaced {
|
||||
println!(
|
||||
"BridgeLine successfully replaced: {:?}",
|
||||
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! : {:?}",
|
||||
bridgeline
|
||||
);
|
||||
context.new_unreplaced_bridge(bridgeline);
|
||||
context.new_unreplaced_bridge(bridgeline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,7 +252,10 @@ mod tests {
|
|||
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 mut bdb = self.context.db.lock().unwrap();
|
||||
let mut lox_auth = self.context.ba.lock().unwrap();
|
||||
|
|
Loading…
Reference in New Issue