-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8421 from madhavajay/madhava/veilid
[WIP] Veilid Prototype
- Loading branch information
Showing
10 changed files
with
1,626 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3ab7de7e-d23e-4cfc-895d-0bd02d9bc17f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# stdlib\n", | ||
"\n", | ||
"# stdlib\n", | ||
"import asyncio\n", | ||
"\n", | ||
"# third party\n", | ||
"import veilid\n", | ||
"from veilid import KeyPair" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "461ef888-76c1-4256-ad69-cbf405d830e0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"app_message_queue: asyncio.Queue = asyncio.Queue()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ad857491-4cad-4a21-bf10-8035f05ef52a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"host = \"localhost\"\n", | ||
"port = 5959" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8d5984fd-30eb-4c9f-8bb7-e0a827b6de2c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"async def noop_callback(update: veilid.VeilidUpdate):\n", | ||
" if update.kind == veilid.VeilidUpdateKind.APP_MESSAGE:\n", | ||
" print(\"Received App Message\")\n", | ||
" await app_message_queue.put(update)\n", | ||
"\n", | ||
"\n", | ||
"async def connect(host: str, port: int):\n", | ||
" conn = await veilid.json_api_connect(host, port, noop_callback)\n", | ||
" return conn" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1296f362-60ff-471a-807b-6d96dbf36403", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"conn = await connect(host, port)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "418b05e9-eaac-4bb5-b61a-e300221b10ba", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# route_id, blob = await conn.new_private_route()\n", | ||
"# Stable and reliable route\n", | ||
"# Creating a new one\n", | ||
"route_id, blob = await conn.new_custom_private_route(\n", | ||
" [veilid.CryptoKind.CRYPTO_KIND_VLD0],\n", | ||
" veilid.Stability.RELIABLE,\n", | ||
" veilid.Sequencing.ENSURE_ORDERED,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "dade6f0b-27f7-4317-84e0-83f5db2f93ea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"route_id, blob" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "de7eb3e2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Creating a new routing context\n", | ||
"# Since it is safe by default , we could remove default safety\n", | ||
"router = await (await conn.new_routing_context()).with_default_safety()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f76a7403", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"router" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ad3b3dbc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"alice_record = await router.create_dht_record(veilid.DHTSchema.dflt(1))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3922a41b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Creation of a Record in DHT DFLT schema , creates a new public and private key pair for the owner\n", | ||
"# that is different from the NodeID public key\n", | ||
"alice_private_key = alice_record.owner_secret\n", | ||
"alice_public_key = alice_record.owner" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "77dd5ed2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"alice_private_key, alice_public_key, alice_record.key" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fb3c60bb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Close the record\n", | ||
"await router.close_dht_record(alice_record.key)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "73249f4a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"key_pair = KeyPair.from_parts(key=alice_public_key, secret=alice_private_key)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b63cb28c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"key_pair" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3afe0d6a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"record_open = await router.open_dht_record(alice_record.key, key_pair)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b12b2281", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"record_open.key" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "11d2d05d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"await router.set_dht_value(record_open.key, 0, blob)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "833bf7e0-c3f9-4280-aa8d-5b1302b00f0f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"record_open.key[5::]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "df056893-c98d-45b4-9eff-c3e6301ce7e4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"self_prr = await conn.import_remote_private_route(blob)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "75b7efff-3b20-4446-ad8d-94ea0f5f4f26", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"message_send = await router.app_message(self_prr, b\"Hello to me\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b6764bf2-30c7-4baa-81e8-c097be06dbea", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"value = await app_message_queue.get()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2d52874c-ad2e-46ef-a9c9-7447661bc7fa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert value.kind == veilid.VeilidUpdateKind.APP_MESSAGE" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b690487b-20fb-4b36-9076-33915a184354", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"value.detail.message" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9e0453a0-4c6d-4d83-aa01-232cab545653", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.