[#229] v2/object: Add hash fields to ShortHeader message

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-17 13:18:07 +03:00
parent b2528d4c59
commit 8fe135ab8c
5 changed files with 81 additions and 1 deletions

View file

@ -48,6 +48,14 @@ func ShortHeaderToGRPCMessage(h *ShortHeader) *object.ShortHeader {
m.SetPayloadLength(h.GetPayloadLength())
m.SetPayloadHash(
refs.ChecksumToGRPCMessage(h.GetPayloadHash()),
)
m.SetHomomorphicHash(
refs.ChecksumToGRPCMessage(h.GetHomomorphicHash()),
)
return m
}
@ -74,6 +82,14 @@ func ShortHeaderFromGRPCMessage(m *object.ShortHeader) *ShortHeader {
h.SetPayloadLength(m.GetPayloadLength())
h.SetPayloadHash(
refs.ChecksumFromGRPCMessage(m.GetPayloadHash()),
)
h.SetHomomorphicHash(
refs.ChecksumFromGRPCMessage(m.GetHomomorphicHash()),
)
return h
}

View file

@ -201,6 +201,20 @@ func (m *ShortHeader) SetPayloadLength(v uint64) {
}
}
// SetPayloadHash sets hash of the object payload.
func (m *ShortHeader) SetPayloadHash(v *refs.Checksum) {
if m != nil {
m.PayloadHash = v
}
}
// SetHomomorphicHash sets homomorphic hash of the object payload.
func (m *ShortHeader) SetHomomorphicHash(v *refs.Checksum) {
if m != nil {
m.HomomorphicHash = v
}
}
// SetSplitId sets id of split hierarchy.
func (m *SplitInfo) SetSplitId(v []byte) {
if m != nil {

View file

@ -12,6 +12,8 @@ const (
shortHdrOwnerField = 3
shortHdrObjectTypeField = 4
shortHdrPayloadLength = 5
shortHdrHashField = 6
shortHdrHomoHashField = 7
attributeKeyField = 1
attributeValueField = 2
@ -151,7 +153,21 @@ func (h *ShortHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n
_, err = proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen)
n, err = proto.UInt64Marshal(shortHdrPayloadLength, buf[offset:], h.payloadLen)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(shortHdrHashField, buf[offset:], h.payloadHash)
if err != nil {
return nil, err
}
offset += n
n, err = proto.NestedStructureMarshal(shortHdrHomoHashField, buf[offset:], h.homoHash)
if err != nil {
return nil, err
}
@ -169,6 +185,8 @@ func (h *ShortHeader) StableSize() (size int) {
size += proto.NestedStructureSize(shortHdrOwnerField, h.ownerID)
size += proto.EnumSize(shortHdrObjectTypeField, int32(h.typ))
size += proto.UInt64Size(shortHdrPayloadLength, h.payloadLen)
size += proto.NestedStructureSize(shortHdrHashField, h.payloadHash)
size += proto.NestedStructureSize(shortHdrHomoHashField, h.homoHash)
return size
}

View file

@ -476,6 +476,8 @@ func generateShortHeader(id string) *object.ShortHeader {
hdr.SetCreationEpoch(200)
hdr.SetObjectType(object.TypeRegular)
hdr.SetPayloadLength(10)
hdr.SetPayloadHash(generateChecksum("payload hash"))
hdr.SetHomomorphicHash(generateChecksum("homomorphic hash"))
return hdr
}

View file

@ -19,6 +19,8 @@ type ShortHeader struct {
typ Type
payloadLen uint64
payloadHash, homoHash *refs.Checksum
}
type Attribute struct {
@ -296,6 +298,34 @@ func (h *ShortHeader) SetPayloadLength(v uint64) {
}
}
func (h *ShortHeader) GetPayloadHash() *refs.Checksum {
if h != nil {
return h.payloadHash
}
return nil
}
func (h *ShortHeader) SetPayloadHash(v *refs.Checksum) {
if h != nil {
h.payloadHash = v
}
}
func (h *ShortHeader) GetHomomorphicHash() *refs.Checksum {
if h != nil {
return h.homoHash
}
return nil
}
func (h *ShortHeader) SetHomomorphicHash(v *refs.Checksum) {
if h != nil {
h.homoHash = v
}
}
func (h *ShortHeader) getHeaderPart() {}
func (a *Attribute) GetKey() string {