-
Notifications
You must be signed in to change notification settings - Fork 110
bmt, param: Introduce SectionHasher interface, implement in bmt #2021
Changes from 15 commits
f47f9d0
ee1ad2c
679b811
851cab0
9f0f874
7a6e8b2
57cf86d
859a48e
8b59531
1ada8d3
0a3ec03
af6f1c9
47b9667
adc45db
8221d1b
fda2831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package file | ||
|
||
import ( | ||
"context" | ||
"hash" | ||
) | ||
|
||
type SectionWriterFunc func(ctx context.Context) SectionWriter | ||
|
||
type SectionWriter interface { | ||
hash.Hash // Write,Sum,Reset,Size,BlockSize | ||
SetWriter(hashFunc SectionWriterFunc) SectionWriter // chain another SectionWriter the current instance | ||
SetSpan(length int) // set data span of chunk | ||
SectionSize() int // section size of this SectionWriter | ||
Branches() int // branch factor of this SectionWriter | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,8 @@ func TestSha3ForCorrectness(t *testing.T) { | |
rawSha3Output := rawSha3.Sum(nil) | ||
|
||
sha3FromMakeFunc := MakeHashFunc(SHA3Hash)() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌷 I know it's not part of this PR, but why not use constructor for Hasher instead of a func? If the func is needed maybe the builder can be extracted instead of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pradovic The |
||
sha3FromMakeFunc.ResetWithLength(input[:8]) | ||
sha3FromMakeFunc.Reset() | ||
sha3FromMakeFunc.SetSpanBytes(input[:8]) | ||
sha3FromMakeFunc.Write(input[8:]) | ||
sha3FromMakeFuncOutput := sha3FromMakeFunc.Sum(nil) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,8 @@ func GenerateRandomChunk(dataSize int64) Chunk { | |
sdata := make([]byte, dataSize+8) | ||
rand.Read(sdata[8:]) | ||
binary.LittleEndian.PutUint64(sdata[:8], uint64(dataSize)) | ||
hasher.ResetWithLength(sdata[:8]) | ||
hasher.Reset() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now this is called twice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry I don't understand what you mean? You mean since we actually construct the hasher then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
hasher.SetSpanBytes(sdata[:8]) | ||
hasher.Write(sdata[8:]) | ||
return NewChunk(hasher.Sum(nil), sdata) | ||
} | ||
|
@@ -202,7 +203,8 @@ func (v *ContentAddressValidator) Validate(ch Chunk) bool { | |
} | ||
|
||
hasher := v.Hasher() | ||
hasher.ResetWithLength(data[:8]) | ||
hasher.Reset() | ||
hasher.SetSpanBytes(data[:8]) | ||
hasher.Write(data[8:]) | ||
hash := hasher.Sum(nil) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why LittleEndian suddenly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember off the top of my head, but at least it's same as in
storage/types.go
?