[#234] Update audit result struct definition

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-21 17:35:03 +03:00 committed by Leonard Lyubich
parent 9986a4ecd1
commit 1c25c3904b
8 changed files with 121 additions and 1 deletions

View file

@ -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"
@ -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.
@ -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).
@ -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).

View file

@ -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"
@ -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)
@ -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())

View file

@ -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(
@ -22,6 +26,8 @@ func DataAuditResultToGRPCMessage(a *DataAuditResult) *audit.DataAuditResult {
m.SetPublicKey(a.GetPublicKey())
m.SetComplete(a.GetComplete())
m.SetPassSg(
refs.ObjectIDListToGRPCMessage(a.GetPassSG()),
)
@ -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(
@ -57,6 +67,8 @@ func DataAuditResultFromGRPCMessage(m *audit.DataAuditResult) *DataAuditResult {
a.SetPublicKey(m.GetPublicKey())
a.SetComplete(m.GetComplete())
a.SetPassSG(
refs.ObjectIDListFromGRPCMessage(m.GetPassSg()),
)

View file

@ -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 {
@ -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 {

Binary file not shown.

View file

@ -9,9 +9,11 @@ import (
const (
_ = iota
versionFNum
auditEpochFNum
cidFNum
pubKeyFNum
completeFNum
passSGFNum
failSGFNum
hitFNum
@ -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
@ -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
@ -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)

View file

@ -25,6 +25,10 @@ func TestDataAuditResult_StableMarshal(t *testing.T) {
func generateDataAuditResult() *audit.DataAuditResult {
a := new(audit.DataAuditResult)
v := new(refs.Version)
v.SetMajor(2)
v.SetMinor(1)
oid1 := new(refs.ObjectID)
oid1.SetValue([]byte("Object ID 1"))
@ -34,9 +38,11 @@ func generateDataAuditResult() *audit.DataAuditResult {
cid := new(refs.ContainerID)
cid.SetValue([]byte("Container ID"))
a.SetVersion(v)
a.SetAuditEpoch(13)
a.SetContainerID(cid)
a.SetPublicKey([]byte("Public key"))
a.SetComplete(true)
a.SetPassSG([]*refs.ObjectID{oid1, oid2})
a.SetFailSG([]*refs.ObjectID{oid2, oid1})
a.SetHit(1)

View file

@ -7,6 +7,8 @@ import (
// DataAuditResult is a unified structure of
// DataAuditResult message from proto definition.
type DataAuditResult struct {
version *refs.Version
auditEpoch uint64
hit, miss, fail uint32
@ -18,6 +20,24 @@ type DataAuditResult struct {
passSG, failSG []*refs.ObjectID
failNodes, passNodes [][]byte
complete bool
}
// GetVersion returns version of Data Audit structure.
func (a *DataAuditResult) GetVersion() *refs.Version {
if a != nil {
return a.version
}
return nil
}
// SetVersion sets version of Data Audit structure.
func (a *DataAuditResult) SetVersion(v *refs.Version) {
if a != nil {
a.version = v
}
}
// GetAuditEpoch returns epoch number when the Data Audit was conducted.
@ -195,3 +215,19 @@ func (a *DataAuditResult) SetFailNodes(v [][]byte) {
a.failNodes = v
}
}
// GetComplete returns boolean completion statement of audit result.
func (a *DataAuditResult) GetComplete() bool {
if a != nil {
return a.complete
}
return false // bool default
}
// SetComplete sets boolean completion statement of audit result.
func (a *DataAuditResult) SetComplete(v bool) {
if a != nil {
a.complete = v
}
}