Tweak logic for storing tree position
This commit is contained in:
parent
87c6bc4f1c
commit
0d9b81ecc8
|
@ -154,6 +154,11 @@ func NewMerkleTreeBuilder (stack []ct.MerkleTreeNode, numLeaves uint64) (*Merkle
|
|||
}
|
||||
return &MerkleTreeBuilder{stack: stack, numLeaves: numLeaves}, nil
|
||||
}
|
||||
func CloneMerkleTreeBuilder (source *MerkleTreeBuilder) *MerkleTreeBuilder {
|
||||
stack := make([]ct.MerkleTreeNode, len(source.stack))
|
||||
copy(stack, source.stack)
|
||||
return &MerkleTreeBuilder{stack: stack, numLeaves: source.numLeaves}
|
||||
}
|
||||
|
||||
func (builder *MerkleTreeBuilder) Add(hash ct.MerkleTreeNode) {
|
||||
builder.stack = append(builder.stack, hash)
|
||||
|
|
|
@ -226,8 +226,7 @@ func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error
|
|||
endIndex := int64(ctlog.verifiedSTH.TreeSize)
|
||||
|
||||
if endIndex > startIndex {
|
||||
treeBuilder := ctlog.position
|
||||
ctlog.position = nil
|
||||
treeBuilder := certspotter.CloneMerkleTreeBuilder(ctlog.position)
|
||||
|
||||
if err := ctlog.scanner.Scan(startIndex, endIndex, processCallback, treeBuilder); err != nil {
|
||||
return fmt.Errorf("Error scanning log (if this error persists, it should be construed as misbehavior by the log): %s", err)
|
||||
|
@ -239,11 +238,10 @@ func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error
|
|||
}
|
||||
|
||||
ctlog.position = treeBuilder
|
||||
}
|
||||
|
||||
if err := ctlog.state.StoreLogPosition(ctlog.position); err != nil {
|
||||
return fmt.Errorf("Error storing log position: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -291,6 +289,10 @@ func processLog(logInfo* certspotter.LogInfo, processCallback certspotter.Proces
|
|||
log.Printf("New log; scanning all %d entries in the log", ctlog.verifiedSTH.TreeSize)
|
||||
}
|
||||
}
|
||||
if err := ctlog.state.StoreLogPosition(ctlog.position); err != nil {
|
||||
log.Printf("Error storing log position: %s\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if err := ctlog.scan(processCallback); err != nil {
|
||||
log.Printf("%s\n", err)
|
||||
|
|
Loading…
Reference in New Issue