implement issue #388: Change app-facing default to Sequencing::PreferOrdered

This commit is contained in:
Christien Rioux 2024-08-20 22:29:02 +00:00
parent 22069d3430
commit 3b9626d79a
8 changed files with 17 additions and 27 deletions

View File

@ -268,17 +268,7 @@ impl BucketEntryInner {
} }
// Lower latency to the front // Lower latency to the front
if let Some(e1_latency) = &e1.peer_stats.latency { Self::cmp_fastest(e1, e2)
if let Some(e2_latency) = &e2.peer_stats.latency {
e1_latency.average.cmp(&e2_latency.average)
} else {
std::cmp::Ordering::Less
}
} else if e2.peer_stats.latency.is_some() {
std::cmp::Ordering::Greater
} else {
std::cmp::Ordering::Equal
}
} }
// Less is more reliable then older // Less is more reliable then older
@ -290,6 +280,7 @@ impl BucketEntryInner {
} }
// Lower timestamp to the front, recent or no timestamp is at the end // Lower timestamp to the front, recent or no timestamp is at the end
// First check consecutive-ping reliability timestamp
if let Some(e1_ts) = &e1.peer_stats.rpc_stats.first_consecutive_seen_ts { if let Some(e1_ts) = &e1.peer_stats.rpc_stats.first_consecutive_seen_ts {
if let Some(e2_ts) = &e2.peer_stats.rpc_stats.first_consecutive_seen_ts { if let Some(e2_ts) = &e2.peer_stats.rpc_stats.first_consecutive_seen_ts {
e1_ts.cmp(e2_ts) e1_ts.cmp(e2_ts)
@ -299,7 +290,8 @@ impl BucketEntryInner {
} else if e2.peer_stats.rpc_stats.first_consecutive_seen_ts.is_some() { } else if e2.peer_stats.rpc_stats.first_consecutive_seen_ts.is_some() {
std::cmp::Ordering::Greater std::cmp::Ordering::Greater
} else { } else {
std::cmp::Ordering::Equal // Then check 'since added to routing table' timestamp
e1.peer_stats.time_added.cmp(&e2.peer_stats.time_added)
} }
} }

View File

@ -362,7 +362,7 @@ impl RouteSpecStore {
entry1: &Option<Arc<BucketEntry>>, entry1: &Option<Arc<BucketEntry>>,
entry2: &Option<Arc<BucketEntry>>| entry2: &Option<Arc<BucketEntry>>|
-> Ordering { -> Ordering {
// Our own node is filtered out // Our own node is filtered out, so it is safe to unwrap here
let entry1 = entry1.as_ref().unwrap().clone(); let entry1 = entry1.as_ref().unwrap().clone();
let entry2 = entry2.as_ref().unwrap().clone(); let entry2 = entry2.as_ref().unwrap().clone();
let entry1_node_ids = entry1.with_inner(|e| e.node_ids()); let entry1_node_ids = entry1.with_inner(|e| e.node_ids());
@ -398,6 +398,7 @@ impl RouteSpecStore {
.signed_node_info(RoutingDomain::PublicInternet) .signed_node_info(RoutingDomain::PublicInternet)
.map(|sni| sni.has_sequencing_matched_dial_info(sequencing)) .map(|sni| sni.has_sequencing_matched_dial_info(sequencing))
.unwrap_or(false); .unwrap_or(false);
// Reverse this comparison because ordered is preferable (less)
e2_can_do_ordered.cmp(&e1_can_do_ordered) e2_can_do_ordered.cmp(&e1_can_do_ordered)
}) })
}); });
@ -406,8 +407,8 @@ impl RouteSpecStore {
} }
} }
// apply stability preference
// always prioritize reliable nodes, but sort by oldest or fastest // always prioritize reliable nodes, but sort by oldest or fastest
entry1.with_inner(|e1| { entry1.with_inner(|e1| {
entry2.with_inner(|e2| match stability { entry2.with_inner(|e2| match stability {
Stability::LowLatency => BucketEntryInner::cmp_fastest_reliable(cur_ts, e1, e2), Stability::LowLatency => BucketEntryInner::cmp_fastest_reliable(cur_ts, e1, e2),

View File

@ -213,8 +213,8 @@ impl RoutingTable {
// These will be used by test_remote_route as well // These will be used by test_remote_route as well
match rss.allocate_route( match rss.allocate_route(
&VALID_CRYPTO_KINDS, &VALID_CRYPTO_KINDS,
Stability::default(), Stability::Reliable,
Sequencing::EnsureOrdered, Sequencing::PreferOrdered,
default_route_hop_count, default_route_hop_count,
DirectionSet::all(), DirectionSet::all(),
&[], &[],

View File

@ -253,7 +253,7 @@ impl VeilidAPI {
// Private route allocation // Private route allocation
/// Allocate a new private route set with default cryptography and network options. /// Allocate a new private route set with default cryptography and network options.
/// Default settings are for [Stability::Reliable] and [Sequencing::EnsureOrdered]. /// Default settings are for [Stability::Reliable] and [Sequencing::PreferOrdered].
/// Returns a route id and a publishable 'blob' with the route encrypted with each crypto kind. /// Returns a route id and a publishable 'blob' with the route encrypted with each crypto kind.
/// Those nodes importing the blob will have their choice of which crypto kind to use. /// Those nodes importing the blob will have their choice of which crypto kind to use.
/// ///
@ -264,7 +264,7 @@ impl VeilidAPI {
self.new_custom_private_route( self.new_custom_private_route(
&VALID_CRYPTO_KINDS, &VALID_CRYPTO_KINDS,
Stability::Reliable, Stability::Reliable,
Sequencing::EnsureOrdered, Sequencing::PreferOrdered,
) )
.await .await
} }

View File

@ -56,7 +56,7 @@ impl RoutingContext {
preferred_route: None, preferred_route: None,
hop_count: c.network.rpc.default_route_hop_count as usize, hop_count: c.network.rpc.default_route_hop_count as usize,
stability: Stability::Reliable, stability: Stability::Reliable,
sequencing: Sequencing::EnsureOrdered, sequencing: Sequencing::PreferOrdered,
}), }),
}), }),
}) })
@ -68,7 +68,7 @@ impl RoutingContext {
/// Default values for hop count, stability and sequencing preferences are used. /// Default values for hop count, stability and sequencing preferences are used.
/// ///
/// * Hop count default is dependent on config, but is set to 1 extra hop. /// * Hop count default is dependent on config, but is set to 1 extra hop.
/// * Stability default is to choose 'low latency' routes, preferring them over long-term reliability. /// * Stability default is to choose reliable routes, preferring them over low latency.
/// * Sequencing default is to prefer ordered before unordered message delivery. /// * Sequencing default is to prefer ordered before unordered message delivery.
/// ///
/// To customize the safety selection in use, use [RoutingContext::with_safety()]. /// To customize the safety selection in use, use [RoutingContext::with_safety()].
@ -84,7 +84,7 @@ impl RoutingContext {
preferred_route: None, preferred_route: None,
hop_count: c.network.rpc.default_route_hop_count as usize, hop_count: c.network.rpc.default_route_hop_count as usize,
stability: Stability::Reliable, stability: Stability::Reliable,
sequencing: Sequencing::EnsureOrdered, sequencing: Sequencing::PreferOrdered,
})) }))
} }

View File

@ -283,8 +283,7 @@ Future<void> testWatchDHTValues(Stream<VeilidUpdate> updateStream) async {
// as the watch's target // as the watch's target
final rcSet = await Veilid.instance.routingContext(); final rcSet = await Veilid.instance.routingContext();
final rcWatch = await Veilid.instance final rcWatch = await Veilid.instance.unsafeRoutingContext();
.unsafeRoutingContext(sequencing: Sequencing.ensureOrdered);
try { try {
// Make a DHT record // Make a DHT record
var rec = await rcWatch.createDHTRecord(const DHTSchema.dflt(oCnt: 10)); var rec = await rcWatch.createDHTRecord(const DHTSchema.dflt(oCnt: 10));

View File

@ -227,9 +227,7 @@ async def test_watch_dht_values():
# as the watch's target # as the watch's target
rcWatch = await api.new_routing_context() rcWatch = await api.new_routing_context()
rcSet = await (await api.new_routing_context()).with_safety( rcSet = await (await api.new_routing_context()).with_safety(veilid.SafetySelection.unsafe())
veilid.SafetySelection.unsafe(veilid.Sequencing.ENSURE_ORDERED)
)
async with rcWatch, rcSet: async with rcWatch, rcSet:
# Make a DHT record # Make a DHT record
rec = await rcWatch.create_dht_record(veilid.DHTSchema.dflt(10)) rec = await rcWatch.create_dht_record(veilid.DHTSchema.dflt(10))

View File

@ -506,7 +506,7 @@ class SafetySelection:
setattr(self, k, v) setattr(self, k, v)
@classmethod @classmethod
def unsafe(cls, sequencing: Sequencing) -> Self: def unsafe(cls, sequencing: Sequencing = Sequencing.PREFER_ORDERED) -> Self:
return cls(SafetySelectionKind.UNSAFE, sequencing=sequencing) return cls(SafetySelectionKind.UNSAFE, sequencing=sequencing)
@classmethod @classmethod