mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
A little closer to serialization and deserialization working correctly, with
some tests passing.
This commit is contained in:
parent
898fe0bc0e
commit
f5c4513cd3
@ -102,7 +102,7 @@ _SCHEMAS = {
|
||||
"""
|
||||
response = {
|
||||
"success": bool,
|
||||
"data": [* share_number: [* bstr]]
|
||||
"data": {* share_number: [* bstr]}
|
||||
}
|
||||
share_number = uint
|
||||
"""
|
||||
@ -609,24 +609,12 @@ class WriteVector:
|
||||
data: bytes
|
||||
|
||||
|
||||
class TestVectorOperator(Enum):
|
||||
"""Possible operators for test vectors."""
|
||||
|
||||
LT = b"lt"
|
||||
LE = b"le"
|
||||
EQ = b"eq"
|
||||
NE = b"ne"
|
||||
GE = b"ge"
|
||||
GT = b"gt"
|
||||
|
||||
|
||||
@define
|
||||
class TestVector:
|
||||
"""Checks to make on a chunk before writing to it."""
|
||||
|
||||
offset: int
|
||||
size: int
|
||||
operator: TestVectorOperator
|
||||
specimen: bytes
|
||||
|
||||
|
||||
@ -714,12 +702,12 @@ class StorageClientMutables:
|
||||
message_to_serialize=message,
|
||||
)
|
||||
if response.code == http.OK:
|
||||
return _decode_cbor(response, _SCHEMAS["mutable_test_read_write"])
|
||||
result = await _decode_cbor(response, _SCHEMAS["mutable_read_test_write"])
|
||||
return ReadTestWriteResult(success=result["success"], reads=result["data"])
|
||||
else:
|
||||
raise ClientException(response.code, (await response.content()))
|
||||
|
||||
@async_to_deferred
|
||||
async def read_share_chunk(
|
||||
def read_share_chunk(
|
||||
self,
|
||||
storage_index: bytes,
|
||||
share_number: int,
|
||||
|
@ -589,8 +589,15 @@ class HTTPServer(object):
|
||||
success, read_data = self._storage_server.slot_testv_and_readv_and_writev(
|
||||
storage_index,
|
||||
secrets,
|
||||
rtw_request["test-write-vectors"],
|
||||
rtw_request["read-vector"],
|
||||
{
|
||||
k: (
|
||||
[(d["offset"], d["size"], b"eq", d["specimen"]) for d in v["test"]],
|
||||
[(d["offset"], d["data"]) for d in v["write"]],
|
||||
v["new-length"],
|
||||
)
|
||||
for (k, v) in rtw_request["test-write-vectors"].items()
|
||||
},
|
||||
[(d["offset"], d["size"]) for d in rtw_request["read-vector"]],
|
||||
)
|
||||
return self._send_encoded(request, {"success": success, "data": read_data})
|
||||
|
||||
|
@ -78,7 +78,7 @@ from allmydata.util.dictutil import BytesKeyDict, UnicodeKeyDict
|
||||
from allmydata.storage.http_client import (
|
||||
StorageClient, StorageClientImmutables, StorageClientGeneral,
|
||||
ClientException as HTTPClientException, StorageClientMutables,
|
||||
ReadVector, TestWriteVectors, WriteVector, TestVector, TestVectorOperator
|
||||
ReadVector, TestWriteVectors, WriteVector, TestVector
|
||||
)
|
||||
|
||||
|
||||
@ -1221,8 +1221,8 @@ class _HTTPStorageServer(object):
|
||||
client_tw_vectors = {}
|
||||
for share_num, (test_vector, data_vector, new_length) in tw_vectors.items():
|
||||
client_test_vectors = [
|
||||
TestVector(offset=offset, size=size, operator=TestVectorOperator[op], specimen=specimen)
|
||||
for (offset, size, op, specimen) in test_vector
|
||||
TestVector(offset=offset, size=size, specimen=specimen)
|
||||
for (offset, size, specimen) in test_vector
|
||||
]
|
||||
client_write_vectors = [
|
||||
WriteVector(offset=offset, data=data) for (offset, data) in data_vector
|
||||
|
Loading…
x
Reference in New Issue
Block a user