diff --git a/v2/container/convert.go b/v2/container/convert.go index d40813f6..386eb8e3 100644 --- a/v2/container/convert.go +++ b/v2/container/convert.go @@ -857,6 +857,8 @@ func UsedSpaceAnnouncementToGRPCMessage(a *UsedSpaceAnnouncement) *container.Ann m := new(container.AnnounceUsedSpaceRequest_Body_Announcement) + m.SetEpoch(a.GetEpoch()) + m.SetContainerId( refs.ContainerIDToGRPCMessage(a.GetContainerID()), ) @@ -873,6 +875,8 @@ func UsedSpaceAnnouncementFromGRPCMessage(m *container.AnnounceUsedSpaceRequest_ a := new(UsedSpaceAnnouncement) + a.SetEpoch(m.GetEpoch()) + a.SetContainerID( refs.ContainerIDFromGRPCMessage(m.GetContainerId()), ) diff --git a/v2/container/grpc/service.go b/v2/container/grpc/service.go index 98c5cc69..644ca3ab 100644 --- a/v2/container/grpc/service.go +++ b/v2/container/grpc/service.go @@ -354,6 +354,13 @@ func (m *GetExtendedACLResponse) SetVerifyHeader(v *session.ResponseVerification } } +// SetEpoch sets epoch of the size estimation. +func (m *AnnounceUsedSpaceRequest_Body_Announcement) SetEpoch(v uint64) { + if m != nil { + m.Epoch = v + } +} + // SetContainerId sets identifier of the container. func (m *AnnounceUsedSpaceRequest_Body_Announcement) SetContainerId(v *refs.ContainerID) { if m != nil { diff --git a/v2/container/grpc/service.pb.go b/v2/container/grpc/service.pb.go index 2951a95b..88dbb48e 100644 Binary files a/v2/container/grpc/service.pb.go and b/v2/container/grpc/service.pb.go differ diff --git a/v2/container/marshal.go b/v2/container/marshal.go index f86d964e..ae190bd2 100644 --- a/v2/container/marshal.go +++ b/v2/container/marshal.go @@ -41,8 +41,9 @@ const ( getEACLRespBodyTableField = 1 getEACLRespBodySignatureField = 2 - usedSpaceAnnounceCIDField = 1 - usedSpaceAnnounceUsedSpaceField = 2 + usedSpaceAnnounceEpochField = 1 + usedSpaceAnnounceCIDField = 2 + usedSpaceAnnounceUsedSpaceField = 3 usedSpaceReqBodyAnnouncementsField = 1 ) @@ -554,6 +555,13 @@ func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) ([]byte, error) { err error ) + n, err = protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch) + if err != nil { + return nil, err + } + + offset += n + n, err = protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid) if err != nil { return nil, err @@ -574,6 +582,7 @@ func (a *UsedSpaceAnnouncement) StableSize() (size int) { return 0 } + size += protoutil.UInt64Size(usedSpaceAnnounceEpochField, a.epoch) size += protoutil.NestedStructureSize(usedSpaceAnnounceCIDField, a.cid) size += protoutil.UInt64Size(usedSpaceAnnounceUsedSpaceField, a.usedSpace) diff --git a/v2/container/marshal_test.go b/v2/container/marshal_test.go index 5a86e88e..dd6599f8 100644 --- a/v2/container/marshal_test.go +++ b/v2/container/marshal_test.go @@ -455,6 +455,7 @@ func generateAnnounceRequestBody(n int) *container.AnnounceUsedSpaceRequestBody cid.SetValue(buf) a := new(container.UsedSpaceAnnouncement) + a.SetEpoch(rand.Uint64()) a.SetContainerID(cid) a.SetUsedSpace(rand.Uint64()) } diff --git a/v2/container/test/client_test.go b/v2/container/test/client_test.go index da7cad00..177b9c95 100644 --- a/v2/container/test/client_test.go +++ b/v2/container/test/client_test.go @@ -418,10 +418,12 @@ func testAnnounceRequest() *container.AnnounceUsedSpaceRequest { cid2.SetValue([]byte{4, 5, 6}) a1 := new(container.UsedSpaceAnnouncement) + a1.SetEpoch(20) a1.SetUsedSpace(10) a1.SetContainerID(cid1) a2 := new(container.UsedSpaceAnnouncement) + a2.SetEpoch(20) a2.SetUsedSpace(20) a2.SetContainerID(cid2) diff --git a/v2/container/types.go b/v2/container/types.go index 07b65e6a..004ddd70 100644 --- a/v2/container/types.go +++ b/v2/container/types.go @@ -94,6 +94,8 @@ type GetExtendedACLResponseBody struct { } type UsedSpaceAnnouncement struct { + epoch uint64 + cid *refs.ContainerID usedSpace uint64 @@ -917,6 +919,20 @@ func (r *GetExtendedACLResponse) SetVerificationHeader(v *session.ResponseVerifi } } +func (a *UsedSpaceAnnouncement) GetEpoch() uint64 { + if a != nil { + return a.epoch + } + + return 0 +} + +func (a *UsedSpaceAnnouncement) SetEpoch(v uint64) { + if a != nil { + a.epoch = v + } +} + func (a *UsedSpaceAnnouncement) GetUsedSpace() uint64 { if a != nil { return a.usedSpace