Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the client decode b64 in all cases #142

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading