mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 04:57:54 +00:00
129c6ec11a
Test vector saving implementation can go near loading implementation. Also we can separate out some simple types from the more complex logic. Initially this was to resolve a circular dependency but that ended up being resolved mostly by treatming SEGMENT_SIZE more like a parameter than a global. Still, smaller modules are okay...
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
"""
|
|
Simple data type definitions useful in the definition/verification of test
|
|
vectors.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from attrs import frozen
|
|
|
|
# CHK have a max of 256 shares. SDMF / MDMF have a max of 255 shares!
|
|
# Represent max symbolically and resolve it when we know what format we're
|
|
# dealing with.
|
|
MAX_SHARES = "max"
|
|
|
|
@frozen
|
|
class Sample:
|
|
"""
|
|
Some instructions for building a long byte string.
|
|
|
|
:ivar seed: Some bytes to repeat some times to produce the string.
|
|
:ivar length: The length of the desired byte string.
|
|
"""
|
|
seed: bytes
|
|
length: int
|
|
|
|
@frozen
|
|
class Param:
|
|
"""
|
|
Some ZFEC parameters.
|
|
"""
|
|
required: int
|
|
total: int
|
|
|
|
@frozen
|
|
class SeedParam:
|
|
"""
|
|
Some ZFEC parameters, almost.
|
|
|
|
:ivar required: The number of required shares.
|
|
|
|
:ivar total: Either the number of total shares or the constant
|
|
``MAX_SHARES`` to indicate that the total number of shares should be
|
|
the maximum number supported by the object format.
|
|
"""
|
|
required: int
|
|
total: int | str
|
|
|
|
def realize(self, max_total: int) -> Param:
|
|
"""
|
|
Create a ``Param`` from this object's values, possibly
|
|
substituting the given real value for total if necessary.
|
|
|
|
:param max_total: The value to use to replace ``MAX_SHARES`` if
|
|
necessary.
|
|
"""
|
|
if self.total == MAX_SHARES:
|
|
return Param(self.required, max_total)
|
|
return Param(self.required, self.total)
|