mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-05-02 22:54:51 -04:00
fixes
This commit is contained in:
parent
d114ea3b72
commit
14ba85efda
18 changed files with 158 additions and 75 deletions
|
@ -12,6 +12,15 @@ async def test_connect():
|
|||
pass
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_node_id():
|
||||
async def func(api: veilid.VeilidAPI):
|
||||
# get our own node id
|
||||
state = await api.get_state()
|
||||
node_id = state.config.config.network.routing_table.node_id.pop()
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_fail_connect():
|
||||
with pytest.raises(Exception):
|
||||
|
@ -27,3 +36,4 @@ async def test_version():
|
|||
vstr = await api.veilid_version_string()
|
||||
print("veilid_version_string: {}".format(vstr))
|
||||
await simple_connect_and_run(func)
|
||||
|
||||
|
|
|
@ -32,16 +32,56 @@ async def test_routing_context_app_message_loopback():
|
|||
# make a routing context that uses a safety route
|
||||
rc = await (await api.new_routing_context()).with_privacy()
|
||||
|
||||
# get our own node id
|
||||
state = await api.get_state()
|
||||
node_id = state.config.config.network.routing_table.node_id.pop()
|
||||
# make a new local private route
|
||||
prl, blob = await api.new_private_route()
|
||||
|
||||
# send an app message to our node id
|
||||
# import it as a remote route as well so we can send to it
|
||||
prr = await api.import_remote_private_route(blob)
|
||||
|
||||
# send an app message to our own private route
|
||||
message = b"abcd1234"
|
||||
await rc.app_message(node_id, message)
|
||||
await rc.app_message(prr, message)
|
||||
|
||||
# we should get the same message back
|
||||
#update: veilid.VeilidUpdate = await asyncio.wait_for(app_message_queue.get(), timeout=10)
|
||||
#appmsg: veilid.VeilidAppMessage = update.detail
|
||||
#assert appmsg.message == message
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(app_message_queue.get(), timeout=10)
|
||||
appmsg: veilid.VeilidAppMessage = update.detail
|
||||
assert appmsg.message == message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_routing_context_app_call_loopback():
|
||||
|
||||
app_call_queue = asyncio.Queue()
|
||||
|
||||
async def app_call_queue_update_callback(update: veilid.VeilidUpdate):
|
||||
if update.kind == veilid.VeilidUpdateKind.APP_CALL:
|
||||
await app_call_queue.put(update)
|
||||
|
||||
api = await veilid.json_api_connect(VEILID_SERVER, VEILID_SERVER_PORT, app_call_queue_update_callback)
|
||||
async with api:
|
||||
|
||||
# make a routing context that uses a safety route
|
||||
rc = await (await api.new_routing_context()).with_privacy()
|
||||
|
||||
# make a new local private route
|
||||
prl, blob = await api.new_private_route()
|
||||
|
||||
# import it as a remote route as well so we can send to it
|
||||
prr = await api.import_remote_private_route(blob)
|
||||
|
||||
# send an app message to our own private route
|
||||
request = b"abcd1234"
|
||||
app_call_task = asyncio.create_task(rc.app_call(prr, request), name = "app call task")
|
||||
|
||||
# we should get the same request back
|
||||
update: veilid.VeilidUpdate = await asyncio.wait_for(app_call_queue.get(), timeout=10)
|
||||
appcall: veilid.VeilidAppCall = update.detail
|
||||
assert appcall.message == request
|
||||
|
||||
# now we reply to the request
|
||||
reply = b"qwer5678"
|
||||
await api.app_call_reply(appcall.call_id, reply)
|
||||
|
||||
# now we should get the reply from the call
|
||||
result = await app_call_task
|
||||
assert result == reply
|
||||
|
|
|
@ -159,10 +159,10 @@ class VeilidAPI(ABC):
|
|||
async def detach(self):
|
||||
pass
|
||||
@abstractmethod
|
||||
async def new_private_route(self) -> NewPrivateRouteResult:
|
||||
async def new_private_route(self) -> Tuple[RouteId, bytes]:
|
||||
pass
|
||||
@abstractmethod
|
||||
async def new_custom_private_route(self, kinds: list[CryptoKind], stability: Stability, sequencing: Sequencing) -> NewPrivateRouteResult:
|
||||
async def new_custom_private_route(self, kinds: list[CryptoKind], stability: Stability, sequencing: Sequencing) -> Tuple[RouteId, bytes]:
|
||||
pass
|
||||
@abstractmethod
|
||||
async def import_remote_private_route(self, blob: bytes) -> RouteId:
|
||||
|
|
|
@ -223,15 +223,15 @@ class _JsonVeilidAPI(VeilidAPI):
|
|||
raise_api_result(await self.send_ndjson_request(Operation.ATTACH))
|
||||
async def detach(self):
|
||||
raise_api_result(await self.send_ndjson_request(Operation.DETACH))
|
||||
async def new_private_route(self) -> NewPrivateRouteResult:
|
||||
return NewPrivateRouteResult.from_json(raise_api_result(await self.send_ndjson_request(Operation.NEW_PRIVATE_ROUTE)))
|
||||
async def new_custom_private_route(self, kinds: list[CryptoKind], stability: Stability, sequencing: Sequencing) -> NewPrivateRouteResult:
|
||||
async def new_private_route(self) -> Tuple[RouteId, bytes]:
|
||||
return NewPrivateRouteResult.from_json(raise_api_result(await self.send_ndjson_request(Operation.NEW_PRIVATE_ROUTE))).to_tuple()
|
||||
async def new_custom_private_route(self, kinds: list[CryptoKind], stability: Stability, sequencing: Sequencing) -> Tuple[RouteId, bytes]:
|
||||
return NewPrivateRouteResult.from_json(raise_api_result(
|
||||
await self.send_ndjson_request(Operation.NEW_CUSTOM_PRIVATE_ROUTE,
|
||||
kinds = kinds,
|
||||
stability = stability,
|
||||
sequencing = sequencing)
|
||||
))
|
||||
)).to_tuple()
|
||||
async def import_remote_private_route(self, blob: bytes) -> RouteId:
|
||||
return RouteId(raise_api_result(
|
||||
await self.send_ndjson_request(Operation.IMPORT_REMOTE_PRIVATE_ROUTE,
|
||||
|
|
|
@ -2347,12 +2347,12 @@
|
|||
"description": "Direct question blob passed to hosting application for processing to send an eventual AppReply",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"call_id",
|
||||
"kind",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"call_id": {
|
||||
"description": "The id to reply to",
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -250,12 +250,12 @@ class VeilidAppMessage:
|
|||
class VeilidAppCall:
|
||||
sender: Optional[TypedKey]
|
||||
message: bytes
|
||||
operation_id: str
|
||||
call_id: str
|
||||
|
||||
def __init__(self, sender: Optional[TypedKey], message: bytes, operation_id: str):
|
||||
def __init__(self, sender: Optional[TypedKey], message: bytes, call_id: str):
|
||||
self.sender = sender
|
||||
self.message = message
|
||||
self.operation_id = operation_id
|
||||
self.call_id = call_id
|
||||
|
||||
@staticmethod
|
||||
def from_json(j: dict) -> Self:
|
||||
|
@ -263,7 +263,7 @@ class VeilidAppCall:
|
|||
return VeilidAppCall(
|
||||
None if j['sender'] is None else TypedKey(j['sender']),
|
||||
urlsafe_b64decode_no_pad(j['message']),
|
||||
j['operation_id'])
|
||||
j['call_id'])
|
||||
|
||||
class VeilidRouteChange:
|
||||
dead_routes: list[RouteId]
|
||||
|
|
|
@ -204,6 +204,9 @@ class NewPrivateRouteResult:
|
|||
self.route_id = route_id
|
||||
self.blob = blob
|
||||
|
||||
def to_tuple(self) -> Tuple[RouteId, bytes]:
|
||||
return (self.route_id, self.blob)
|
||||
|
||||
@staticmethod
|
||||
def from_json(j: dict) -> Self:
|
||||
return NewPrivateRouteResult(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue