fix dial info filter
This commit is contained in:
parent
91031531e4
commit
27c0f6e73a
@ -375,10 +375,14 @@ impl NetworkManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dial info filter comes from the target node ref
|
// 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();
|
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();
|
let sequencing = target_node_ref.sequencing();
|
||||||
|
|
||||||
|
|
||||||
// If the node has had lost questions or failures to send, prefer 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
|
// to improve reliability. The node may be experiencing UDP fragmentation drops
|
||||||
// or other firewalling issues and may perform better with TCP.
|
// or other firewalling issues and may perform better with TCP.
|
||||||
|
@ -278,6 +278,8 @@ fn first_filtered_dial_info_detail_between_nodes(
|
|||||||
sequencing: Sequencing,
|
sequencing: Sequencing,
|
||||||
dif_sort: Option<Arc<DialInfoDetailSort>>
|
dif_sort: Option<Arc<DialInfoDetailSort>>
|
||||||
) -> Option<DialInfoDetail> {
|
) -> Option<DialInfoDetail> {
|
||||||
|
|
||||||
|
// Consider outbound capabilities
|
||||||
let dial_info_filter = (*dial_info_filter).filtered(
|
let dial_info_filter = (*dial_info_filter).filtered(
|
||||||
&DialInfoFilter::all()
|
&DialInfoFilter::all()
|
||||||
.with_address_type_set(from_node.address_types())
|
.with_address_type_set(from_node.address_types())
|
||||||
@ -569,45 +571,19 @@ impl RoutingDomainDetail for LocalNetworkRoutingDomainDetail {
|
|||||||
sequencing: Sequencing,
|
sequencing: Sequencing,
|
||||||
dif_sort: Option<Arc<DialInfoDetailSort>>,
|
dif_sort: Option<Arc<DialInfoDetailSort>>,
|
||||||
) -> ContactMethod {
|
) -> 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
|
// Get the nodeinfos for convenience
|
||||||
// Include sorting by external dial info sort for rotating through dialinfo
|
let node_a = peer_a.signed_node_info().node_info();
|
||||||
// based on an external preference table, for example the one kept by
|
let node_b = peer_b.signed_node_info().node_info();
|
||||||
// AddressFilter to deprioritize dialinfo that have recently failed to connect
|
|
||||||
let (ordered, dial_info_filter) = dial_info_filter.with_sequencing(sequencing);
|
// Get the node ids that would be used between these peers
|
||||||
let sort: Option<Box<DialInfoDetailSort>> = if ordered {
|
let cck = common_crypto_kinds(&peer_a.node_ids().kinds(), &peer_b.node_ids().kinds());
|
||||||
if let Some(dif_sort) = dif_sort {
|
let Some(_best_ck) = cck.first().copied() else {
|
||||||
Some(Box::new(move |a, b| {
|
// No common crypto kinds between these nodes, can't contact
|
||||||
let mut ord = dif_sort(a,b);
|
return ContactMethod::Unreachable;
|
||||||
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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the filter is dead then we won't be able to connect
|
if let Some(target_did) = first_filtered_dial_info_detail_between_nodes(node_a, node_b, &dial_info_filter, sequencing, dif_sort) {
|
||||||
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 {
|
|
||||||
return ContactMethod::Direct(target_did.dial_info);
|
return ContactMethod::Direct(target_did.dial_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user