dht testing work

This commit is contained in:
John Smith 2023-06-29 22:18:45 -04:00
parent d044f646bf
commit 176d9ac68e
4 changed files with 32 additions and 19 deletions

View File

@ -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)

View File

@ -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())));
}
}

View File

@ -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

View File

@ -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)