From 176d9ac68eb010dc4ece7eb12d086dbcfbc1f2a8 Mon Sep 17 00:00:00 2001 From: John Smith Date: Thu, 29 Jun 2023 22:18:45 -0400 Subject: [PATCH] dht testing work --- veilid-core/src/storage_manager/mod.rs | 10 ++++-- veilid-core/src/storage_manager/set_value.rs | 6 ++-- veilid-python/tests/test_dht.py | 33 +++++++++++++------- veilid-python/veilid/json_api.py | 2 -- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index 2fb7ab80..4fcf20f5 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -338,8 +338,14 @@ impl StorageManager { let schema = descriptor.schema()?; // Make new subkey data - let value_data = if let Some(signed_value_data) = last_subkey_result.value { - let seq = signed_value_data.value_data().seq(); + let value_data = if let Some(last_signed_value_data) = last_subkey_result.value { + if last_signed_value_data.value_data().data() == &data + && last_signed_value_data.value_data().writer() == &writer.key + { + // Data and writer is the name, nothing is changing, just return the same ValueData + return Ok(Some(last_signed_value_data.into_value_data())); + } + let seq = last_signed_value_data.value_data().seq(); ValueData::new_with_seq(seq + 1, data, writer.key) } else { ValueData::new(data, writer.key) diff --git a/veilid-core/src/storage_manager/set_value.rs b/veilid-core/src/storage_manager/set_value.rs index 5222f89a..74e50181 100644 --- a/veilid-core/src/storage_manager/set_value.rs +++ b/veilid-core/src/storage_manager/set_value.rs @@ -98,7 +98,7 @@ impl StorageManager { if new_seq > prior_seq { // If the sequence number is greater, keep it ctx.value = value; - // One node has show us this value so far + // One node has shown us this value so far ctx.value_count = 1; } else { // If the sequence number is older, or an equal sequence number, @@ -171,8 +171,8 @@ impl StorageManager { // Make sure this value would actually be newer if let Some(last_value) = &last_subkey_result.value { - if value.value_data().seq() < last_value.value_data().seq() { - // inbound value is older than the one we have, just return the one we have + if value.value_data().seq() <= last_value.value_data().seq() { + // inbound value is older or equal sequence number than the one we have, just return the one we have return Ok(NetworkResult::value(Some(last_value.clone()))); } } diff --git a/veilid-python/tests/test_dht.py b/veilid-python/tests/test_dht.py index afeccb42..36a2f1c6 100644 --- a/veilid-python/tests/test_dht.py +++ b/veilid-python/tests/test_dht.py @@ -91,6 +91,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): 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) async with cs: @@ -101,29 +102,30 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): vb = b"1234567890" vc = b"!@#$%^&*()" + # Test subkey writes vdtemp = await rc.set_dht_value(key, 1, va) assert vdtemp != None assert vdtemp.data == va assert vdtemp.seq == 0 assert vdtemp.writer == owner - # Test subkey writes vdtemp = await rc.get_dht_value(key, 1, False) - assert vdtemp == va + assert vdtemp.data == va + assert vdtemp.seq == 0 + assert vdtemp.writer == owner vdtemp = await rc.get_dht_value(key, 0, False) - assert vdtemp.data == b"" - assert vdtemp.seq == 1 + assert vdtemp == None vdtemp = await rc.set_dht_value(key, 0, vb) - assert vdtemp == vb - assert vdtemp.seq == 2 + assert vdtemp.data == vb + assert vdtemp.seq == 0 vdtemp = await rc.get_dht_value(key, 0, True) - assert vdtemp == vb + assert vdtemp.data == vb vdtemp = await rc.get_dht_value(key, 1, True) - assert vdtemp == va + assert vdtemp.data == va # Equal value should not trigger sequence number update vdtemp = await rc.set_dht_value(key, 1, va) @@ -155,14 +157,21 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): assert rec.schema.kind == veilid.DHTSchemaKind.DFLT assert rec.schema.o_cnt == 2 - # Verify subkey 1 can be set before it is get (should auto-get) - vdtemp = await rec.set_dht_value(key, 1, vc) + # Verify subkey 1 can be set before it is get but newer is available online + vdtemp = await rc.set_dht_value(key, 1, vc) + assert vdtemp != None + assert vdtemp.data == vb + assert vdtemp.seq == 1 + assert vdtemp.writer == owner + + # Verify subkey 1 can be set a second time and it updates because seq is newer + vdtemp = await rc.set_dht_value(key, 1, vc) assert vdtemp != None assert vdtemp.data == vc assert vdtemp.seq == 2 assert vdtemp.writer == owner - # Verify the network got the subkey update + # Verify the network got the subkey update with a refresh check vdtemp = await rc.get_dht_value(key, 1, True) assert vdtemp != None assert vdtemp.data == vc @@ -194,7 +203,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI): vdtemp = await rec.set_dht_value(key, 0, va) assert vdtemp != None assert vdtemp.data == vb - assert vdtemp.seq == 2 + assert vdtemp.seq == 1 assert vdtemp.writer == owner # Clean up diff --git a/veilid-python/veilid/json_api.py b/veilid-python/veilid/json_api.py index 1b75d061..8138cf57 100644 --- a/veilid-python/veilid/json_api.py +++ b/veilid-python/veilid/json_api.py @@ -150,8 +150,6 @@ class _JsonVeilidAPI(VeilidAPI): # Parse line as ndjson j = json.loads(linebytes.strip()) - print(f"linebytes: {linebytes}") - if self.validate_schema: _schema_validate(_VALIDATOR_RECV_MESSAGE, j)