Add fix for failure to replace bridges

- Change text for disabled functionality for blocked bridges
This commit is contained in:
onyinyang 2023-05-11 11:07:42 -04:00
parent 13d1bc8b1d
commit da4d7c962f
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 45 additions and 17 deletions

View File

@ -80,6 +80,7 @@ pub struct LoxServerContext {
pub db: Arc<Mutex<BridgeDb>>,
pub ba: Arc<Mutex<BridgeAuth>>,
pub extra_bridges: Arc<Mutex<Vec<BridgeLine>>>,
pub unreplaced_bridges: Arc<Mutex<Vec<BridgeLine>>>,
}
impl LoxServerContext {
@ -100,6 +101,11 @@ impl LoxServerContext {
}
pub fn new_unreplaced_bridge(&self, bridge: BridgeLine) {
let mut unreplaced_bridges = self.unreplaced_bridges.lock().unwrap();
unreplaced_bridges.push(bridge);
}
pub fn allocate_leftover_bridges(&self) {
let mut ba_obj = self.ba.lock().unwrap();
let mut db_obj = self.db.lock().unwrap();

View File

@ -184,6 +184,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
db: Arc::new(Mutex::new(bridgedb)),
ba: Arc::new(Mutex::new(lox_auth)),
extra_bridges: Arc::new(Mutex::new(Vec::new())),
unreplaced_bridges: Arc::new(Mutex::new(Vec::new())),
};
while let Some(cmd) = context_rx.recv().await {
@ -222,6 +223,21 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
info: info_bytes,
};
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 {
println!(
"BridgeLine successfully replaced: {:?}",
bridgeline
);
} else {
// 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-1 {
bucket[count] = bridgeline;
count += 1;
@ -233,6 +249,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
}
}
}
}
// Handle the extra buckets that were not allocated already
if count != 0 {
@ -287,7 +304,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
let bucket = context.remove_extra_bridges();
context.add_spare_bucket(bucket);
}
//TODO probably do something else here
}
}
}
@ -326,7 +343,27 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
uid_fingerprint: resource_uid,
info: info_bytes,
};
/* // Marking bridges as unreachable is reserved for blocked bridges
println!("BridgeLine to be replaced: {:?}", bridgeline);
let res = context.replace_with_new(bridgeline);
if res {
println!(
"BridgeLine successfully replaced: {:?}",
bridgeline
);
} else {
// 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);
}
}
}
}
/* Functionality for marking bridges as unreachable/blocked is currently not enabled as there is not
yet a reliable way to determine that a bridge is blocked. This means that migrations to unblocked bridges do not
currently work but can be easily enabled with a list of `blocked resources` from rdsys or another source with something
like the following:
println!("BridgeLine to be removed: {:?}", bridgeline);
let res = context.add_unreachable(bridgeline);
if res {
@ -339,21 +376,6 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
//TODO probably do something else here
}
*/
println!("BridgeLine to be replaced: {:?}", bridgeline);
let res = context.replace_with_new(bridgeline);
if res {
println!(
"BridgeLine successfully replaced: {:?}",
bridgeline
);
} else {
println!("'Gone' BridgeLine NOT replaced, marked removed!! : {:?}", bridgeline);
//TODO probably do something else here
}
}
}
}
context.allocate_leftover_bridges();
context.encrypt_table();
sleep(Duration::from_millis(1)).await;