From da4d7c962f150df17f2ab90622c79304be16ab5a Mon Sep 17 00:00:00 2001 From: onyinyang Date: Thu, 11 May 2023 11:07:42 -0400 Subject: [PATCH] Add fix for failure to replace bridges - Change text for disabled functionality for blocked bridges --- crates/lox-distributor/src/lox_context.rs | 6 +++ crates/lox-distributor/src/main.rs | 56 ++++++++++++++++------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 6111aba..d79ac30 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -80,6 +80,7 @@ pub struct LoxServerContext { pub db: Arc>, pub ba: Arc>, pub extra_bridges: Arc>>, + pub unreplaced_bridges: Arc>>, } 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(); diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 07f8234..1dbd0bb 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -184,6 +184,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver) { 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) { 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) { 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) { 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) { 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) { //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;