From 1cacc547e0ed232af8eeae6ea538a5254cdbdddb Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Wed, 21 Feb 2024 20:52:48 -0500 Subject: [PATCH] python work and network keying work --- veilid-core/src/network_manager/mod.rs | 2 +- veilid-python/tests/api.py | 2 +- veilid-python/tests/test_dht.py | 4 ++++ veilid-python/veilid/api.py | 4 ++-- veilid-python/veilid/json_api.py | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index 9415512a..24284dcd 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -227,7 +227,7 @@ impl NetworkManager { Some( bcs.derive_shared_secret( network_key_password.as_bytes(), - network_key_password.as_bytes(), + &bcs.generate_hash(network_key_password.as_bytes()).bytes, ) .expect("failed to derive network key"), ) diff --git a/veilid-python/tests/api.py b/veilid-python/tests/api.py index d3ad9a57..3bb86f33 100644 --- a/veilid-python/tests/api.py +++ b/veilid-python/tests/api.py @@ -57,7 +57,7 @@ def ipc_info() -> str: # hack to deal with rust's 'directories' crate case-inconsistency if sys.platform.startswith('darwin'): - data_dir = appdirs.user_data_dir("Veilid","Veilid") + data_dir = appdirs.user_data_dir("org.Veilid.Veilid") else: data_dir = appdirs.user_data_dir("veilid","veilid") ipc_0_path = os.path.join(data_dir, "ipc", "0") diff --git a/veilid-python/tests/test_dht.py b/veilid-python/tests/test_dht.py index efae87fd..021a882e 100644 --- a/veilid-python/tests/test_dht.py +++ b/veilid-python/tests/test_dht.py @@ -195,6 +195,10 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): with pytest.raises(veilid.VeilidAPIError): vdtemp = await rc.set_dht_value(key, 0, va) + # Verify subkey 0 can be set because override with the right writer + with pytest.raises(veilid.VeilidAPIError): + vdtemp = await rc.set_dht_value(key, 0, va, veilid.KeyPair.from_parts(owner, secret)) + # Clean up await rc.close_dht_record(key) await rc.delete_dht_record(key) diff --git a/veilid-python/veilid/api.py b/veilid-python/veilid/api.py index 8e6ab1cf..eefadade 100644 --- a/veilid-python/veilid/api.py +++ b/veilid-python/veilid/api.py @@ -55,7 +55,7 @@ class RoutingContext(ABC): @abstractmethod async def open_dht_record( - self, key: types.TypedKey, writer: Optional[types.KeyPair] + self, key: types.TypedKey, writer: Optional[types.KeyPair] = None ) -> types.DHTRecordDescriptor: pass @@ -75,7 +75,7 @@ class RoutingContext(ABC): @abstractmethod async def set_dht_value( - self, key: types.TypedKey, subkey: types.ValueSubkey, data: bytes, writer: Optional[types.KeyPair] + self, key: types.TypedKey, subkey: types.ValueSubkey, data: bytes, writer: Optional[types.KeyPair] = None ) -> Optional[types.ValueData]: pass diff --git a/veilid-python/veilid/json_api.py b/veilid-python/veilid/json_api.py index e143a10f..7c56b474 100644 --- a/veilid-python/veilid/json_api.py +++ b/veilid-python/veilid/json_api.py @@ -572,7 +572,7 @@ class _JsonRoutingContext(RoutingContext): ) async def open_dht_record( - self, key: TypedKey, writer: Optional[KeyPair] + self, key: TypedKey, writer: Optional[KeyPair] = None ) -> DHTRecordDescriptor: return DHTRecordDescriptor.from_json( raise_api_result( @@ -626,7 +626,7 @@ class _JsonRoutingContext(RoutingContext): return None if ret is None else ValueData.from_json(ret) async def set_dht_value( - self, key: TypedKey, subkey: ValueSubkey, data: bytes, writer: Optional[KeyPair] + self, key: TypedKey, subkey: ValueSubkey, data: bytes, writer: Optional[KeyPair] = None ) -> Optional[ValueData]: ret = raise_api_result( await self.api.send_ndjson_request(