diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 011f94d..9858c01 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -59,25 +59,25 @@ impl LoxServerContext { pub fn handle_working_resources(&self, working_resources: Vec) -> Vec { let mut accounted_for_bridges: Vec = Vec::new(); - let bridgelines = parse_into_bridgelines(working_resources); + let (bridgelines, blocked_bridgelines) = parse_into_bridgelines(working_resources); + /* TODO: Functionality for marking bridges as unreachable/blocked should eventually happen here. + It 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 by parsing the + list of `blocked resources` from rdsys or another source with something like the following: + let res = context.add_unreachable(bridgeline); + */ + for bridge in blocked_bridgelines { + let res = self.add_unreachable(bridge); + if res { + println!("BridgeLine {:?} successfully marked unreachable", bridge); + } else { + println!( + "BridgeLine {:?} NOT marked unreachable, saved for next update!", + bridge.uid_fingerprint + ); + } + } for bridge in bridgelines { - /* TODO: Functionality for marking bridges as unreachable/blocked should eventually happen here. - It 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 by parsing the - list of `blocked resources` from rdsys or another source with something like the following: - let res = context.add_unreachable(bridgeline); - if res { - println!( - "BridgeLine {:?} successfully marked unreachable: {:?}", - bridgeline - ); - } else { - println!( - "BridgeLine {:?} NOT marked unreachable, saved for next update!", - bridge.uid_fingerprint - ); - } - */ let res = self.update_bridge(bridge); if res { println!( @@ -298,14 +298,6 @@ impl LoxServerContext { result } - /* TODO: Uncomment when bridge blocking is finalized - pub fn add_unreachable(&self, bridgeline: BridgeLine) -> bool { - let mut ba_obj = self.ba.lock().unwrap(); - let mut db_obj = self.db.lock().unwrap(); - ba_obj.bridge_unreachable(&bridgeline, &mut db_obj) - } - */ - // Mark bridges as blocked pub fn mark_blocked(&self, bridgeline: BridgeLine) -> bool { let mut ba_obj = self.ba.lock().unwrap(); let mut db_obj = self.db.lock().unwrap(); diff --git a/crates/lox-distributor/src/resource_parser.rs b/crates/lox-distributor/src/resource_parser.rs index 9136450..8843d90 100644 --- a/crates/lox-distributor/src/resource_parser.rs +++ b/crates/lox-distributor/src/resource_parser.rs @@ -1,12 +1,14 @@ use chrono::{Duration, Utc}; +use futures::executor::block_on; use lox_library::bridge_table::{BridgeLine, BRIDGE_BYTES, MAX_BRIDGES_PER_BUCKET}; use rdsys_backend::proto::Resource; pub const ACCEPTED_HOURS_OF_FAILURE: i64 = 3; // Parse each resource from rdsys into a Bridgeline as expected by the Lox Bridgetable -pub fn parse_into_bridgelines(resources: Vec) -> Vec { +pub fn parse_into_bridgelines(resources: Vec) -> (Vec, Vec) { let mut bridgelines: Vec = Vec::new(); + let mut blocked_bridgelines: Vec = Vec::new(); for resource in resources { let mut ip_bytes: [u8; 16] = [0; 16]; ip_bytes[..resource.address.len()].copy_from_slice(resource.address.as_bytes()); @@ -27,14 +29,23 @@ pub fn parse_into_bridgelines(resources: Vec) -> Vec { let mut info_bytes: [u8; BRIDGE_BYTES - 26] = [0; BRIDGE_BYTES - 26]; info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes()); - bridgelines.push(BridgeLine { - addr: ip_bytes, - port: resource.port, - uid_fingerprint: resource_uid, - info: info_bytes, - }) + if !resource.blocked_in.get("RU").unwrap() { + bridgelines.push(BridgeLine { + addr: ip_bytes, + port: resource.port, + uid_fingerprint: resource_uid, + info: info_bytes, + }); + } else { + blocked_bridgelines.push(BridgeLine { + addr: ip_bytes, + port: resource.port, + uid_fingerprint: resource_uid, + info: info_bytes, + }); + } } - bridgelines + (bridgelines, blocked_bridgelines) } // Allocate each Bridgeline into a bucket that will later be allocated into spare buckets or open invitation buckets @@ -90,8 +101,8 @@ pub fn sort_for_parsing(resources: Vec) -> (Vec, Vec