manifest: adding interleave parameter

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-11-14 18:28:24 +01:00
parent 24ade73061
commit 41669e9cb3
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
2 changed files with 21 additions and 6 deletions

View File

@ -60,7 +60,8 @@ proc encode*(coder: DagPBCoder, manifest: Manifest): ?!seq[byte] =
var erasureInfo = initProtoBuffer()
erasureInfo.write(1, manifest.ecK.uint32)
erasureInfo.write(2, manifest.ecM.uint32)
erasureInfo.write(3, ? coder.encode(manifest.originalManifest)) # TODO: fix check
erasureInfo.write(3, manifest.interleave.uint32)
erasureInfo.write(4, ? coder.encode(manifest.originalManifest)) # TODO: fix check
erasureInfo.finish()
header.write(4, erasureInfo)
@ -82,7 +83,7 @@ proc decode*(coder: DagPBCoder, data: openArray[byte]): ?!Manifest =
originalManifest: Manifest
datasetSize: uint32
blockSize: uint32
ecK, ecM: uint32
ecK, ecM, interleave: uint32
# Decode `Header` message
if pbNode.getField(1, pbHeader).isErr:
@ -109,8 +110,11 @@ proc decode*(coder: DagPBCoder, data: openArray[byte]): ?!Manifest =
if pbErasureInfo.getField(2, ecM).isErr:
return failure("Unable to decode `M` from manifest!")
if pbErasureInfo.getField(3, interleave).isErr:
return failure("Unable to decode `interleave` from manifest!")
var buffer = newSeq[byte]()
if pbErasureInfo.getField(3, buffer).isErr:
if pbErasureInfo.getField(4, buffer).isErr:
return failure("Unable to decode `originalManifest` from manifest!")
originalManifest = coder.decode(buffer).get # TODO: fix check
@ -128,7 +132,8 @@ proc decode*(coder: DagPBCoder, data: openArray[byte]): ?!Manifest =
codec = treeCid.mcodec,
ecK = ecK.int,
ecM = ecM.int,
originalManifest originalManifest
interleave = interleave.int, #TODO
originalManifest = originalManifest
)
else:
Manifest.new(

View File

@ -40,6 +40,7 @@ type
of true:
ecK: int # Number of blocks to encode
ecM: int # Number of resulting parity blocks
interleave: int # How far apart are blocks of an erasure code according to original index
originalManifest: Manifest # The original Manifest being erasure coded
else:
discard
@ -72,6 +73,9 @@ proc ecK*(self: Manifest): int =
proc ecM*(self: Manifest): int =
self.ecM
proc interleave*(self: Manifest): int =
self.interleave
proc originalManifest*(self: Manifest): Manifest =
self.originalManifest
@ -119,7 +123,7 @@ func rounded*(self: Manifest): int =
func steps*(self: Manifest): int =
## Number of EC groups in *protected* manifest
divUp(self.originalBlocksCount, self.ecK)
divUp(self.originalBlocksCount, self.ecK * self.interleave)
func verify*(self: Manifest): ?!void =
## Check manifest correctness
@ -144,6 +148,7 @@ proc `==`*(a, b: Manifest): bool =
(if a.protected:
(a.ecK == b.ecK) and
(a.ecM == b.ecM) and
(a.interleave == b.interleave) and
(a.originalManifest == b.originalManifest)
else:
true)
@ -159,6 +164,7 @@ proc `$`*(self: Manifest): string =
(if self.protected:
", ecK: " & $self.ecK &
", ecM: " & $self.ecM &
", interleave: " & $self.interleave &
", originalManifest: " & $self.originalManifest
else:
"")
@ -192,7 +198,8 @@ proc new*(
manifest: Manifest,
treeCid: Cid,
datasetSize: NBytes,
ecK, ecM: int
ecK, ecM: int,
interleave: int
): Manifest =
## Create an erasure protected dataset from an
## unprotected one
@ -206,6 +213,7 @@ proc new*(
blockSize: manifest.blockSize,
protected: true,
ecK: ecK, ecM: ecM,
interleave: interleave,
originalManifest: manifest)
proc new*(
@ -236,6 +244,7 @@ proc new*(
codec: MultiCodec,
ecK: int,
ecM: int,
interleave: int,
originalManifest: Manifest
): Manifest =
Manifest(
@ -248,5 +257,6 @@ proc new*(
protected: true,
ecK: ecK,
ecM: ecM,
interleave: interleave,
originalManifest: originalManifest
)