Documentation
¶
Overview ¶
Package container provides functionality related to the NeoFS containers.
The base type is Container.
Index ¶
- type Container
- func (x *Container) ApplyNetworkConfig(cfg netmap.NetworkInfo)
- func (x Container) AssertID(id cid.ID) bool
- func (x Container) AssertNetworkConfig(cfg netmap.NetworkInfo) bool
- func (x Container) Attribute(key string) string
- func (x Container) BasicACL() (res acl.Basic)
- func (x Container) CalculateID(dst *cid.ID)
- func (x Container) CalculateSignature(dst *neofscrypto.Signature, signer neofscrypto.Signer) error
- func (x Container) CopyTo(dst *Container)
- func (x Container) CreatedAt() time.Time
- func (x *Container) DisableHomomorphicHashing()
- func (x *Container) Init()
- func (x Container) IsHomomorphicHashingDisabled() bool
- func (x Container) IterateAttributes(f func(key, val string))
- func (x Container) IterateUserAttributes(f func(key, val string))
- func (x Container) Marshal() []byte
- func (x Container) MarshalJSON() ([]byte, error)
- func (x Container) Name() string
- func (x Container) Owner() (res user.ID)
- func (x Container) PlacementPolicy() (res netmap.PlacementPolicy)
- func (x Container) ReadDomain() (res Domain)
- func (x *Container) ReadFromV2(m container.Container) error
- func (x *Container) SetAttribute(key, value string)
- func (x *Container) SetBasicACL(basicACL acl.Basic)
- func (x *Container) SetCreationTime(t time.Time)
- func (x *Container) SetName(name string)
- func (x *Container) SetOwner(owner user.ID)
- func (x *Container) SetPlacementPolicy(policy netmap.PlacementPolicy)
- func (x Container) SignedData() []byte
- func (x *Container) Unmarshal(data []byte) error
- func (x *Container) UnmarshalJSON(data []byte) error
- func (x Container) VerifySignature(sig neofscrypto.Signature) bool
- func (x Container) Version() version.Version
- func (x *Container) WriteDomain(domain Domain)
- func (x Container) WriteToV2(m *container.Container)
- type Domain
- type SizeEstimation
- func (x SizeEstimation) Container() (res cid.ID)
- func (x SizeEstimation) Epoch() uint64
- func (x *SizeEstimation) ReadFromV2(m container.UsedSpaceAnnouncement) error
- func (x *SizeEstimation) SetContainer(cnr cid.ID)
- func (x *SizeEstimation) SetEpoch(epoch uint64)
- func (x *SizeEstimation) SetValue(value uint64)
- func (x SizeEstimation) Value() uint64
- func (x SizeEstimation) WriteToV2(m *container.UsedSpaceAnnouncement)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container represents descriptor of the NeoFS container. Container logically stores NeoFS objects. Container is one of the basic and at the same time necessary data storage units in the NeoFS. Container includes data about the owner, rules for placing objects and other information necessary for the system functioning.
Container type instances can represent different container states in the system, depending on the context. To create new container in NeoFS zero instance SHOULD be declared, initialized using Init method and filled using dedicated methods. Once container is saved in the NeoFS network, it can't be changed: containers stored in the system are immutable, and NeoFS is a CAS of containers that are identified by a fixed length value (see cid.ID type). Instances for existing containers can be initialized using decoding methods (e.g Unmarshal).
Container is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/container.Container message. See ReadFromV2 / WriteToV2 methods.
Example (Marshalling) ¶
Instances can be also used to process NeoFS API V2 protocol messages with [https://github.com/nspcc-dev/neofs-api] package.
package main import ( apiGoContainer "github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-sdk-go/container" ) func main() { // import apiGoContainer "github.com/nspcc-dev/neofs-api-go/v2/container" // On the client side. var cnr container.Container var msg apiGoContainer.Container cnr.WriteToV2(&msg) // *send message* // On the server side. _ = cnr.ReadFromV2(msg) }
Output:
func (*Container) ApplyNetworkConfig ¶
func (x *Container) ApplyNetworkConfig(cfg netmap.NetworkInfo)
ApplyNetworkConfig applies network configuration to the container. Changes the container if it does not satisfy network configuration.
func (Container) AssertID ¶
AssertID checks if the given Container matches its identifier in CAS of the NeoFS containers.
See also CalculateID.
func (Container) AssertNetworkConfig ¶
func (x Container) AssertNetworkConfig(cfg netmap.NetworkInfo) bool
AssertNetworkConfig checks if a container matches passed network configuration.
func (Container) Attribute ¶
Attribute reads value of the Container attribute by key. Empty result means attribute absence.
See also SetAttribute, IterateAttributes.
func (Container) BasicACL ¶
BasicACL returns basic ACL set using SetBasicACL.
Zero Container has zero basic ACL which structurally correct but doesn't make sense since it denies any access to any party.
func (Container) CalculateID ¶
CalculateID encodes the given Container and passes the result into FromBinary.
See also Container.Marshal, AssertID.
func (Container) CalculateSignature ¶
func (x Container) CalculateSignature(dst *neofscrypto.Signature, signer neofscrypto.Signer) error
CalculateSignature calculates signature of the Container using provided signer and writes it into dst. Signature instance MUST NOT be nil. CalculateSignature is expected to be called after all the Container data is filled and before saving the Container in the NeoFS network. Note that мany subsequent change will most likely break the signature. signer MUST be of neofscrypto.ECDSA_DETERMINISTIC_SHA256 scheme, for example, [neofsecdsa.SignerRFC6979] can be used.
See also Container.VerifySignature, Container.SignedData.
Returned errors:
func (Container) CreatedAt ¶
CreatedAt returns container's creation time set using SetCreationTime.
Zero Container has zero timestamp (in seconds).
func (*Container) DisableHomomorphicHashing ¶
func (x *Container) DisableHomomorphicHashing()
DisableHomomorphicHashing sets flag to disable homomorphic hashing of the Container data.
See also IsHomomorphicHashingDisabled.
func (*Container) Init ¶
func (x *Container) Init()
Init initializes all internal data of the Container required by NeoFS API protocol. Init MUST be called when creating a new container. Init SHOULD NOT be called multiple times. Init SHOULD NOT be called if the Container instance is used for decoding only.
Example ¶
To create new container in the NeoFS network Container instance should be initialized.
package main import ( "time" "github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container/acl" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/user" ) func main() { // import "github.com/nspcc-dev/neofs-sdk-go/container/acl" // import "github.com/nspcc-dev/neofs-sdk-go/user" // import "github.com/nspcc-dev/neofs-sdk-go/netmap" var account user.ID var cnr container.Container cnr.Init() // required fields cnr.SetOwner(account) cnr.SetBasicACL(acl.PublicRWExtended) // optional cnr.SetName("awesome container name") cnr.SetCreationTime(time.Now()) // ... var rd netmap.ReplicaDescriptor rd.SetNumberOfObjects(1) // placement policy and replicas definition is required var pp netmap.PlacementPolicy pp.SetContainerBackupFactor(1) pp.SetReplicas([]netmap.ReplicaDescriptor{rd}) cnr.SetPlacementPolicy(pp) }
Output:
func (Container) IsHomomorphicHashingDisabled ¶
IsHomomorphicHashingDisabled checks if DisableHomomorphicHashing was called.
Zero Container has enabled hashing.
func (Container) IterateAttributes ¶
IterateAttributes iterates over all Container attributes and passes them into f. The handler MUST NOT be nil.
See also Container.SetAttribute, Container.Attribute, Container.IterateUserAttributes.
func (Container) IterateUserAttributes ¶
IterateUserAttributes iterates over user attributes of the Container and passes them into f. The handler MUST NOT be nil.
See also Container.SetAttribute, Container.Attribute, Container.IterateAttributes.
func (Container) Marshal ¶
Marshal encodes Container into a binary format of the NeoFS API protocol (Protocol Buffers with direct field order).
See also Unmarshal.
func (Container) MarshalJSON ¶
MarshalJSON encodes Container into a JSON format of the NeoFS API protocol (Protocol Buffers JSON).
See also UnmarshalJSON.
func (Container) Owner ¶
Owner returns owner of the Container set using SetOwner.
Zero Container has no owner which is incorrect according to NeoFS API protocol.
func (Container) PlacementPolicy ¶
func (x Container) PlacementPolicy() (res netmap.PlacementPolicy)
PlacementPolicy returns placement policy set using SetPlacementPolicy.
Zero Container has no placement policy which is incorrect according to NeoFS API protocol.
func (Container) ReadDomain ¶
ReadDomain reads Domain from the Container. Returns value with empty name if domain is not specified.
func (*Container) ReadFromV2 ¶
ReadFromV2 reads Container from the container.Container message. Checks if the message conforms to NeoFS API V2 protocol.
See also WriteToV2.
func (*Container) SetAttribute ¶
SetAttribute sets Container attribute value by key. Both key and value MUST NOT be empty. Attributes set by the creator (owner) are most commonly ignored by the NeoFS system and used for application layer. Some attributes are so-called system or well-known attributes: they are reserved for system needs. System attributes SHOULD NOT be modified using SetAttribute, use corresponding methods/functions. List of the reserved keys is documented in the particular protocol version.
SetAttribute overwrites existing attribute value.
See also Attribute, IterateAttributes.
func (*Container) SetBasicACL ¶
SetBasicACL specifies basic part of the Container ACL. Basic ACL is used to control access inside container storage.
See also BasicACL.
func (*Container) SetCreationTime ¶
SetCreationTime writes container's creation time in Unix Timestamp format.
See also CreatedAt.
func (*Container) SetName ¶
SetName sets human-readable name of the Container. Name MUST NOT be empty.
See also Name.
func (*Container) SetOwner ¶
SetOwner specifies the owner of the Container. Each Container has exactly one owner, so SetOwner MUST be called for instances to be saved in the NeoFS.
See also Owner.
func (*Container) SetPlacementPolicy ¶
func (x *Container) SetPlacementPolicy(policy netmap.PlacementPolicy)
SetPlacementPolicy sets placement policy for the objects within the Container. NeoFS storage layer strives to follow the specified policy.
See also PlacementPolicy.
func (Container) SignedData ¶
SignedData returns actual payload to sign.
See also Container.CalculateSignature.
func (*Container) Unmarshal ¶
Unmarshal decodes NeoFS API protocol binary format into the Container (Protocol Buffers with direct field order). Returns an error describing a format violation.
See also Marshal.
func (*Container) UnmarshalJSON ¶
UnmarshalJSON decodes NeoFS API protocol JSON format into the Container (Protocol Buffers JSON). Returns an error describing a format violation.
See also MarshalJSON.
func (Container) VerifySignature ¶
func (x Container) VerifySignature(sig neofscrypto.Signature) bool
VerifySignature verifies Container signature calculated using CalculateSignature. Result means signature correctness.
func (*Container) WriteDomain ¶
WriteDomain writes Domain into the Container. Name MUST NOT be empty.
type Domain ¶
type Domain struct {
// contains filtered or unexported fields
}
Domain represents information about container domain registered in the NNS contract deployed in the NeoFS network.
type SizeEstimation ¶
type SizeEstimation struct {
// contains filtered or unexported fields
}
SizeEstimation groups information about estimation of the size of the data stored in the NeoFS container.
SizeEstimation is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/container.UsedSpaceAnnouncement message. See ReadFromV2 / WriteToV2 methods.
func (SizeEstimation) Container ¶
func (x SizeEstimation) Container() (res cid.ID)
Container returns container set using SetContainer.
Zero SizeEstimation is not bound to any container (returns zero) which is incorrect according to NeoFS API protocol.
func (SizeEstimation) Epoch ¶
func (x SizeEstimation) Epoch() uint64
Epoch return epoch set using SetEpoch.
Zero SizeEstimation represents estimation in zero epoch.
func (*SizeEstimation) ReadFromV2 ¶
func (x *SizeEstimation) ReadFromV2(m container.UsedSpaceAnnouncement) error
ReadFromV2 reads SizeEstimation from the container.UsedSpaceAnnouncement message. Checks if the message conforms to NeoFS API V2 protocol.
See also WriteToV2.
func (*SizeEstimation) SetContainer ¶
func (x *SizeEstimation) SetContainer(cnr cid.ID)
SetContainer specifies the container for which the amount of data is estimated. Required by the NeoFS API protocol.
See also Container.
func (*SizeEstimation) SetEpoch ¶
func (x *SizeEstimation) SetEpoch(epoch uint64)
SetEpoch sets epoch when estimation of the container data size was calculated.
See also Epoch.
func (*SizeEstimation) SetValue ¶
func (x *SizeEstimation) SetValue(value uint64)
SetValue sets estimated amount of data (in bytes) in the specified container.
See also Value.
func (SizeEstimation) Value ¶
func (x SizeEstimation) Value() uint64
Value returns data size estimation set using SetValue.
Zero SizeEstimation has zero value.
func (SizeEstimation) WriteToV2 ¶
func (x SizeEstimation) WriteToV2(m *container.UsedSpaceAnnouncement)
WriteToV2 writes SizeEstimation into the container.UsedSpaceAnnouncement message. The message MUST NOT be nil.
See also ReadFromV2.
Directories
¶
Path | Synopsis |
---|---|
Package acl provides functionality to control access to data and operations on them in NeoFS containers.
|
Package acl provides functionality to control access to data and operations on them in NeoFS containers. |
Package cid provides primitives to work with container identification in NeoFS.
|
Package cid provides primitives to work with container identification in NeoFS. |
test
Package cidtest provides functions for convenient testing of cid package API.
|
Package cidtest provides functions for convenient testing of cid package API. |