Tweak logic for storing tree position

This commit is contained in:
Andrew Ayer 2017-01-06 12:19:53 -08:00
parent 87c6bc4f1c
commit 0d9b81ecc8
2 changed files with 13 additions and 6 deletions

View File

@ -154,6 +154,11 @@ func NewMerkleTreeBuilder (stack []ct.MerkleTreeNode, numLeaves uint64) (*Merkle
} }
return &MerkleTreeBuilder{stack: stack, numLeaves: numLeaves}, nil 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) { func (builder *MerkleTreeBuilder) Add(hash ct.MerkleTreeNode) {
builder.stack = append(builder.stack, hash) builder.stack = append(builder.stack, hash)

View File

@ -226,8 +226,7 @@ func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error
endIndex := int64(ctlog.verifiedSTH.TreeSize) endIndex := int64(ctlog.verifiedSTH.TreeSize)
if endIndex > startIndex { if endIndex > startIndex {
treeBuilder := ctlog.position treeBuilder := certspotter.CloneMerkleTreeBuilder(ctlog.position)
ctlog.position = nil
if err := ctlog.scanner.Scan(startIndex, endIndex, processCallback, treeBuilder); err != nil { 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) return fmt.Errorf("Error scanning log (if this error persists, it should be construed as misbehavior by the log): %s", err)
@ -239,10 +238,9 @@ func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error
} }
ctlog.position = treeBuilder ctlog.position = treeBuilder
} if err := ctlog.state.StoreLogPosition(ctlog.position); err != nil {
return fmt.Errorf("Error storing log position: %s", err)
if err := ctlog.state.StoreLogPosition(ctlog.position); err != nil { }
return fmt.Errorf("Error storing log position: %s", err)
} }
return nil 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) 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 { if err := ctlog.scan(processCallback); err != nil {
log.Printf("%s\n", err) log.Printf("%s\n", err)