From 27c0f6e73aa854b5bab9174299f854aecbc98b8b Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Fri, 29 Sep 2023 09:38:12 -0400 Subject: [PATCH] fix dial info filter --- veilid-core/src/network_manager/send_data.rs | 8 ++- .../src/routing_table/routing_domains.rs | 52 +++++-------------- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/veilid-core/src/network_manager/send_data.rs b/veilid-core/src/network_manager/send_data.rs index 6818dbc3..c7643984 100644 --- a/veilid-core/src/network_manager/send_data.rs +++ b/veilid-core/src/network_manager/send_data.rs @@ -375,10 +375,14 @@ impl NetworkManager { } }; - // Dial info filter comes from the target node ref - let dial_info_filter = target_node_ref.dial_info_filter(); + // Dial info filter comes from the target node ref but must be filtered by this node's outbound capabilities + let dial_info_filter = target_node_ref.dial_info_filter().filtered( + &DialInfoFilter::all() + .with_address_type_set(peer_a.signed_node_info().node_info().address_types()) + .with_protocol_type_set(peer_a.signed_node_info().node_info().outbound_protocols())); let sequencing = target_node_ref.sequencing(); + // If the node has had lost questions or failures to send, prefer sequencing // to improve reliability. The node may be experiencing UDP fragmentation drops // or other firewalling issues and may perform better with TCP. diff --git a/veilid-core/src/routing_table/routing_domains.rs b/veilid-core/src/routing_table/routing_domains.rs index 32eb0eec..3139ca1b 100644 --- a/veilid-core/src/routing_table/routing_domains.rs +++ b/veilid-core/src/routing_table/routing_domains.rs @@ -278,6 +278,8 @@ fn first_filtered_dial_info_detail_between_nodes( sequencing: Sequencing, dif_sort: Option> ) -> Option { + + // Consider outbound capabilities let dial_info_filter = (*dial_info_filter).filtered( &DialInfoFilter::all() .with_address_type_set(from_node.address_types()) @@ -569,48 +571,22 @@ impl RoutingDomainDetail for LocalNetworkRoutingDomainDetail { sequencing: Sequencing, dif_sort: Option>, ) -> ContactMethod { - // Scope the filter down to protocols node A can do outbound - let dial_info_filter = dial_info_filter.filtered( - &DialInfoFilter::all() - .with_address_type_set(peer_a.signed_node_info().node_info().address_types()) - .with_protocol_type_set(peer_a.signed_node_info().node_info().outbound_protocols()), - ); - - // Apply sequencing and get sort - // Include sorting by external dial info sort for rotating through dialinfo - // based on an external preference table, for example the one kept by - // AddressFilter to deprioritize dialinfo that have recently failed to connect - let (ordered, dial_info_filter) = dial_info_filter.with_sequencing(sequencing); - let sort: Option> = if ordered { - if let Some(dif_sort) = dif_sort { - Some(Box::new(move |a, b| { - let mut ord = dif_sort(a,b); - if ord == core::cmp::Ordering::Equal { - ord = DialInfoDetail::ordered_sequencing_sort(a,b); - } - ord - })) - } else { - Some(Box::new(move |a,b| { DialInfoDetail::ordered_sequencing_sort(a,b) })) - } - } else if let Some(dif_sort) = dif_sort { - Some(Box::new(move |a,b| { dif_sort(a,b) })) - } else { - None + + // Get the nodeinfos for convenience + let node_a = peer_a.signed_node_info().node_info(); + let node_b = peer_b.signed_node_info().node_info(); + + // Get the node ids that would be used between these peers + let cck = common_crypto_kinds(&peer_a.node_ids().kinds(), &peer_b.node_ids().kinds()); + let Some(_best_ck) = cck.first().copied() else { + // No common crypto kinds between these nodes, can't contact + return ContactMethod::Unreachable; }; - // If the filter is dead then we won't be able to connect - if dial_info_filter.is_dead() { - return ContactMethod::Unreachable; - } - - let filter = |did: &DialInfoDetail| did.matches_filter(&dial_info_filter); - - let opt_target_did = peer_b.signed_node_info().node_info().first_filtered_dial_info_detail(sort, filter); - if let Some(target_did) = opt_target_did { + if let Some(target_did) = first_filtered_dial_info_detail_between_nodes(node_a, node_b, &dial_info_filter, sequencing, dif_sort) { return ContactMethod::Direct(target_did.dial_info); } - + ContactMethod::Unreachable } }