From 9bc907fddd76eed88515ed9cbdcd6ba48316ab67 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 5 Mar 2023 18:16:01 +0000 Subject: [PATCH] bugfixes --- .../routing_table/route_spec_store/permutation.rs | 6 +++--- .../route_spec_store/route_spec_store.rs | 12 ++++++------ veilid-core/src/routing_table/routing_table_inner.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/veilid-core/src/routing_table/route_spec_store/permutation.rs b/veilid-core/src/routing_table/route_spec_store/permutation.rs index 9a7f9812..691e75c3 100644 --- a/veilid-core/src/routing_table/route_spec_store/permutation.rs +++ b/veilid-core/src/routing_table/route_spec_store/permutation.rs @@ -16,7 +16,7 @@ fn _get_route_permutation_count(hop_count: usize) -> usize { (3..hop_count).into_iter().fold(2usize, |acc, x| acc * x) } pub type PermReturnType = (Vec, bool); -pub type PermFunc<'t> = Box Option + Send + 't>; +pub type PermFunc<'t> = Box Option + Send + 't>; /// get the route permutation at particular 'perm' index, starting at the 'start' index /// for a set of 'hop_count' nodes. the first node is always fixed, and the maximum @@ -25,7 +25,7 @@ pub type PermFunc<'t> = Box Option + Send + pub fn with_route_permutations( hop_count: usize, start: usize, - f: &PermFunc, + f: &mut PermFunc, ) -> Option { if hop_count == 0 { unreachable!(); @@ -44,7 +44,7 @@ pub fn with_route_permutations( fn heaps_permutation( permutation: &mut [usize], size: usize, - f: &PermFunc, + f: &mut PermFunc, ) -> Option { if size == 1 { return f(&permutation); diff --git a/veilid-core/src/routing_table/route_spec_store/route_spec_store.rs b/veilid-core/src/routing_table/route_spec_store/route_spec_store.rs index 913a5b17..4b0d3e1f 100644 --- a/veilid-core/src/routing_table/route_spec_store/route_spec_store.rs +++ b/veilid-core/src/routing_table/route_spec_store/route_spec_store.rs @@ -168,7 +168,7 @@ impl RouteSpecStore { fn allocate_route_inner( &self, inner: &mut RouteSpecStoreInner, - rti: &RoutingTableInner, + rti: &mut RoutingTableInner, crypto_kinds: &[CryptoKind], stability: Stability, sequencing: Sequencing, @@ -351,7 +351,7 @@ impl RouteSpecStore { let nodes_pi: Vec = nodes.iter().map(|nr| nr.locked(rti).make_peer_info(RoutingDomain::PublicInternet).unwrap()).collect(); // Now go through nodes and try to build a route we haven't seen yet - let perm_func = Box::new(|permutation: &[usize]| { + let mut perm_func = Box::new(|permutation: &[usize]| { /// Get the hop cache key for a particular route permutation /// uses the same algorithm as RouteSetSpecDetail::make_cache_key @@ -372,7 +372,7 @@ impl RouteSpecStore { // Ensure the route doesn't contain both a node and its relay let mut seen_nodes: HashSet = HashSet::new(); for n in permutation { - let node = nodes.get(*n).unwrap().locked(rti); + let node = nodes.get(*n).unwrap().locked_mut(rti); if !seen_nodes.insert(node.best_node_id()) { // Already seen this node, should not be in the route twice return None; @@ -471,7 +471,7 @@ impl RouteSpecStore { for start in 0..(nodes.len() - hop_count) { // Try the permutations available starting with 'start' - if let Some((rn, cds)) = with_route_permutations(hop_count, start, &perm_func) { + if let Some((rn, cds)) = with_route_permutations(hop_count, start, &mut perm_func) { route_nodes = rn; can_do_sequenced = cds; break; @@ -1070,7 +1070,7 @@ impl RouteSpecStore { fn get_route_for_safety_spec_inner( &self, inner: &mut RouteSpecStoreInner, - rti: &RoutingTableInner, + rti: &mut RoutingTableInner, crypto_kind: CryptoKind, safety_spec: &SafetySpec, direction: DirectionSet, @@ -1146,7 +1146,7 @@ impl RouteSpecStore { ) -> EyreResult> { let inner = &mut *self.inner.lock(); let routing_table = self.unlocked_inner.routing_table.clone(); - let rti = &*routing_table.inner.read(); + let rti = &mut *routing_table.inner.write(); Ok(self.get_route_for_safety_spec_inner( inner, diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index 2da59280..c5104ae7 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -993,12 +993,16 @@ impl RoutingTableInner { // add all nodes that match filter self.with_entries(cur_ts, BucketEntryState::Unreliable, |rti, v| { // Apply filter + let mut filtered = false; for filter in &mut filters { - if filter(rti, Some(v.clone())) { - nodes.push(Some(v.clone())); + if !filter(rti, Some(v.clone())) { + filtered = true; break; } } + if !filtered { + nodes.push(Some(v.clone())); + } Option::<()>::None });