Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
[#234] Update audit result struct definition
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Vanin <[email protected]>
  • Loading branch information
alexvanin authored and Leonard Lyubich committed Dec 25, 2020
1 parent 9986a4e commit 1c25c39
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 50 deletions.
31 changes: 30 additions & 1 deletion pkg/audit/result.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package audit

import (
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/v2/audit"
Expand All @@ -17,7 +18,10 @@ func NewResultFromV2(aV2 *audit.DataAuditResult) *Result {

// New creates and initializes blank Result.
func NewResult() *Result {
return NewResultFromV2(new(audit.DataAuditResult))
r := NewResultFromV2(new(audit.DataAuditResult))
r.SetVersion(pkg.SDKVersion())

return r
}

// ToV2 converts Result to v2 DataAuditResult message.
Expand Down Expand Up @@ -57,6 +61,19 @@ func (r *Result) UnmarshalJSON(data []byte) error {
UnmarshalJSON(data)
}

// Version returns Data Audit structure version.
func (r *Result) Version() *pkg.Version {
return pkg.NewVersionFromV2(
(*audit.DataAuditResult)(r).GetVersion(),
)
}

// SetVersion sets Data Audit structure version.
func (r *Result) SetVersion(v *pkg.Version) {
(*audit.DataAuditResult)(r).
SetVersion(v.ToV2())
}

// AuditEpoch returns epoch number when the Data Audit was conducted.
func (r *Result) AuditEpoch() uint64 {
return (*audit.DataAuditResult)(r).
Expand Down Expand Up @@ -95,6 +112,18 @@ func (r *Result) SetPublicKey(key []byte) {
SetPublicKey(key)
}

// Complete returns completion state of audit result.
func (r *Result) Complete() bool {
return (*audit.DataAuditResult)(r).
GetComplete()
}

// SetComplete sets completion state of audit result.
func (r *Result) SetComplete(v bool) {
(*audit.DataAuditResult)(r).
SetComplete(v)
}

// PassSG returns list of Storage Groups that passed audit PoR stage.
func (r *Result) PassSG() []*object.ID {
mV2 := (*audit.DataAuditResult)(r).
Expand Down
5 changes: 5 additions & 0 deletions pkg/audit/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"testing"

"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/audit"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
Expand Down Expand Up @@ -32,6 +33,7 @@ func testOID() *object.ID {

func TestResult(t *testing.T) {
r := audit.NewResult()
require.Equal(t, pkg.SDKVersion(), r.Version())

epoch := uint64(13)
r.SetAuditEpoch(epoch)
Expand All @@ -45,6 +47,9 @@ func TestResult(t *testing.T) {
r.SetPublicKey(key)
require.Equal(t, key, r.PublicKey())

r.SetComplete(true)
require.True(t, r.Complete())

passSG := []*object.ID{testOID(), testOID()}
r.SetPassSG(passSG)
require.Equal(t, passSG, r.PassSG())
Expand Down
12 changes: 12 additions & 0 deletions v2/audit/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func DataAuditResultToGRPCMessage(a *DataAuditResult) *audit.DataAuditResult {

m := new(audit.DataAuditResult)

m.SetVersion(
refs.VersionToGRPCMessage(a.GetVersion()),
)

m.SetAuditEpoch(a.GetAuditEpoch())

m.SetContainerId(
Expand All @@ -22,6 +26,8 @@ func DataAuditResultToGRPCMessage(a *DataAuditResult) *audit.DataAuditResult {

m.SetPublicKey(a.GetPublicKey())

m.SetComplete(a.GetComplete())

m.SetPassSg(
refs.ObjectIDListToGRPCMessage(a.GetPassSG()),
)
Expand Down Expand Up @@ -49,6 +55,10 @@ func DataAuditResultFromGRPCMessage(m *audit.DataAuditResult) *DataAuditResult {

a := new(DataAuditResult)

a.SetVersion(
refs.VersionFromGRPCMessage(m.GetVersion()),
)

a.SetAuditEpoch(m.GetAuditEpoch())

a.SetContainerID(
Expand All @@ -57,6 +67,8 @@ func DataAuditResultFromGRPCMessage(m *audit.DataAuditResult) *DataAuditResult {

a.SetPublicKey(m.GetPublicKey())

a.SetComplete(m.GetComplete())

a.SetPassSG(
refs.ObjectIDListFromGRPCMessage(m.GetPassSg()),
)
Expand Down
14 changes: 14 additions & 0 deletions v2/audit/grpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import (
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
)

// SetVersion is a Version field setter.
func (x *DataAuditResult) SetVersion(v *refs.Version) {
if x != nil {
x.Version = v
}
}

// SetAuditEpoch is an AuditEpoch field setter.
func (x *DataAuditResult) SetAuditEpoch(v uint64) {
if x != nil {
Expand All @@ -25,6 +32,13 @@ func (x *DataAuditResult) SetPublicKey(v []byte) {
}
}

// SetComplete is a Complete field setter.
func (x *DataAuditResult) SetComplete(v bool) {
if x != nil {
x.Complete = v
}
}

// SetPassSg is a PassSg field setter.
func (x *DataAuditResult) SetPassSg(v []*refs.ObjectID) {
if x != nil {
Expand Down
124 changes: 75 additions & 49 deletions v2/audit/grpc/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions v2/audit/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (

const (
_ = iota
versionFNum
auditEpochFNum
cidFNum
pubKeyFNum
completeFNum
passSGFNum
failSGFNum
hitFNum
Expand All @@ -37,6 +39,13 @@ func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) {
err error
)

n, err = proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version)
if err != nil {
return nil, err
}

offset += n

n, err = proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch)
if err != nil {
return nil, err
Expand All @@ -58,6 +67,13 @@ func (a *DataAuditResult) StableMarshal(buf []byte) ([]byte, error) {

offset += n

n, err = proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
if err != nil {
return nil, err
}

offset += n

n, err = refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG)
if err != nil {
return nil, err
Expand Down Expand Up @@ -115,9 +131,11 @@ func (a *DataAuditResult) StableSize() (size int) {
return 0
}

size += proto.NestedStructureSize(versionFNum, a.version)
size += proto.Fixed64Size(auditEpochFNum, a.auditEpoch)
size += proto.NestedStructureSize(cidFNum, a.cid)
size += proto.BytesSize(pubKeyFNum, a.pubKey)
size += proto.BoolSize(completeFNum, a.complete)
size += refs.ObjectIDNestedListSize(passSGFNum, a.passSG)
size += refs.ObjectIDNestedListSize(failSGFNum, a.failSG)
size += proto.UInt32Size(hitFNum, a.hit)
Expand Down
Loading

0 comments on commit 1c25c39

Please sign in to comment.