fanout work

This commit is contained in:
Christien Rioux 2023-09-08 20:38:31 -04:00
parent aa490d5e65
commit 0aa7cf5ef2
10 changed files with 146 additions and 129 deletions

View file

@ -1,8 +1,10 @@
use super::*;
impl RoutingTable {
/// Utility to find all closest nodes to a particular key, including possibly our own node and nodes further away from the key than our own, returning their peer info
pub fn find_all_closest_peers(
/// Utility to find the closest nodes to a particular key, preferring reliable nodes first,
/// including possibly our own node and nodes further away from the key than our own,
/// returning their peer info
pub fn find_preferred_closest_peers(
&self,
key: TypedKey,
capabilities: &[Capability],
@ -49,7 +51,7 @@ impl RoutingTable {
};
let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet);
let closest_nodes = match self.find_closest_nodes(
let closest_nodes = match self.find_preferred_closest_nodes(
node_count,
key,
filters,
@ -68,9 +70,10 @@ impl RoutingTable {
NetworkResult::value(closest_nodes)
}
/// Utility to find nodes that are closer to a key than our own node, returning their peer info
/// Utility to find nodes that are closer to a key than our own node,
/// preferring reliable nodes first, and returning their peer info
/// Can filter based on a particular set of capabiltiies
pub fn find_peers_closer_to_key(
pub fn find_preferred_peers_closer_to_key(
&self,
key: TypedKey,
required_capabilities: Vec<Capability>,
@ -126,7 +129,7 @@ impl RoutingTable {
};
//
let closest_nodes = match self.find_closest_nodes(
let closest_nodes = match self.find_preferred_closest_nodes(
node_count,
key,
filters,

View file

@ -939,7 +939,7 @@ impl RoutingTable {
let filters = VecDeque::from([filter]);
self.find_fastest_nodes(
self.find_preferred_fastest_nodes(
protocol_types_len * 2 * max_per_type,
filters,
|_rti, entry: Option<Arc<BucketEntry>>| {
@ -990,7 +990,7 @@ impl RoutingTable {
.find_peers_with_sort_and_filter(node_count, cur_ts, filters, compare, transform)
}
pub fn find_fastest_nodes<'a, T, O>(
pub fn find_preferred_fastest_nodes<'a, T, O>(
&self,
node_count: usize,
filters: VecDeque<RoutingTableEntryFilter>,
@ -1001,10 +1001,10 @@ impl RoutingTable {
{
self.inner
.read()
.find_fastest_nodes(node_count, filters, transform)
.find_preferred_fastest_nodes(node_count, filters, transform)
}
pub fn find_closest_nodes<'a, T, O>(
pub fn find_preferred_closest_nodes<'a, T, O>(
&self,
node_count: usize,
node_id: TypedKey,
@ -1016,14 +1016,14 @@ impl RoutingTable {
{
self.inner
.read()
.find_closest_nodes(node_count, node_id, filters, transform)
.find_preferred_closest_nodes(node_count, node_id, filters, transform)
}
pub fn sort_and_clean_closest_noderefs(
&self,
node_id: TypedKey,
closest_nodes: &mut Vec<NodeRef>,
) {
closest_nodes: &[NodeRef],
) -> Vec<NodeRef> {
self.inner
.read()
.sort_and_clean_closest_noderefs(node_id, closest_nodes)

View file

@ -963,7 +963,7 @@ impl RoutingTableInner {
}) as RoutingTableEntryFilter;
filters.push_front(public_node_filter);
self.find_fastest_nodes(
self.find_preferred_fastest_nodes(
node_count,
filters,
|_rti: &RoutingTableInner, v: Option<Arc<BucketEntry>>| {
@ -1062,7 +1062,7 @@ impl RoutingTableInner {
out
}
pub fn find_fastest_nodes<T, O>(
pub fn find_preferred_fastest_nodes<T, O>(
&self,
node_count: usize,
mut filters: VecDeque<RoutingTableEntryFilter>,
@ -1154,7 +1154,7 @@ impl RoutingTableInner {
out
}
pub fn find_closest_nodes<T, O>(
pub fn find_preferred_closest_nodes<T, O>(
&self,
node_count: usize,
node_id: TypedKey,
@ -1242,8 +1242,8 @@ impl RoutingTableInner {
pub fn sort_and_clean_closest_noderefs(
&self,
node_id: TypedKey,
closest_nodes: &mut Vec<NodeRef>,
) {
closest_nodes: &[NodeRef],
) -> Vec<NodeRef> {
// Lock all noderefs
let kind = node_id.kind;
let mut closest_nodes_locked: Vec<NodeRefLocked> = closest_nodes
@ -1263,7 +1263,7 @@ impl RoutingTableInner {
closest_nodes_locked.sort_by(sort);
// Unlock noderefs
*closest_nodes = closest_nodes_locked.iter().map(|x| x.unlocked()).collect();
closest_nodes_locked.iter().map(|x| x.unlocked()).collect()
}
}
@ -1271,7 +1271,6 @@ fn make_closest_noderef_sort(
crypto: Crypto,
node_id: TypedKey,
) -> impl Fn(&NodeRefLocked, &NodeRefLocked) -> core::cmp::Ordering {
let cur_ts = get_aligned_timestamp();
let kind = node_id.kind;
// Get cryptoversion to check distance with
let vcrypto = crypto.get(kind).unwrap();
@ -1282,19 +1281,8 @@ fn make_closest_noderef_sort(
return core::cmp::Ordering::Equal;
}
// reliable nodes come first, pessimistically treating our own node as unreliable
a.operate(|_rti, a_entry| {
b.operate(|_rti, b_entry| {
let ra = a_entry.check_reliable(cur_ts);
let rb = b_entry.check_reliable(cur_ts);
if ra != rb {
if ra {
return core::cmp::Ordering::Less;
} else {
return core::cmp::Ordering::Greater;
}
}
// get keys
let a_key = a_entry.node_ids().get(kind).unwrap();
let b_key = b_entry.node_ids().get(kind).unwrap();

View file

@ -67,7 +67,7 @@ impl RoutingTable {
) as RoutingTableEntryFilter;
filters.push_front(filter);
let noderefs = routing_table.find_fastest_nodes(
let noderefs = routing_table.find_preferred_fastest_nodes(
min_peer_count,
filters,
|_rti, entry: Option<Arc<BucketEntry>>| {