diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 802a5a5..c04cef1 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -91,11 +91,12 @@ impl LoxServerContext { pub fn remove_extra_bridges(&self) -> [BridgeLine; MAX_BRIDGES_PER_BUCKET] { let mut extra_bridges = self.extra_bridges.lock().unwrap(); - [ - extra_bridges.remove(0), - extra_bridges.remove(1), - extra_bridges.remove(2), - ] + let mut return_bridges = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; + for i in 0..MAX_BRIDGES_PER_BUCKET{ + return_bridges[i] = extra_bridges.remove(i); + } + + return_bridges } diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index 13d4e41..e3c5309 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -7,6 +7,7 @@ use hyper::{ service::{make_service_fn, service_fn}, Body, Method, Request, Response, Server, StatusCode, }; +use lox::bridge_table::MAX_BRIDGES_PER_BUCKET; use lox::bridge_table::{BridgeLine, BRIDGE_BYTES}; use lox::{BridgeAuth, BridgeDb}; @@ -192,11 +193,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver) { Rdsys { resourcediff } => { if let Some(new_resources) = resourcediff.new { let mut count = 0; - let mut bucket = [ - BridgeLine::default(), - BridgeLine::default(), - BridgeLine::default(), - ]; + let mut bucket= [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; for pt in new_resources { println!("A NEW RESOURCE: {:?}", pt); for resource in pt.1 { @@ -225,7 +222,7 @@ async fn context_manager(mut context_rx: mpsc::Receiver) { info: info_bytes, }; println!("Now it's a bridgeline: {:?}", bridgeline); - if count < 2 { + if count < MAX_BRIDGES_PER_BUCKET-1 { bucket[count] = bridgeline; count += 1; } else { @@ -233,18 +230,14 @@ async fn context_manager(mut context_rx: mpsc::Receiver) { // 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(), - BridgeLine::default(), - BridgeLine::default(), - ]; + bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET]; } } } // Handle the extra buckets that were not allocated already if count != 0 { for val in 0..count { - if context.extra_bridges.lock().unwrap().len() < 2 { + if context.extra_bridges.lock().unwrap().len() < (MAX_BRIDGES_PER_BUCKET-1) { context.append_extra_bridges(bucket[val]); } else { bucket = context.remove_extra_bridges();