From 94ce43f944505d662bde92b42bc3c232cf345771 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 18 Mar 2024 20:35:13 -0400 Subject: [PATCH] reliable + ensureordered is now the routingcontext and private route default --- veilid-core/src/veilid_api/api.rs | 7 +++- veilid-core/src/veilid_api/routing_context.rs | 8 ++-- veilid-core/src/veilid_api/types/safety.rs | 2 + .../example/integration_test/test_dht.dart | 38 ++++++----------- .../test_routing_context.dart | 15 +++---- veilid-python/tests/test_dht.py | 42 ++++++------------- veilid-python/tests/test_routing_context.py | 24 +++-------- 7 files changed, 47 insertions(+), 89 deletions(-) diff --git a/veilid-core/src/veilid_api/api.rs b/veilid-core/src/veilid_api/api.rs index 2c55cf80..d455fa42 100644 --- a/veilid-core/src/veilid_api/api.rs +++ b/veilid-core/src/veilid_api/api.rs @@ -200,7 +200,7 @@ impl VeilidAPI { //////////////////////////////////////////////////////////////// // Routing Context - /// Get a new `RoutingContext` object to use to send messages over the Veilid network. + /// Get a new `RoutingContext` object to use to send messages over the Veilid network with default safety, sequencing, and stability parameters. #[instrument(target = "veilid_api", level = "debug", skip_all, err, ret)] pub fn routing_context(&self) -> VeilidAPIResult { event!(target: "veilid_api", Level::DEBUG, @@ -246,6 +246,7 @@ impl VeilidAPI { // Private route allocation /// Allocate a new private route set with default cryptography and network options + /// Default settings are for Stability::Reliable and Sequencing::EnsureOrdered /// 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 /// @@ -256,12 +257,14 @@ impl VeilidAPI { self.new_custom_private_route( &VALID_CRYPTO_KINDS, Stability::Reliable, - Sequencing::PreferOrdered, + Sequencing::EnsureOrdered, ) .await } /// Allocate a new private route and specify a specific cryptosystem, stability and sequencing preference + /// Faster connections may be possible with Stability::LowLatency, and Sequencing::NoPreference at the + /// expense of some loss of messages /// 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 /// diff --git a/veilid-core/src/veilid_api/routing_context.rs b/veilid-core/src/veilid_api/routing_context.rs index 5d6dbeb8..6c9f3b85 100644 --- a/veilid-core/src/veilid_api/routing_context.rs +++ b/veilid-core/src/veilid_api/routing_context.rs @@ -55,8 +55,8 @@ impl RoutingContext { safety_selection: SafetySelection::Safe(SafetySpec { preferred_route: None, hop_count: c.network.rpc.default_route_hop_count as usize, - stability: Stability::default(), - sequencing: Sequencing::PreferOrdered, + stability: Stability::Reliable, + sequencing: Sequencing::EnsureOrdered, }), }), }) @@ -83,8 +83,8 @@ impl RoutingContext { self.with_safety(SafetySelection::Safe(SafetySpec { preferred_route: None, hop_count: c.network.rpc.default_route_hop_count as usize, - stability: Stability::default(), - sequencing: Sequencing::PreferOrdered, + stability: Stability::Reliable, + sequencing: Sequencing::EnsureOrdered, })) } diff --git a/veilid-core/src/veilid_api/types/safety.rs b/veilid-core/src/veilid_api/types/safety.rs index caa0b6f6..b49bbe7d 100644 --- a/veilid-core/src/veilid_api/types/safety.rs +++ b/veilid-core/src/veilid_api/types/safety.rs @@ -17,6 +17,7 @@ pub enum Sequencing { impl Default for Sequencing { fn default() -> Self { + // This is the default for veilid-core, and should not be the default used in any API-level code Self::NoPreference } } @@ -37,6 +38,7 @@ pub enum Stability { impl Default for Stability { fn default() -> Self { + // This is the default for veilid-core, and should not be the default used in any API-level code Self::LowLatency } } diff --git a/veilid-flutter/example/integration_test/test_dht.dart b/veilid-flutter/example/integration_test/test_dht.dart index a6bc3b1c..795ff83a 100644 --- a/veilid-flutter/example/integration_test/test_dht.dart +++ b/veilid-flutter/example/integration_test/test_dht.dart @@ -8,8 +8,7 @@ final bogusKey = TypedKey.fromString("VLD0:qD10lHHPD1_Qr23_Qy-1JnxTht12eaWwENVG_m2v7II"); Future testGetDHTValueUnopened() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { await expectLater( () async => await rc.getDHTValue(bogusKey, 0, forceRefresh: false), @@ -20,8 +19,7 @@ Future testGetDHTValueUnopened() async { } Future testOpenDHTRecordNonexistentNoWriter() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { await expectLater(() async => await rc.openDHTRecord(bogusKey), throwsA(isA())); @@ -31,8 +29,7 @@ Future testOpenDHTRecordNonexistentNoWriter() async { } Future testCloseDHTRecordNonexistent() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { await expectLater(() async => await rc.closeDHTRecord(bogusKey), throwsA(isA())); @@ -42,8 +39,7 @@ Future testCloseDHTRecordNonexistent() async { } Future testDeleteDHTRecordNonexistent() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { await expectLater(() async => await rc.deleteDHTRecord(bogusKey), throwsA(isA())); @@ -53,8 +49,7 @@ Future testDeleteDHTRecordNonexistent() async { } Future testCreateDeleteDHTRecordSimple() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { final rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 1)); await rc.closeDHTRecord(rec.key); @@ -65,8 +60,7 @@ Future testCreateDeleteDHTRecordSimple() async { } Future testCreateDeleteDHTRecordNoClose() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { final rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 1)); await rc.deleteDHTRecord(rec.key); @@ -76,8 +70,7 @@ Future testCreateDeleteDHTRecordNoClose() async { } Future testGetDHTValueNonexistent() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { final rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 1)); expect(await rc.getDHTValue(rec.key, 0), isNull); @@ -88,8 +81,7 @@ Future testGetDHTValueNonexistent() async { } Future testSetGetDHTValue() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { final rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 2)); expect(await rc.setDHTValue(rec.key, 0, utf8.encode("BLAH BLAH BLAH")), @@ -112,8 +104,7 @@ Future testSetGetDHTValue() async { } Future testOpenWriterDHTValue() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { var rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 2)); final key = rec.key; @@ -249,11 +240,9 @@ Future testWatchDHTValues(Stream updateStream) async { // Normally they would not get sent if the set comes from the same target // as the watch's target - final rcWatch = (await Veilid.instance.routingContext()) - .withSequencing(Sequencing.ensureOrdered, closeSelf: true); - final rcSet = (await Veilid.instance.routingContext()).withSafety( - const SafetySelectionUnsafe(sequencing: Sequencing.ensureOrdered), - closeSelf: true); + final rcWatch = await Veilid.instance.routingContext(); + final rcSet = await Veilid.instance + .unsafeRoutingContext(sequencing: Sequencing.ensureOrdered); try { // Make a DHT record var rec = await rcWatch.createDHTRecord(const DHTSchema.dflt(oCnt: 10)); @@ -360,8 +349,7 @@ Future testWatchDHTValues(Stream updateStream) async { } Future testInspectDHTRecord() async { - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { var rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 2)); diff --git a/veilid-flutter/example/integration_test/test_routing_context.dart b/veilid-flutter/example/integration_test/test_routing_context.dart index cfc0367c..f794350f 100644 --- a/veilid-flutter/example/integration_test/test_routing_context.dart +++ b/veilid-flutter/example/integration_test/test_routing_context.dart @@ -55,8 +55,7 @@ Future testAppMessageLoopback(Stream updateStream) async { await Veilid.instance.debug("purge routes"); // make a routing context that uses a safety route - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { // make a new local private route final prl = await Veilid.instance.newPrivateRoute(); @@ -97,8 +96,7 @@ Future testAppCallLoopback(Stream updateStream) async { await Veilid.instance.debug("purge routes"); // make a routing context that uses a safety route - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { // make a new local private route final prl = await Veilid.instance.newPrivateRoute(); @@ -155,8 +153,7 @@ Future testAppMessageLoopbackBigPackets( await Veilid.instance.debug("purge routes"); // make a routing context that uses a safety route - final rc = await Veilid.instance - .safeRoutingContext(sequencing: Sequencing.ensureOrdered); + final rc = await Veilid.instance.routingContext(); try { // make a new local private route final prl = await Veilid.instance.newPrivateRoute(); @@ -220,12 +217,10 @@ Future testAppCallLoopbackBigPackets( await Veilid.instance.debug("purge routes"); // make a routing context that uses a safety route - final rc = (await Veilid.instance.routingContext()) - .withSequencing(Sequencing.ensureOrdered, closeSelf: true); + final rc = await Veilid.instance.routingContext(); try { // make a new local private route - final prl = await Veilid.instance - .newCustomPrivateRoute(Stability.reliable, Sequencing.ensureOrdered); + final prl = await Veilid.instance.newPrivateRoute(); try { // import it as a remote route as well so we can send to it final prr = await Veilid.instance.importRemotePrivateRoute(prl.blob); diff --git a/veilid-python/tests/test_dht.py b/veilid-python/tests/test_dht.py index bdd99ace..5346e229 100644 --- a/veilid-python/tests/test_dht.py +++ b/veilid-python/tests/test_dht.py @@ -14,9 +14,8 @@ BOGUS_KEY = veilid.TypedKey.from_value( @pytest.mark.asyncio async def test_get_dht_value_unopened(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() + async with rc: with pytest.raises(veilid.VeilidAPIError): out = await rc.get_dht_value(BOGUS_KEY, veilid.ValueSubkey(0), False) @@ -24,9 +23,7 @@ async def test_get_dht_value_unopened(api_connection: veilid.VeilidAPI): @pytest.mark.asyncio async def test_open_dht_record_nonexistent_no_writer(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: with pytest.raises(veilid.VeilidAPIError): out = await rc.open_dht_record(BOGUS_KEY, None) @@ -34,9 +31,7 @@ async def test_open_dht_record_nonexistent_no_writer(api_connection: veilid.Veil @pytest.mark.asyncio async def test_close_dht_record_nonexistent(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: with pytest.raises(veilid.VeilidAPIError): await rc.close_dht_record(BOGUS_KEY) @@ -44,9 +39,7 @@ async def test_close_dht_record_nonexistent(api_connection: veilid.VeilidAPI): @pytest.mark.asyncio async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: with pytest.raises(veilid.VeilidAPIError): await rc.delete_dht_record(BOGUS_KEY) @@ -54,9 +47,7 @@ async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI): @pytest.mark.asyncio async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: rec = await rc.create_dht_record( veilid.DHTSchema.dflt(1), veilid.CryptoKind.CRYPTO_KIND_VLD0 @@ -67,9 +58,7 @@ async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI) @pytest.mark.asyncio async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: rec = await rc.create_dht_record(veilid.DHTSchema.dflt(1)) assert await rc.get_dht_value(rec.key, 0, False) == None @@ -79,9 +68,7 @@ async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI): @pytest.mark.asyncio async def test_set_get_dht_value(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2)) @@ -108,9 +95,7 @@ async def test_set_get_dht_value(api_connection: veilid.VeilidAPI): @pytest.mark.asyncio async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2)) key = rec.key @@ -239,9 +224,8 @@ async def test_watch_dht_values(): # So we can pretend to be a different node and get the watch updates # Normally they would not get sent if the set comes from the same target # as the watch's target - rcWatch = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rcWatch = await api.new_routing_context() + rcSet = await (await api.new_routing_context()).with_safety( veilid.SafetySelection.unsafe(veilid.Sequencing.ENSURE_ORDERED) ) @@ -328,9 +312,7 @@ async def test_watch_dht_values(): @pytest.mark.asyncio async def test_inspect_dht_record(api_connection: veilid.VeilidAPI): - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2)) diff --git a/veilid-python/tests/test_routing_context.py b/veilid-python/tests/test_routing_context.py index 81290727..2a45c405 100644 --- a/veilid-python/tests/test_routing_context.py +++ b/veilid-python/tests/test_routing_context.py @@ -26,9 +26,7 @@ async def test_routing_contexts(api_connection: veilid.VeilidAPI): async with rcp: pass - rc = await (await api_connection.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api_connection.new_routing_context() async with rc: pass @@ -65,9 +63,7 @@ async def test_routing_context_app_message_loopback(): await api.debug("purge routes") # make a routing context that uses a safety route - rc = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api.new_routing_context() async with rc: # make a new local private route prl, blob = await api.new_private_route() @@ -115,9 +111,7 @@ async def test_routing_context_app_call_loopback(): await api.debug("purge routes") # make a routing context - rc = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api.new_routing_context() async with rc: # make a new local private route prl, blob = await api.new_private_route() @@ -178,9 +172,7 @@ async def test_routing_context_app_message_loopback_big_packets(): await api.debug("purge routes") # make a routing context that uses a safety route - rc = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api.new_routing_context() async with rc: # make a new local private route prl, blob = await api.new_private_route() @@ -247,9 +239,7 @@ async def test_routing_context_app_call_loopback_big_packets(): app_call_task = asyncio.create_task(app_call_queue_task_handler(api), name="app call task") try: # make a routing context that uses a safety route - rc = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api.new_routing_context() async with rc: # make a new local private route prl, blob = await api.new_custom_private_route( @@ -297,9 +287,7 @@ async def test_routing_context_app_message_loopback_bandwidth(): await api.debug("purge routes") # make a routing context that uses a safety route - rc = await (await api.new_routing_context()).with_sequencing( - veilid.Sequencing.ENSURE_ORDERED - ) + rc = await api.new_routing_context() async with rc: # make a new local private route prl, blob = await api.new_private_route()