reliable + ensureordered is now the routingcontext and private route default

This commit is contained in:
Christien Rioux 2024-03-18 20:35:13 -04:00
parent c468d9c850
commit 94ce43f944
7 changed files with 47 additions and 89 deletions

View File

@ -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<RoutingContext> {
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
///

View File

@ -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,
}))
}

View File

@ -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
}
}

View File

@ -8,8 +8,7 @@ final bogusKey =
TypedKey.fromString("VLD0:qD10lHHPD1_Qr23_Qy-1JnxTht12eaWwENVG_m2v7II");
Future<void> 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<void> testGetDHTValueUnopened() async {
}
Future<void> 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<VeilidAPIException>()));
@ -31,8 +29,7 @@ Future<void> testOpenDHTRecordNonexistentNoWriter() async {
}
Future<void> 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<VeilidAPIException>()));
@ -42,8 +39,7 @@ Future<void> testCloseDHTRecordNonexistent() async {
}
Future<void> 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<VeilidAPIException>()));
@ -53,8 +49,7 @@ Future<void> testDeleteDHTRecordNonexistent() async {
}
Future<void> 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<void> testCreateDeleteDHTRecordSimple() async {
}
Future<void> 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<void> testCreateDeleteDHTRecordNoClose() async {
}
Future<void> 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<void> testGetDHTValueNonexistent() async {
}
Future<void> 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<void> testSetGetDHTValue() async {
}
Future<void> 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<void> testWatchDHTValues(Stream<VeilidUpdate> 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<void> testWatchDHTValues(Stream<VeilidUpdate> updateStream) async {
}
Future<void> 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));

View File

@ -55,8 +55,7 @@ Future<void> testAppMessageLoopback(Stream<VeilidUpdate> 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<void> testAppCallLoopback(Stream<VeilidUpdate> 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<void> 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<void> 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);

View File

@ -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))

View File

@ -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()