dht testing work
This commit is contained in:
parent
d044f646bf
commit
176d9ac68e
@ -338,8 +338,14 @@ impl StorageManager {
|
|||||||
let schema = descriptor.schema()?;
|
let schema = descriptor.schema()?;
|
||||||
|
|
||||||
// Make new subkey data
|
// Make new subkey data
|
||||||
let value_data = if let Some(signed_value_data) = last_subkey_result.value {
|
let value_data = if let Some(last_signed_value_data) = last_subkey_result.value {
|
||||||
let seq = signed_value_data.value_data().seq();
|
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)
|
ValueData::new_with_seq(seq + 1, data, writer.key)
|
||||||
} else {
|
} else {
|
||||||
ValueData::new(data, writer.key)
|
ValueData::new(data, writer.key)
|
||||||
|
@ -98,7 +98,7 @@ impl StorageManager {
|
|||||||
if new_seq > prior_seq {
|
if new_seq > prior_seq {
|
||||||
// If the sequence number is greater, keep it
|
// If the sequence number is greater, keep it
|
||||||
ctx.value = value;
|
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;
|
ctx.value_count = 1;
|
||||||
} else {
|
} else {
|
||||||
// If the sequence number is older, or an equal sequence number,
|
// 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
|
// Make sure this value would actually be newer
|
||||||
if let Some(last_value) = &last_subkey_result.value {
|
if let Some(last_value) = &last_subkey_result.value {
|
||||||
if value.value_data().seq() < last_value.value_data().seq() {
|
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
|
// 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())));
|
return Ok(NetworkResult::value(Some(last_value.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
key = rec.key
|
key = rec.key
|
||||||
owner = rec.owner
|
owner = rec.owner
|
||||||
secret = rec.owner_secret
|
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(veilid.CryptoKind.CRYPTO_KIND_VLD0)
|
||||||
async with cs:
|
async with cs:
|
||||||
@ -101,29 +102,30 @@ async def test_open_writer_dht_value(api_connection: veilid.VeilidAPI):
|
|||||||
vb = b"1234567890"
|
vb = b"1234567890"
|
||||||
vc = b"!@#$%^&*()"
|
vc = b"!@#$%^&*()"
|
||||||
|
|
||||||
|
# Test subkey writes
|
||||||
vdtemp = await rc.set_dht_value(key, 1, va)
|
vdtemp = await rc.set_dht_value(key, 1, va)
|
||||||
assert vdtemp != None
|
assert vdtemp != None
|
||||||
assert vdtemp.data == va
|
assert vdtemp.data == va
|
||||||
assert vdtemp.seq == 0
|
assert vdtemp.seq == 0
|
||||||
assert vdtemp.writer == owner
|
assert vdtemp.writer == owner
|
||||||
|
|
||||||
# Test subkey writes
|
|
||||||
vdtemp = await rc.get_dht_value(key, 1, False)
|
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)
|
vdtemp = await rc.get_dht_value(key, 0, False)
|
||||||
assert vdtemp.data == b""
|
assert vdtemp == None
|
||||||
assert vdtemp.seq == 1
|
|
||||||
|
|
||||||
vdtemp = await rc.set_dht_value(key, 0, vb)
|
vdtemp = await rc.set_dht_value(key, 0, vb)
|
||||||
assert vdtemp == vb
|
assert vdtemp.data == vb
|
||||||
assert vdtemp.seq == 2
|
assert vdtemp.seq == 0
|
||||||
|
|
||||||
vdtemp = await rc.get_dht_value(key, 0, True)
|
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)
|
vdtemp = await rc.get_dht_value(key, 1, True)
|
||||||
assert vdtemp == va
|
assert vdtemp.data == va
|
||||||
|
|
||||||
# Equal value should not trigger sequence number update
|
# Equal value should not trigger sequence number update
|
||||||
vdtemp = await rc.set_dht_value(key, 1, va)
|
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.kind == veilid.DHTSchemaKind.DFLT
|
||||||
assert rec.schema.o_cnt == 2
|
assert rec.schema.o_cnt == 2
|
||||||
|
|
||||||
# Verify subkey 1 can be set before it is get (should auto-get)
|
# Verify subkey 1 can be set before it is get but newer is available online
|
||||||
vdtemp = await rec.set_dht_value(key, 1, vc)
|
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 != None
|
||||||
assert vdtemp.data == vc
|
assert vdtemp.data == vc
|
||||||
assert vdtemp.seq == 2
|
assert vdtemp.seq == 2
|
||||||
assert vdtemp.writer == owner
|
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)
|
vdtemp = await rc.get_dht_value(key, 1, True)
|
||||||
assert vdtemp != None
|
assert vdtemp != None
|
||||||
assert vdtemp.data == vc
|
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)
|
vdtemp = await rec.set_dht_value(key, 0, va)
|
||||||
assert vdtemp != None
|
assert vdtemp != None
|
||||||
assert vdtemp.data == vb
|
assert vdtemp.data == vb
|
||||||
assert vdtemp.seq == 2
|
assert vdtemp.seq == 1
|
||||||
assert vdtemp.writer == owner
|
assert vdtemp.writer == owner
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
|
@ -150,8 +150,6 @@ class _JsonVeilidAPI(VeilidAPI):
|
|||||||
# Parse line as ndjson
|
# Parse line as ndjson
|
||||||
j = json.loads(linebytes.strip())
|
j = json.loads(linebytes.strip())
|
||||||
|
|
||||||
print(f"linebytes: {linebytes}")
|
|
||||||
|
|
||||||
if self.validate_schema:
|
if self.validate_schema:
|
||||||
_schema_validate(_VALIDATOR_RECV_MESSAGE, j)
|
_schema_validate(_VALIDATOR_RECV_MESSAGE, j)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user