From 1c25c3904baa8383dc21f0bfd59fba61b50d2ae2 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 21 Dec 2020 17:35:03 +0300 Subject: [PATCH] [#234] Update audit result struct definition Signed-off-by: Alex Vanin --- pkg/audit/result.go | 31 +++++++++- pkg/audit/result_test.go | 5 ++ v2/audit/convert.go | 12 ++++ v2/audit/grpc/types.go | 14 +++++ v2/audit/grpc/types.pb.go | 124 +++++++++++++++++++++++--------------- v2/audit/marshal.go | 18 ++++++ v2/audit/marshal_test.go | 6 ++ v2/audit/types.go | 36 +++++++++++ 8 files changed, 196 insertions(+), 50 deletions(-) diff --git a/pkg/audit/result.go b/pkg/audit/result.go index c5af81a..6f5ea9f 100644 --- a/pkg/audit/result.go +++ b/pkg/audit/result.go @@ -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). diff --git a/pkg/audit/result_test.go b/pkg/audit/result_test.go index 8f86037..57038a3 100644 --- a/pkg/audit/result_test.go +++ b/pkg/audit/result_test.go @@ -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()) diff --git a/v2/audit/convert.go b/v2/audit/convert.go index 40dcd3b..4384953 100644 --- a/v2/audit/convert.go +++ b/v2/audit/convert.go @@ -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()), ) diff --git a/v2/audit/grpc/types.go b/v2/audit/grpc/types.go index 7390d89..2c225ef 100644 --- a/v2/audit/grpc/types.go +++ b/v2/audit/grpc/types.go @@ -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 { diff --git a/v2/audit/grpc/types.pb.go b/v2/audit/grpc/types.pb.go index 10158d4..32daf3a 100644 --- a/v2/audit/grpc/types.pb.go +++ b/v2/audit/grpc/types.pb.go @@ -33,30 +33,35 @@ type DataAuditResult struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // Data Audit Result format version. Effectively the version of API library + // used to report DataAuditResult structure. + Version *grpc.Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` // Epoch number when the Data Audit was conducted - AuditEpoch uint64 `protobuf:"fixed64,1,opt,name=audit_epoch,json=auditEpoch,proto3" json:"audit_epoch,omitempty"` + AuditEpoch uint64 `protobuf:"fixed64,2,opt,name=audit_epoch,json=auditEpoch,proto3" json:"audit_epoch,omitempty"` // Container under audit - ContainerId *grpc.ContainerID `protobuf:"bytes,2,opt,name=container_id,json=containerID,proto3" json:"container_id,omitempty"` + ContainerId *grpc.ContainerID `protobuf:"bytes,3,opt,name=container_id,json=containerID,proto3" json:"container_id,omitempty"` // Public key of the auditing InnerRing node in a binary format - PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + PublicKey []byte `protobuf:"bytes,4,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + // Shows if Data Audit process was complete in time or if it was cancelled + Complete bool `protobuf:"varint,5,opt,name=complete,proto3" json:"complete,omitempty"` // List of Storage Groups that passed audit PoR stage - PassSg []*grpc.ObjectID `protobuf:"bytes,4,rep,name=pass_sg,json=passSG,proto3" json:"pass_sg,omitempty"` + PassSg []*grpc.ObjectID `protobuf:"bytes,6,rep,name=pass_sg,json=passSG,proto3" json:"pass_sg,omitempty"` // List of Storage Groups that failed audit PoR stage - FailSg []*grpc.ObjectID `protobuf:"bytes,5,rep,name=fail_sg,json=failSG,proto3" json:"fail_sg,omitempty"` + FailSg []*grpc.ObjectID `protobuf:"bytes,7,rep,name=fail_sg,json=failSG,proto3" json:"fail_sg,omitempty"` // Number of sampled objects under audit placed in an optimal way according to // the containers placement policy when checking PoP - Hit uint32 `protobuf:"varint,6,opt,name=hit,proto3" json:"hit,omitempty"` + Hit uint32 `protobuf:"varint,8,opt,name=hit,proto3" json:"hit,omitempty"` // Number of sampled objects under audit placed in suboptimal way according to // the containers placement policy, but still at a satisfactory level when // checking PoP - Miss uint32 `protobuf:"varint,7,opt,name=miss,proto3" json:"miss,omitempty"` + Miss uint32 `protobuf:"varint,9,opt,name=miss,proto3" json:"miss,omitempty"` // Number of sampled objects under audit stored in a way not confirming // placement policy or not found at all when checking PoP - Fail uint32 `protobuf:"varint,8,opt,name=fail,proto3" json:"fail,omitempty"` + Fail uint32 `protobuf:"varint,10,opt,name=fail,proto3" json:"fail,omitempty"` // List of storage node public keys that passed at least one PDP - PassNodes [][]byte `protobuf:"bytes,9,rep,name=pass_nodes,json=passNodes,proto3" json:"pass_nodes,omitempty"` + PassNodes [][]byte `protobuf:"bytes,11,rep,name=pass_nodes,json=passNodes,proto3" json:"pass_nodes,omitempty"` // List of storage node public keys that failed at least one PDP - FailNodes [][]byte `protobuf:"bytes,10,rep,name=fail_nodes,json=failNodes,proto3" json:"fail_nodes,omitempty"` + FailNodes [][]byte `protobuf:"bytes,12,rep,name=fail_nodes,json=failNodes,proto3" json:"fail_nodes,omitempty"` } func (x *DataAuditResult) Reset() { @@ -91,6 +96,13 @@ func (*DataAuditResult) Descriptor() ([]byte, []int) { return file_v2_audit_grpc_types_proto_rawDescGZIP(), []int{0} } +func (x *DataAuditResult) GetVersion() *grpc.Version { + if x != nil { + return x.Version + } + return nil +} + func (x *DataAuditResult) GetAuditEpoch() uint64 { if x != nil { return x.AuditEpoch @@ -112,6 +124,13 @@ func (x *DataAuditResult) GetPublicKey() []byte { return nil } +func (x *DataAuditResult) GetComplete() bool { + if x != nil { + return x.Complete + } + return false +} + func (x *DataAuditResult) GetPassSg() []*grpc.ObjectID { if x != nil { return x.PassSg @@ -168,35 +187,40 @@ var file_v2_audit_grpc_types_proto_rawDesc = []byte{ 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x74, 0x1a, 0x18, 0x76, 0x32, 0x2f, 0x72, 0x65, 0x66, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xef, 0x02, 0x0a, 0x0f, 0x44, 0x61, 0x74, 0x61, 0x41, - 0x75, 0x64, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x75, - 0x64, 0x69, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x06, 0x52, - 0x0a, 0x61, 0x75, 0x64, 0x69, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x3e, 0x0a, 0x0c, 0x63, - 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1b, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, - 0x66, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x44, 0x52, 0x0b, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x44, 0x12, 0x1d, 0x0a, 0x0a, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x07, 0x70, 0x61, - 0x73, 0x73, 0x5f, 0x73, 0x67, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x65, - 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, 0x4f, 0x62, 0x6a, - 0x65, 0x63, 0x74, 0x49, 0x44, 0x52, 0x06, 0x70, 0x61, 0x73, 0x73, 0x53, 0x47, 0x12, 0x31, 0x0a, - 0x07, 0x66, 0x61, 0x69, 0x6c, 0x5f, 0x73, 0x67, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, - 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, - 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x44, 0x52, 0x06, 0x66, 0x61, 0x69, 0x6c, 0x53, 0x47, - 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x68, - 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x69, 0x73, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x04, 0x6d, 0x69, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x18, 0x08, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, - 0x73, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, - 0x70, 0x61, 0x73, 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x61, 0x69, - 0x6c, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x66, - 0x61, 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x4c, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, - 0x2f, 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, - 0x2f, 0x61, 0x75, 0x64, 0x69, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x61, 0x75, 0x64, 0x69, - 0x74, 0xaa, 0x02, 0x12, 0x4e, 0x65, 0x6f, 0x46, 0x53, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x76, 0x32, - 0x2e, 0x41, 0x75, 0x64, 0x69, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbe, 0x03, 0x0a, 0x0f, 0x44, 0x61, 0x74, 0x61, 0x41, + 0x75, 0x64, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x31, 0x0a, 0x07, 0x76, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6e, 0x65, + 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, + 0x0b, 0x61, 0x75, 0x64, 0x69, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x06, 0x52, 0x0a, 0x61, 0x75, 0x64, 0x69, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x3e, + 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, + 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, + 0x44, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x44, 0x12, 0x1d, + 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12, 0x1a, 0x0a, + 0x08, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x08, 0x63, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x31, 0x0a, 0x07, 0x70, 0x61, 0x73, + 0x73, 0x5f, 0x73, 0x67, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x65, 0x6f, + 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, 0x4f, 0x62, 0x6a, 0x65, + 0x63, 0x74, 0x49, 0x44, 0x52, 0x06, 0x70, 0x61, 0x73, 0x73, 0x53, 0x47, 0x12, 0x31, 0x0a, 0x07, + 0x66, 0x61, 0x69, 0x6c, 0x5f, 0x73, 0x67, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, + 0x6e, 0x65, 0x6f, 0x2e, 0x66, 0x73, 0x2e, 0x76, 0x32, 0x2e, 0x72, 0x65, 0x66, 0x73, 0x2e, 0x4f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x44, 0x52, 0x06, 0x66, 0x61, 0x69, 0x6c, 0x53, 0x47, 0x12, + 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x68, 0x69, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x69, 0x73, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x04, 0x6d, 0x69, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x61, 0x73, + 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x70, + 0x61, 0x73, 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x66, 0x61, 0x69, 0x6c, + 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x0c, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x66, 0x61, + 0x69, 0x6c, 0x4e, 0x6f, 0x64, 0x65, 0x73, 0x42, 0x4c, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, + 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x61, 0x70, 0x69, 0x2d, 0x67, 0x6f, 0x2f, 0x76, 0x32, 0x2f, + 0x61, 0x75, 0x64, 0x69, 0x74, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x3b, 0x61, 0x75, 0x64, 0x69, 0x74, + 0xaa, 0x02, 0x12, 0x4e, 0x65, 0x6f, 0x46, 0x53, 0x2e, 0x41, 0x50, 0x49, 0x2e, 0x76, 0x32, 0x2e, + 0x41, 0x75, 0x64, 0x69, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -214,18 +238,20 @@ func file_v2_audit_grpc_types_proto_rawDescGZIP() []byte { var file_v2_audit_grpc_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_v2_audit_grpc_types_proto_goTypes = []interface{}{ (*DataAuditResult)(nil), // 0: neo.fs.v2.audit.DataAuditResult - (*grpc.ContainerID)(nil), // 1: neo.fs.v2.refs.ContainerID - (*grpc.ObjectID)(nil), // 2: neo.fs.v2.refs.ObjectID + (*grpc.Version)(nil), // 1: neo.fs.v2.refs.Version + (*grpc.ContainerID)(nil), // 2: neo.fs.v2.refs.ContainerID + (*grpc.ObjectID)(nil), // 3: neo.fs.v2.refs.ObjectID } var file_v2_audit_grpc_types_proto_depIdxs = []int32{ - 1, // 0: neo.fs.v2.audit.DataAuditResult.container_id:type_name -> neo.fs.v2.refs.ContainerID - 2, // 1: neo.fs.v2.audit.DataAuditResult.pass_sg:type_name -> neo.fs.v2.refs.ObjectID - 2, // 2: neo.fs.v2.audit.DataAuditResult.fail_sg:type_name -> neo.fs.v2.refs.ObjectID - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 1, // 0: neo.fs.v2.audit.DataAuditResult.version:type_name -> neo.fs.v2.refs.Version + 2, // 1: neo.fs.v2.audit.DataAuditResult.container_id:type_name -> neo.fs.v2.refs.ContainerID + 3, // 2: neo.fs.v2.audit.DataAuditResult.pass_sg:type_name -> neo.fs.v2.refs.ObjectID + 3, // 3: neo.fs.v2.audit.DataAuditResult.fail_sg:type_name -> neo.fs.v2.refs.ObjectID + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_v2_audit_grpc_types_proto_init() } diff --git a/v2/audit/marshal.go b/v2/audit/marshal.go index c0174c7..9aedb16 100644 --- a/v2/audit/marshal.go +++ b/v2/audit/marshal.go @@ -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) diff --git a/v2/audit/marshal_test.go b/v2/audit/marshal_test.go index bb80652..e9212ed 100644 --- a/v2/audit/marshal_test.go +++ b/v2/audit/marshal_test.go @@ -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) diff --git a/v2/audit/types.go b/v2/audit/types.go index 97676e1..67a6fd3 100644 --- a/v2/audit/types.go +++ b/v2/audit/types.go @@ -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 + } +}