Rename some types/functions for clarity
This commit is contained in:
parent
35eef25f4a
commit
b47d35a005
12
auditing.go
12
auditing.go
|
@ -115,19 +115,19 @@ func hashChildren (left ct.MerkleTreeNode, right ct.MerkleTreeNode) ct.MerkleTre
|
|||
return hasher.Sum(nil)
|
||||
}
|
||||
|
||||
type MerkleBuilder struct {
|
||||
type MerkleTreeBuilder struct {
|
||||
stack []ct.MerkleTreeNode
|
||||
size uint64 // number of hashes added so far
|
||||
}
|
||||
|
||||
func ResumedMerkleBuilder (hashes []ct.MerkleTreeNode, size uint64) *MerkleBuilder {
|
||||
return &MerkleBuilder{
|
||||
func ResumedMerkleTreeBuilder (hashes []ct.MerkleTreeNode, size uint64) *MerkleTreeBuilder {
|
||||
return &MerkleTreeBuilder{
|
||||
stack: hashes,
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
|
||||
func (builder *MerkleBuilder) Add (hash ct.MerkleTreeNode) {
|
||||
func (builder *MerkleTreeBuilder) Add (hash ct.MerkleTreeNode) {
|
||||
builder.stack = append(builder.stack, hash)
|
||||
builder.size++
|
||||
size := builder.size
|
||||
|
@ -139,9 +139,9 @@ func (builder *MerkleBuilder) Add (hash ct.MerkleTreeNode) {
|
|||
}
|
||||
}
|
||||
|
||||
func (builder *MerkleBuilder) Finish () ct.MerkleTreeNode {
|
||||
func (builder *MerkleTreeBuilder) Finish () ct.MerkleTreeNode {
|
||||
if len(builder.stack) == 0 {
|
||||
panic("MerkleBuilder.Finish called on an empty tree")
|
||||
panic("MerkleTreeBuilder.Finish called on an empty tree")
|
||||
}
|
||||
for len(builder.stack) > 1 {
|
||||
left, right := builder.stack[len(builder.stack)-2], builder.stack[len(builder.stack)-1]
|
||||
|
|
|
@ -159,7 +159,7 @@ func Main (argStateDir string, processCallback ctwatch.ProcessCallback) {
|
|||
}
|
||||
|
||||
if latestSTH.TreeSize > startIndex {
|
||||
var merkleBuilder *ctwatch.MerkleBuilder
|
||||
var treeBuilder *ctwatch.MerkleTreeBuilder
|
||||
if prevSTH != nil {
|
||||
valid, nodes, err := scanner.CheckConsistency(prevSTH, latestSTH)
|
||||
if err != nil {
|
||||
|
@ -173,18 +173,18 @@ func Main (argStateDir string, processCallback ctwatch.ProcessCallback) {
|
|||
continue
|
||||
}
|
||||
|
||||
merkleBuilder = ctwatch.ResumedMerkleBuilder(nodes, prevSTH.TreeSize)
|
||||
treeBuilder = ctwatch.ResumedMerkleTreeBuilder(nodes, prevSTH.TreeSize)
|
||||
} else {
|
||||
merkleBuilder = &ctwatch.MerkleBuilder{}
|
||||
treeBuilder = &ctwatch.MerkleTreeBuilder{}
|
||||
}
|
||||
|
||||
if err := scanner.Scan(int64(startIndex), int64(latestSTH.TreeSize), processCallback, merkleBuilder); err != nil {
|
||||
if err := scanner.Scan(int64(startIndex), int64(latestSTH.TreeSize), processCallback, treeBuilder); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: Error scanning log: %s: %s\n", os.Args[0], logUri, err)
|
||||
exitCode = 1
|
||||
continue
|
||||
}
|
||||
|
||||
rootHash := merkleBuilder.Finish()
|
||||
rootHash := treeBuilder.Finish()
|
||||
if !bytes.Equal(rootHash, latestSTH.SHA256RootHash[:]) {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s: Validation of log entries failed - calculated tree root (%x) does not match signed tree root (%s)\n", os.Args[0], logUri, rootHash, latestSTH.SHA256RootHash)
|
||||
exitCode = 1
|
||||
|
|
10
scanner.go
10
scanner.go
|
@ -77,7 +77,7 @@ func (s *Scanner) processerJob(id int, entries <-chan ct.LogEntry, processCert P
|
|||
wg.Done()
|
||||
}
|
||||
|
||||
func (s *Scanner) fetch(r fetchRange, entries chan<- ct.LogEntry, merkleBuilder *MerkleBuilder) {
|
||||
func (s *Scanner) fetch(r fetchRange, entries chan<- ct.LogEntry, treeBuilder *MerkleTreeBuilder) {
|
||||
success := false
|
||||
// TODO(alcutter): give up after a while:
|
||||
for !success {
|
||||
|
@ -88,8 +88,8 @@ func (s *Scanner) fetch(r fetchRange, entries chan<- ct.LogEntry, merkleBuilder
|
|||
continue
|
||||
}
|
||||
for _, logEntry := range logEntries {
|
||||
if merkleBuilder != nil {
|
||||
merkleBuilder.Add(hashLeaf(logEntry.LeafBytes))
|
||||
if treeBuilder != nil {
|
||||
treeBuilder.Add(hashLeaf(logEntry.LeafBytes))
|
||||
}
|
||||
logEntry.Index = r.start
|
||||
entries <- logEntry
|
||||
|
@ -207,7 +207,7 @@ func (s *Scanner) CheckConsistency(first *ct.SignedTreeHead, second *ct.SignedTr
|
|||
return valid, builderNodes, nil
|
||||
}
|
||||
|
||||
func (s *Scanner) Scan(startIndex int64, endIndex int64, processCert ProcessCallback, merkleBuilder *MerkleBuilder) error {
|
||||
func (s *Scanner) Scan(startIndex int64, endIndex int64, processCert ProcessCallback, treeBuilder *MerkleTreeBuilder) error {
|
||||
s.Log("Starting scan...");
|
||||
|
||||
s.certsProcessed = 0
|
||||
|
@ -256,7 +256,7 @@ func (s *Scanner) Scan(startIndex int64, endIndex int64, processCert ProcessCall
|
|||
*/
|
||||
for start := startIndex; start < int64(endIndex); {
|
||||
end := min(start+int64(s.opts.BatchSize), int64(endIndex)) - 1
|
||||
s.fetch(fetchRange{start, end}, jobs, merkleBuilder)
|
||||
s.fetch(fetchRange{start, end}, jobs, treeBuilder)
|
||||
start = end + 1
|
||||
}
|
||||
close(jobs)
|
||||
|
|
Loading…
Reference in New Issue