Skip to content

Commit

Permalink
Merge branch 'release/0.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeniy Kulikov committed Dec 3, 2019
2 parents d05b7f3 + 90b6e5c commit f7b10e4
Show file tree
Hide file tree
Showing 12 changed files with 1,021 additions and 696 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog
This is the changelog for NeoFS Proto

## [0.2.4] - 2019-12-03

### Added
- StorageGroup library

### Changed
- Storage group part of object library moved into separate package
- Updated proto documentation

## [0.2.3] - 2019-11-28

### Removed
Expand Down Expand Up @@ -50,3 +59,4 @@ Initial public release
[0.2.1]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.0...v0.2.1
[0.2.2]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.1...v0.2.2
[0.2.3]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.2...v0.2.3
[0.2.4]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.3...v0.2.4
42 changes: 1 addition & 41 deletions docs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
- [Link](#object.Link)
- [Object](#object.Object)
- [Range](#object.Range)
- [StorageGroup](#object.StorageGroup)
- [StorageGroup.Lifetime](#object.StorageGroup.Lifetime)
- [SystemHeader](#object.SystemHeader)
- [Tombstone](#object.Tombstone)
- [Transform](#object.Transform)
Expand Down Expand Up @@ -369,7 +367,7 @@ in distributed system.
| HomoHash | [bytes](#bytes) | | HomoHash is a homomorphic hash of original object payload |
| PayloadChecksum | [bytes](#bytes) | | PayloadChecksum of actual object's payload |
| Integrity | [IntegrityHeader](#object.IntegrityHeader) | | Integrity header with checksum of all above headers in the object |
| StorageGroup | [StorageGroup](#object.StorageGroup) | | StorageGroup contains meta information for the data audit |
| StorageGroup | [storagegroup.StorageGroup](#storagegroup.StorageGroup) | | StorageGroup contains meta information for the data audit |


<a name="object.IntegrityHeader"></a>
Expand Down Expand Up @@ -421,31 +419,6 @@ in distributed system.
| Length | [uint64](#uint64) | | Length of the data range |


<a name="object.StorageGroup"></a>

### Message StorageGroup



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ValidationDataSize | [uint64](#uint64) | | ValidationDataSize is size of the all object's payloads included into storage group |
| ValidationHash | [bytes](#bytes) | | ValidationHash is homomorphic hash of all object's payloads included into storage group |
| lifetime | [StorageGroup.Lifetime](#object.StorageGroup.Lifetime) | | Lifetime is time until storage group is valid |


<a name="object.StorageGroup.Lifetime"></a>

### Message StorageGroup.Lifetime



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| unit | [StorageGroup.Lifetime.Unit](#object.StorageGroup.Lifetime.Unit) | | Unit is lifetime type |
| Value | [int64](#int64) | | Value for lifetime |


<a name="object.SystemHeader"></a>

### Message SystemHeader
Expand Down Expand Up @@ -514,19 +487,6 @@ in distributed system.



<a name="object.StorageGroup.Lifetime.Unit"></a>

### StorageGroup.Lifetime.Unit


| Name | Number | Description |
| ---- | ------ | ----------- |
| Unlimited | 0 | Unlimited set if storage group always valid |
| NeoFSEpoch | 1 | NeoFSEpoch set if storage group is valid until lifetime NeoFS epoch |
| UnixTime | 2 | UnixTime set if storage group is valid until lifetime unix timestamp |



<a name="object.Transform.Type"></a>

### Transform.Type
Expand Down
88 changes: 88 additions & 0 deletions docs/storagegroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Protocol Documentation
<a name="top"></a>

## Table of Contents

- [storagegroup/types.proto](#storagegroup/types.proto)

- Messages
- [StorageGroup](#storagegroup.StorageGroup)
- [StorageGroup.Lifetime](#storagegroup.StorageGroup.Lifetime)


- [Scalar Value Types](#scalar-value-types)



<a name="storagegroup/types.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## storagegroup/types.proto


<!-- end services -->


<a name="storagegroup.StorageGroup"></a>

### Message StorageGroup



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ValidationDataSize | [uint64](#uint64) | | ValidationDataSize is size of the all object's payloads included into storage group |
| ValidationHash | [bytes](#bytes) | | ValidationHash is homomorphic hash of all object's payloads included into storage group |
| lifetime | [StorageGroup.Lifetime](#storagegroup.StorageGroup.Lifetime) | | Lifetime is time until storage group is valid |


<a name="storagegroup.StorageGroup.Lifetime"></a>

### Message StorageGroup.Lifetime



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| unit | [StorageGroup.Lifetime.Unit](#storagegroup.StorageGroup.Lifetime.Unit) | | Unit is lifetime type |
| Value | [int64](#int64) | | Value for lifetime |

<!-- end messages -->


<a name="storagegroup.StorageGroup.Lifetime.Unit"></a>

### StorageGroup.Lifetime.Unit


| Name | Number | Description |
| ---- | ------ | ----------- |
| Unlimited | 0 | Unlimited set if storage group always valid |
| NeoFSEpoch | 1 | NeoFSEpoch set if storage group is valid until lifetime NeoFS epoch |
| UnixTime | 2 | UnixTime set if storage group is valid until lifetime unix timestamp |


<!-- end enums -->



## Scalar Value Types

| .proto Type | Notes | C++ Type | Java Type | Python Type |
| ----------- | ----- | -------- | --------- | ----------- |
| <a name="double" /> double | | double | double | float |
| <a name="float" /> float | | float | float | float |
| <a name="int32" /> int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int | int |
| <a name="int64" /> int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long | int/long |
| <a name="uint32" /> uint32 | Uses variable-length encoding. | uint32 | int | int/long |
| <a name="uint64" /> uint64 | Uses variable-length encoding. | uint64 | long | int/long |
| <a name="sint32" /> sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int | int |
| <a name="sint64" /> sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long |
| <a name="fixed32" /> fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 2^28. | uint32 | int | int |
| <a name="fixed64" /> fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | uint64 | long | int/long |
| <a name="sfixed32" /> sfixed32 | Always four bytes. | int32 | int | int |
| <a name="sfixed64" /> sfixed64 | Always eight bytes. | int64 | long | int/long |
| <a name="bool" /> bool | | bool | boolean | boolean |
| <a name="string" /> string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode |
| <a name="bytes" /> bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str |

15 changes: 4 additions & 11 deletions object/extensions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package object

import (
"github.com/nspcc-dev/neofs-proto/hash"
)
import "github.com/nspcc-dev/neofs-proto/storagegroup"

// IsLinking checks if object has children links to another objects.
// We have to check payload size because zero-object must have zero
Expand Down Expand Up @@ -64,7 +62,7 @@ func (m Object) IsTombstone() bool {
}

// StorageGroup returns storage group structure if it is presented in extended headers.
func (m Object) StorageGroup() (*StorageGroup, error) {
func (m Object) StorageGroup() (*storagegroup.StorageGroup, error) {
_, sgHdr := m.LastHeader(HeaderType(StorageGroupHdr))
if sgHdr == nil {
return nil, ErrHeaderNotFound
Expand All @@ -74,11 +72,6 @@ func (m Object) StorageGroup() (*StorageGroup, error) {

// SetStorageGroup sets storage group header in the object.
// It will replace existing storage group header or add a new one.
func (m *Object) SetStorageGroup(sg *StorageGroup) {
m.SetHeader(&Header{Value: &Header_StorageGroup{StorageGroup: sg}})
}

// Empty checks if storage group has some data for validation.
func (m StorageGroup) Empty() bool {
return m.ValidationDataSize == 0 && m.ValidationHash.Equal(hash.Hash{})
func (m *Object) SetStorageGroup(group *storagegroup.StorageGroup) {
m.SetHeader(&Header{Value: &Header_StorageGroup{StorageGroup: group}})
}
43 changes: 10 additions & 33 deletions object/sg.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,31 @@
package object

import (
"bytes"
"sort"

"github.com/nspcc-dev/neofs-proto/refs"
"github.com/nspcc-dev/neofs-proto/storagegroup"
)

// Here are defined getter functions for objects that contain storage group
// information.

type (
// IDList is a slice of object ids, that can be sorted.
IDList []ID

// ZoneInfo provides validation info of storage group.
ZoneInfo struct {
Hash
Size uint64
}

// IdentificationInfo provides meta information about storage group.
IdentificationInfo struct {
SGID
CID
OwnerID
}
)

// Len returns amount of object ids in IDList.
func (s IDList) Len() int { return len(s) }

// Less returns byte comparision between IDList[i] and IDList[j].
func (s IDList) Less(i, j int) bool { return bytes.Compare(s[i].Bytes(), s[j].Bytes()) == -1 }

// Swap swaps element with i and j index in IDList.
func (s IDList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
var _ storagegroup.Provider = (*Object)(nil)

// Group returns slice of object ids that are part of a storage group.
func (m *Object) Group() []ID {
func (m *Object) Group() []refs.ObjectID {
sgLinks := m.Links(Link_StorageGroup)
sort.Sort(IDList(sgLinks))
sort.Sort(storagegroup.IDList(sgLinks))
return sgLinks
}

// Zones returns validation zones of storage group.
func (m *Object) Zones() []ZoneInfo {
func (m *Object) Zones() []storagegroup.ZoneInfo {
sgInfo, err := m.StorageGroup()
if err != nil {
return nil
}
return []ZoneInfo{
return []storagegroup.ZoneInfo{
{
Hash: sgInfo.ValidationHash,
Size: sgInfo.ValidationDataSize,
Expand All @@ -57,8 +34,8 @@ func (m *Object) Zones() []ZoneInfo {
}

// IDInfo returns meta information about storage group.
func (m *Object) IDInfo() *IdentificationInfo {
return &IdentificationInfo{
func (m *Object) IDInfo() *storagegroup.IdentificationInfo {
return &storagegroup.IdentificationInfo{
SGID: m.SystemHeader.ID,
CID: m.SystemHeader.CID,
OwnerID: m.SystemHeader.OwnerID,
Expand Down
5 changes: 3 additions & 2 deletions object/sg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/nspcc-dev/neofs-proto/hash"
"github.com/nspcc-dev/neofs-proto/storagegroup"
"github.com/stretchr/testify/require"
)

Expand All @@ -28,7 +29,7 @@ func TestObject_StorageGroup(t *testing.T) {
}

rand.Shuffle(len(obj.Headers), func(i, j int) { obj.Headers[i], obj.Headers[j] = obj.Headers[j], obj.Headers[i] })
sort.Sort(IDList(idList))
sort.Sort(storagegroup.IDList(idList))
require.Equal(t, idList, obj.Group())
})
t.Run("identification method", func(t *testing.T) {
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestObject_StorageGroup(t *testing.T) {
Headers: []Header{
{
Value: &Header_StorageGroup{
StorageGroup: &StorageGroup{
StorageGroup: &storagegroup.StorageGroup{
ValidationDataSize: sgSize,
ValidationHash: sgHash,
},
Expand Down
Loading

0 comments on commit f7b10e4

Please sign in to comment.