container

package
v1.0.0-rc.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 15 Imported by: 26

Documentation

Overview

Package container provides functionality related to the NeoFS containers.

The base type is Container.

Index

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

func (x Container) AssertID(id cid.ID) bool

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

func (x Container) Attribute(key string) string

Attribute reads value of the Container attribute by key. Empty result means attribute absence.

See also SetAttribute, IterateAttributes.

func (Container) BasicACL

func (x Container) BasicACL() (res acl.Basic)

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

func (x Container) CalculateID(dst *cid.ID)

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) CopyTo

func (x Container) CopyTo(dst *Container)

CopyTo writes deep copy of the Container to dst.

func (Container) CreatedAt

func (x Container) CreatedAt() time.Time

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.AddReplicas(rd)

	cnr.SetPlacementPolicy(pp)
}
Output:

func (Container) IsHomomorphicHashingDisabled

func (x Container) IsHomomorphicHashingDisabled() bool

IsHomomorphicHashingDisabled checks if DisableHomomorphicHashing was called.

Zero Container has enabled hashing.

func (Container) IterateAttributes

func (x Container) IterateAttributes(f func(key, val string))

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

func (x Container) IterateUserAttributes(f func(key, val string))

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

func (x Container) Marshal() []byte

Marshal encodes Container into a binary format of the NeoFS API protocol (Protocol Buffers with direct field order).

See also Unmarshal.

func (Container) MarshalJSON

func (x Container) MarshalJSON() ([]byte, error)

MarshalJSON encodes Container into a JSON format of the NeoFS API protocol (Protocol Buffers JSON).

See also UnmarshalJSON.

func (Container) Name

func (x Container) Name() string

Name returns container name set using SetName.

Zero Container has no name.

func (Container) Owner

func (x Container) Owner() (res user.ID)

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

func (x Container) ReadDomain() (res Domain)

ReadDomain reads Domain from the Container. Returns value with empty name if domain is not specified.

func (*Container) ReadFromV2

func (x *Container) ReadFromV2(m container.Container) error

ReadFromV2 reads Container from the container.Container message. Checks if the message conforms to NeoFS API V2 protocol.

See also WriteToV2.

func (*Container) SetAttribute

func (x *Container) SetAttribute(key, value string)

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

func (x *Container) SetBasicACL(basicACL acl.Basic)

SetBasicACL specifies basic part of the Container ACL. Basic ACL is used to control access inside container storage.

See also BasicACL.

func (*Container) SetCreationTime

func (x *Container) SetCreationTime(t time.Time)

SetCreationTime writes container's creation time in Unix Timestamp format.

See also CreatedAt.

func (*Container) SetName

func (x *Container) SetName(name string)

SetName sets human-readable name of the Container. Name MUST NOT be empty.

See also Name.

func (*Container) SetOwner

func (x *Container) SetOwner(owner user.ID)

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

func (x Container) SignedData() []byte

SignedData returns actual payload to sign.

See also Container.CalculateSignature.

func (*Container) Unmarshal

func (x *Container) Unmarshal(data []byte) error

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

func (x *Container) UnmarshalJSON(data []byte) error

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

func (x *Container) WriteDomain(domain Domain)

WriteDomain writes Domain into the Container. Name MUST NOT be empty.

func (Container) WriteToV2

func (x Container) WriteToV2(m *container.Container)

WriteToV2 writes Container into the container.Container message. The message MUST NOT be nil.

See also ReadFromV2.

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.

func (Domain) Name

func (x Domain) Name() string

Name returns name set using SetName.

Zero Domain has zero name.

func (*Domain) SetName

func (x *Domain) SetName(name string)

SetName sets human-friendly container domain name.

func (*Domain) SetZone

func (x *Domain) SetZone(zone string)

SetZone sets zone which is used as a TLD of a domain name in NNS contract.

func (Domain) Zone

func (x Domain) Zone() string

Zone returns domain zone set using SetZone.

Zero Domain has "container" zone.

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

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

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.
id
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL