-
Notifications
You must be signed in to change notification settings - Fork 15
/
tree.go
201 lines (166 loc) · 4.49 KB
/
tree.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package data
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
)
const (
UnversionedObjectVersionID = "null"
)
// NodeVersion represent node from tree service.
type NodeVersion struct {
BaseNodeVersion
DeleteMarker *DeleteMarkerInfo
IsUnversioned bool
}
func (v NodeVersion) IsDeleteMarker() bool {
return v.DeleteMarker != nil
}
// DeleteMarkerInfo is used to save object info if node in the tree service is delete marker.
// We need this information because the "delete marker" object is no longer stored in NeoFS.
type DeleteMarkerInfo struct {
Created time.Time
Owner user.ID
}
// ExtendedObjectInfo contains additional node info to be able to sort versions by timestamp.
type ExtendedObjectInfo struct {
ObjectInfo *ObjectInfo
NodeVersion *NodeVersion
IsLatest bool
}
func (e ExtendedObjectInfo) Version() string {
if e.NodeVersion.IsUnversioned {
return UnversionedObjectVersionID
}
return e.ObjectInfo.ID.EncodeToString()
}
// BaseNodeVersion is minimal node info from tree service.
// Basically used for "system" object.
type BaseNodeVersion struct {
ID uint64
ParenID uint64
OID oid.ID
Timestamp uint64
Size int64
ETag string
FilePath string
}
type ObjectTaggingInfo struct {
CnrID cid.ID
ObjName string
VersionID string
}
// MultipartInfo is multipart upload information.
type MultipartInfo struct {
// ID is node id in tree service.
// It's ignored when creating a new multipart upload.
ID uint64
Key string
UploadID string
Owner user.ID
OwnerPubKey keys.PublicKey
Created time.Time
Meta map[string]string
CopiesNumber uint32
}
// LinkObjectPayload contains part info of the complex object.
// This data will be used for linking object construction.
type LinkObjectPayload struct {
OID oid.ID
Size uint32
}
// Marshal converts LinkObjectPayload to string.
func (e *LinkObjectPayload) Marshal() string {
return fmt.Sprintf("%s:%d", e.OID.String(), e.Size)
}
// Unmarshal converts string to LinkObjectPayload.
func (e *LinkObjectPayload) Unmarshal(value string) error {
parts := strings.Split(value, ":")
if len(parts) != 2 {
return fmt.Errorf("invalid format: %s", value)
}
if err := e.OID.DecodeString(parts[0]); err != nil {
return fmt.Errorf("invalid id: %w", err)
}
size, err := strconv.ParseUint(parts[1], 10, 32)
if err != nil {
return fmt.Errorf("invalid size: %w", err)
}
e.Size = uint32(size)
return nil
}
// PartInfo is upload information about part.
type PartInfo struct {
Key string
UploadID string
Number int
OID oid.ID
Size int64
ETag string
// Creation time from the client.
Created time.Time
// Server creation time.
ServerCreated time.Time
// MultipartHash contains internal state of the [hash.Hash] to calculate whole object payload hash.
MultipartHash []byte
// HomoHash contains internal state of the [hash.Hash] to calculate whole object homomorphic payload hash.
HomoHash []byte
// Elements contain [oid.ID] and size for each element for the current part.
Elements []LinkObjectPayload
}
// ToHeaderString form short part representation to use in S3-Completed-Parts header.
func (p *PartInfo) ToHeaderString() string {
return strconv.Itoa(p.Number) + "-" + strconv.FormatInt(p.Size, 10) + "-" + p.ETag
}
// LockInfo is lock information to create appropriate tree node.
type LockInfo struct {
id uint64
legalHoldOID oid.ID
setLegalHold bool
retentionOID oid.ID
setRetention bool
untilDate string
isCompliance bool
}
func NewLockInfo(id uint64) *LockInfo {
return &LockInfo{id: id}
}
func (l LockInfo) ID() uint64 {
return l.id
}
func (l *LockInfo) SetLegalHold(objID oid.ID) {
l.legalHoldOID = objID
l.setLegalHold = true
}
func (l *LockInfo) ResetLegalHold() {
l.setLegalHold = false
}
func (l LockInfo) LegalHold() oid.ID {
return l.legalHoldOID
}
func (l LockInfo) IsLegalHoldSet() bool {
return l.setLegalHold
}
func (l *LockInfo) SetRetention(objID oid.ID, until string, isCompliance bool) {
l.retentionOID = objID
l.setRetention = true
l.untilDate = until
l.isCompliance = isCompliance
}
func (l LockInfo) IsRetentionSet() bool {
return l.setRetention
}
func (l LockInfo) Retention() oid.ID {
return l.retentionOID
}
func (l LockInfo) UntilDate() string {
return l.untilDate
}
func (l LockInfo) IsCompliance() bool {
return l.isCompliance
}