refactor: store length in result

This commit is contained in:
Derrick Hammer 2024-02-16 21:55:16 -05:00
parent ffbb7e371a
commit 44c564761c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 12 additions and 8 deletions

View File

@ -5,12 +5,13 @@ import (
"bytes"
_ "embed"
"errors"
"github.com/docker/go-units"
"github.com/hashicorp/go-plugin"
"io"
"math"
"os"
"os/exec"
"github.com/docker/go-units"
"github.com/hashicorp/go-plugin"
)
//go:generate buf generate
@ -70,7 +71,7 @@ func Shutdown() {
client.Kill()
}
func Hash(r io.Reader) (*Result, int, error) {
func Hash(r io.Reader) (*Result, error) {
hasherId := bao.NewHasher()
initialSize := 4 * units.KiB
maxSize := 3.5 * units.MiB
@ -86,12 +87,12 @@ func Hash(r io.Reader) (*Result, int, error) {
if err == io.EOF {
break
}
return nil, 0, err
return nil, err
}
totalReadSize += n
if !bao.Hash(hasherId, buf[:n]) {
return nil, 0, errors.New("hashing failed")
return nil, errors.New("hashing failed")
}
// Adaptively adjust buffer size based on read patterns
@ -103,6 +104,7 @@ func Hash(r io.Reader) (*Result, int, error) {
}
result := bao.Finish(hasherId)
result.Length = uint(totalReadSize)
return &result, totalReadSize, nil
return &result, nil
}

View File

@ -2,6 +2,7 @@ package bao
import (
"context"
"git.lumeweb.com/LumeWeb/portal/bao/proto"
"github.com/google/uuid"
"github.com/hashicorp/go-plugin"
@ -29,8 +30,9 @@ func (p *BaoPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c
}
type Result struct {
Hash []byte
Proof []byte
Hash []byte
Proof []byte
Length uint
}
type BaoGRPC struct {
client proto.BaoClient