Skip to content

Commit

Permalink
Make the client decode b64 in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchinson committed May 16, 2024
1 parent 96bd1da commit 36cc7fa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hammer/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *LeafReader) getLeaf(ctx context.Context, i uint64, logSize uint64) ([]b
if i >= logSize {
return nil, fmt.Errorf("requested leaf %d >= log size %d", i, logSize)
}
if cached := r.c.get(i); cached != nil {
if cached, _ := r.c.get(i); cached != nil {
klog.V(2).Infof("Using cached result for index %d", i)
return cached, nil
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (r *LeafReader) getLeaf(ctx context.Context, i uint64, logSize uint64) ([]b
leaves: bs,
}

return base64.StdEncoding.DecodeString(string(bs[br]))
return r.c.get(i)
}

// Kills this leaf reader at the next opportune moment.
Expand All @@ -144,12 +144,13 @@ type leafBundleCache struct {
leaves [][]byte
}

func (tc leafBundleCache) get(i uint64) []byte {
func (tc leafBundleCache) get(i uint64) ([]byte, error) {
end := tc.start + uint64(len(tc.leaves))
if i >= tc.start && i < end {
return tc.leaves[i-tc.start]
leaf := tc.leaves[i-tc.start]
return base64.StdEncoding.DecodeString(string(leaf))
}
return nil
return nil, errors.New("not found")
}

// RandomNextLeaf returns a function that fetches a random leaf available in the tree.
Expand Down

0 comments on commit 36cc7fa

Please sign in to comment.