safety by default

This commit is contained in:
Christien Rioux 2023-11-05 18:38:05 -05:00
parent 88389a1b78
commit ee375ad430
22 changed files with 1406 additions and 1593 deletions

View file

@ -22,7 +22,7 @@ async def test_routing_contexts(api_connection: veilid.VeilidAPI):
rc = await api_connection.new_routing_context()
async with rc:
rcp = await rc.with_privacy(release=False)
rcp = await rc.with_default_safety(release=False)
async with rcp:
pass
@ -32,15 +32,15 @@ async def test_routing_contexts(api_connection: veilid.VeilidAPI):
async with rc:
pass
rc = await (await api_connection.new_routing_context()).with_custom_privacy(
rc = await (await api_connection.new_routing_context()).with_safety(
veilid.SafetySelection.safe(
veilid.SafetySpec(None, 2, veilid.Stability.RELIABLE, veilid.Sequencing.ENSURE_ORDERED)
veilid.SafetySpec(None, 2, veilid.Stability.LOW_LATENCY, veilid.Sequencing.NO_PREFERENCE)
)
)
await rc.release()
rc = await (await api_connection.new_routing_context()).with_custom_privacy(
veilid.SafetySelection.unsafe(veilid.Sequencing.ENSURE_ORDERED)
rc = await (await api_connection.new_routing_context()).with_safety(
veilid.SafetySelection.unsafe(veilid.Sequencing.PREFER_ORDERED)
)
await rc.release()
@ -65,7 +65,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_privacy()
rc = await api.new_routing_context()
async with rc:
# make a new local private route
prl, blob = await api.new_private_route()
@ -105,7 +105,7 @@ async def test_routing_context_app_call_loopback():
await api.debug("purge routes")
# make a routing context that uses a safety route
rc = await (await (await api.new_routing_context()).with_privacy()).with_sequencing(
rc = await (await api.new_routing_context()).with_sequencing(
veilid.Sequencing.ENSURE_ORDERED
)
async with rc:
@ -160,7 +160,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 (await api.new_routing_context()).with_privacy()).with_sequencing(
rc = await (await api.new_routing_context()).with_sequencing(
veilid.Sequencing.ENSURE_ORDERED
)
async with rc:
@ -225,7 +225,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")
# make a routing context that uses a safety route
rc = await (await (await api.new_routing_context()).with_privacy()).with_sequencing(
rc = await (await api.new_routing_context()).with_sequencing(
veilid.Sequencing.ENSURE_ORDERED
)
async with rc:
@ -269,8 +269,8 @@ 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 (await api.new_routing_context()).with_privacy()).with_sequencing(veilid.Sequencing.ENSURE_ORDERED)
# rc = await (await api.new_routing_context()).with_privacy()
# rc = await (await api.new_routing_context()).with_sequencing(veilid.Sequencing.ENSURE_ORDERED)
# rc = await api.new_routing_context()
rc = await api.new_routing_context()
async with rc:
# make a new local private route

View file

@ -22,11 +22,11 @@ class RoutingContext(ABC):
pass
@abstractmethod
async def with_privacy(self, release=True) -> Self:
async def with_default_safety(self, release=True) -> Self:
pass
@abstractmethod
async def with_custom_privacy(
async def with_safety(
self, safety_selection: types.SafetySelection, release=True
) -> Self:
pass
@ -35,6 +35,10 @@ class RoutingContext(ABC):
async def with_sequencing(self, sequencing: types.Sequencing, release=True) -> Self:
pass
@abstractmethod
async def safety(self) -> types.SafetySelection:
pass
@abstractmethod
async def app_call(self, target: types.TypedKey | types.RouteId, request: bytes) -> bytes:
pass

View file

@ -446,26 +446,26 @@ class _JsonRoutingContext(RoutingContext):
)
self.done = True
async def with_privacy(self, release=True) -> Self:
async def with_default_safety(self, release=True) -> Self:
new_rc_id = raise_api_result(
await self.api.send_ndjson_request(
Operation.ROUTING_CONTEXT,
validate=validate_rc_op,
rc_id=self.rc_id,
rc_op=RoutingContextOperation.WITH_PRIVACY,
rc_op=RoutingContextOperation.WITH_DEFAULT_SAFETY,
)
)
if release:
await self.release()
return self.__class__(self.api, new_rc_id)
async def with_custom_privacy(self, safety_selection: SafetySelection, release=True) -> Self:
async def with_safety(self, safety_selection: SafetySelection, release=True) -> Self:
new_rc_id = raise_api_result(
await self.api.send_ndjson_request(
Operation.ROUTING_CONTEXT,
validate=validate_rc_op,
rc_id=self.rc_id,
rc_op=RoutingContextOperation.WITH_CUSTOM_PRIVACY,
rc_op=RoutingContextOperation.WITH_SAFETY,
safety_selection=safety_selection,
)
)
@ -487,6 +487,19 @@ class _JsonRoutingContext(RoutingContext):
await self.release()
return self.__class__(self.api, new_rc_id)
async def safety(
self
) -> SafetySelection:
return SafetySelection.from_json(
raise_api_result(
await self.api.send_ndjson_request(
Operation.ROUTING_CONTEXT,
validate=validate_rc_op,
rc_id=self.rc_id,
rc_op=RoutingContextOperation.SAFETY,
)
)
)
async def app_call(self, target: TypedKey | RouteId, message: bytes) -> bytes:
return urlsafe_b64decode_no_pad(
raise_api_result(

View file

@ -33,9 +33,10 @@ class Operation(StrEnum):
class RoutingContextOperation(StrEnum):
INVALID_ID = "InvalidId"
RELEASE = "Release"
WITH_PRIVACY = "WithPrivacy"
WITH_CUSTOM_PRIVACY = "WithCustomPrivacy"
WITH_DEFAULT_SAFETY = "WithDefaultSafety"
WITH_SAFETY = "WithSafety"
WITH_SEQUENCING = "WithSequencing"
SAFETY = "Safety"
APP_CALL = "AppCall"
APP_MESSAGE = "AppMessage"
CREATE_DHT_RECORD = "CreateDhtRecord"