refactor create dht value

This commit is contained in:
Christien Rioux
2023-07-08 22:50:44 -04:00
parent 9f9feeb325
commit 19f384ab33
13 changed files with 53 additions and 40 deletions

View File

@@ -42,7 +42,7 @@ async def test_delete_dht_record_nonexistent(api_connection: veilid.VeilidAPI):
async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI):
rc = await api_connection.new_routing_context()
async with rc:
rec = await rc.create_dht_record(veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.DHTSchema.dflt(1))
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(1), veilid.CryptoKind.CRYPTO_KIND_VLD0)
await rc.close_dht_record(rec.key)
await rc.delete_dht_record(rec.key)
@@ -50,7 +50,7 @@ async def test_create_delete_dht_record_simple(api_connection: veilid.VeilidAPI)
async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI):
rc = await api_connection.new_routing_context()
async with rc:
rec = await rc.create_dht_record(veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.DHTSchema.dflt(1))
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(1))
assert await rc.get_dht_value(rec.key, 0, False) == None
await rc.close_dht_record(rec.key)
await rc.delete_dht_record(rec.key)
@@ -59,7 +59,7 @@ async def test_get_dht_value_nonexistent(api_connection: veilid.VeilidAPI):
async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
rc = await api_connection.new_routing_context()
async with rc:
rec = await rc.create_dht_record(veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.DHTSchema.dflt(2))
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2))
vd = await rc.set_dht_value(rec.key, 0, b"BLAH BLAH BLAH")
assert vd != None
@@ -87,13 +87,13 @@ async def test_set_get_dht_value(api_connection: veilid.VeilidAPI):
async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
rc = await api_connection.new_routing_context()
async with rc:
rec = await rc.create_dht_record(veilid.CryptoKind.CRYPTO_KIND_VLD0, veilid.DHTSchema.dflt(2))
rec = await rc.create_dht_record(veilid.DHTSchema.dflt(2))
key = rec.key
owner = rec.owner
secret = rec.owner_secret
print(f"key:{key}")
cs = await api_connection.get_crypto_system(veilid.CryptoKind.CRYPTO_KIND_VLD0)
cs = await api_connection.get_crypto_system(rec.key.kind())
async with cs:
assert await cs.validate_key_pair(owner, secret)
other_keypair = await cs.generate_key_pair()

View File

@@ -46,7 +46,7 @@ class RoutingContext(ABC):
@abstractmethod
async def create_dht_record(
self, kind: types.CryptoKind, schema: types.DHTSchema
self, schema: types.DHTSchema, kind: Optional[types.CryptoKind] = None
) -> types.DHTRecordDescriptor:
pass

View File

@@ -514,7 +514,7 @@ class _JsonRoutingContext(RoutingContext):
)
async def create_dht_record(
self, kind: CryptoKind, schema: DHTSchema
self, schema: DHTSchema, kind: Optional[CryptoKind] = None
) -> DHTRecordDescriptor:
return DHTRecordDescriptor.from_json(
raise_api_result(

View File

@@ -303,13 +303,15 @@
{
"type": "object",
"required": [
"kind",
"rc_op",
"schema"
],
"properties": {
"kind": {
"type": "string"
"type": [
"string",
"null"
]
},
"rc_op": {
"type": "string",