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) Attributes() iter.Seq2[string, string]
- func (x Container) BasicACL() acl.Basic
- 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) FromProtoMessage(m *protocontainer.Container) error
- func (x Container) GetLockUntil() (time.Time, error)
- func (x *Container) Init()
- func (x Container) IsHomomorphicHashingDisabled() bool
- func (x Container) Marshal() []byte
- func (x Container) MarshalJSON() ([]byte, error)
- func (x Container) Name() string
- func (x Container) Owner() user.ID
- func (x Container) PlacementPolicy() netmap.PlacementPolicy
- func (x Container) ProtoMessage() *protocontainer.Container
- func (x Container) ReadDomain() (res Domain)
- func (x *Container) SetAttribute(key, value string)
- func (x *Container) SetBasicACL(basicACL acl.Basic)
- func (x *Container) SetCreationTime(t time.Time)
- func (x *Container) SetLockUntil(until 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) UserAttributes() iter.Seq2[string, string]
- func (x Container) VerifySignature(sig neofscrypto.Signature) bool
- func (x Container) Version() version.Version
- func (x *Container) WriteDomain(domain Domain)
- type Domain
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 protocontainer.Container message. See Container.FromProtoMessage / Container.ProtoMessage 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 (
"github.com/nspcc-dev/neofs-sdk-go/container"
)
func main() {
// On the client side.
var cnr container.Container
msg := cnr.ProtoMessage()
// *send message*
// On the server side.
_ = cnr.FromProtoMessage(msg)
}
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.
func (Container) Attributes ¶
Attributes returns an iterator that yields the container attributes.
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) 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) FromProtoMessage ¶
func (x *Container) FromProtoMessage(m *protocontainer.Container) error
FromProtoMessage validates m according to the NeoFS API protocol and restores x from it.
See also Container.ProtoMessage.
func (Container) GetLockUntil ¶
GetLockUntil looks up for attribute with removal lock timestamp in Unix Timestamp format. If attribute is missing, GetLockUntil returns both zero. Otherwise, GetLockUntil parses the value. If parsing fails, GetLockUntil returns an error containing the value.
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)
}
func (Container) IsHomomorphicHashingDisabled ¶
IsHomomorphicHashingDisabled checks if DisableHomomorphicHashing was called.
Zero Container has enabled hashing.
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() 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) ProtoMessage ¶
func (x Container) ProtoMessage() *protocontainer.Container
ProtoMessage converts x into message to transmit using the NeoFS API protocol.
See also Container.FromProtoMessage.
func (Container) ReadDomain ¶
ReadDomain reads Domain from the Container. Returns value with empty name if domain is not specified.
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.
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) SetLockUntil ¶
SetLockUntil sets attribute with removal lock timestamp in Unix Timestamp format.
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) UserAttributes ¶
UserAttributes returns an iterator that yields the user-defined container attributes.
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.
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. |