object

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoOpKey = EncryptionKey{
	// contains filtered or unexported fields
}

Functions

func ContractsFromShards added in v0.7.0

func ContractsFromShards(shards []Sector) map[types.PublicKey]map[types.FileContractID]struct{}

ContractsFromShards is a helper to extract all contracts used by a set of shards.

Types

type EncryptionKey

type EncryptionKey struct {
	// contains filtered or unexported fields
}

A EncryptionKey can encrypt and decrypt messages.

func GenerateEncryptionKey

func GenerateEncryptionKey() EncryptionKey

GenerateEncryptionKey returns a random encryption key.

func (EncryptionKey) Decrypt

func (k EncryptionKey) Decrypt(w io.Writer, offset uint64) cipher.StreamWriter

Decrypt returns a cipher.StreamWriter that decrypts w with k, starting at the specified offset.

func (EncryptionKey) Encrypt

func (k EncryptionKey) Encrypt(r io.Reader, offset uint64) (cipher.StreamReader, error)

Encrypt returns a cipher.StreamReader that encrypts r with k starting at the given offset.

func (EncryptionKey) IsNoopKey added in v0.6.0

func (k EncryptionKey) IsNoopKey() bool

func (EncryptionKey) MarshalBinary added in v0.7.0

func (k EncryptionKey) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (EncryptionKey) MarshalText

func (k EncryptionKey) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (EncryptionKey) String

func (k EncryptionKey) String() string

String implements fmt.Stringer.

func (*EncryptionKey) UnmarshalBinary added in v0.7.0

func (k *EncryptionKey) UnmarshalBinary(b []byte) error

func (*EncryptionKey) UnmarshalText

func (k *EncryptionKey) UnmarshalText(b []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Object

type Object struct {
	Key   EncryptionKey `json:"key,omitempty"`
	Slabs []SlabSlice   `json:"slabs,omitempty"`
}

An Object is a unit of data that has been stored on a host. NOTE: Object is embedded in the API's Object type, so all fields should be tagged omitempty to make sure responses where no object is returned remain clean.

func NewObject

func NewObject(ec EncryptionKey) Object

NewObject returns a new Object with a random key.

func (*Object) ComputeETag added in v1.0.6

func (o *Object) ComputeETag() string

func (Object) Contracts added in v0.7.0

func (o Object) Contracts() map[types.PublicKey]map[types.FileContractID]struct{}

func (Object) Encrypt

func (o Object) Encrypt(r io.Reader, offset uint64) (cipher.StreamReader, error)

Encrypt wraps the given reader with a reader that encrypts the stream using the object's key.

func (Object) TotalSize

func (o Object) TotalSize() int64

TotalSize returns the total size of the object.

type Sector

type Sector struct {
	Contracts  map[types.PublicKey][]types.FileContractID `json:"contracts"`
	LatestHost types.PublicKey                            `json:"latestHost"`
	Root       types.Hash256                              `json:"root"`
}

A Sector uniquely identifies a sector stored on a particular host.

type Slab

type Slab struct {
	Health    float64       `json:"health"`
	Key       EncryptionKey `json:"key"`
	MinShards uint8         `json:"minShards"`
	Shards    []Sector      `json:"shards,omitempty"`
}

A Slab is raw data that has been erasure-encoded into sector-sized shards, encrypted, and stored across a set of hosts. A distinct EncryptionKey should be used for each Slab, and should not be the same key used for the parent Object.

func NewPartialSlab added in v0.7.0

func NewPartialSlab(ec EncryptionKey, minShards uint8) Slab

NewPartialSlab returns a new partial slab.

func NewSlab

func NewSlab(minShards uint8) Slab

NewSlab returns a new slab for the shards.

func (Slab) Contracts added in v0.7.0

func (s Slab) Contracts() map[types.PublicKey]map[types.FileContractID]struct{}

func (Slab) Encode

func (s Slab) Encode(buf []byte, shards [][]byte)

Encode encodes slab data into sector-sized shards. The supplied shards should have a capacity of at least rhpv2.SectorSize, or they will be reallocated.

func (Slab) Encrypt

func (s Slab) Encrypt(shards [][]byte)

Encrypt xors shards with the keystream derived from s.Key, using a different nonce for each shard.

func (Slab) IsPartial added in v0.7.0

func (s Slab) IsPartial() bool

func (Slab) Length

func (s Slab) Length() int

Length returns the length of the raw data stored in s.

func (Slab) Reconstruct

func (s Slab) Reconstruct(shards [][]byte) error

Reconstruct reconstructs the missing shards of a slab. Missing shards must have a len of zero. All shards should have a capacity of at least rhpv2.SectorSize, or they will be reallocated.

type SlabSlice

type SlabSlice struct {
	Slab   `json:"slab"`
	Offset uint32 `json:"offset"`
	Length uint32 `json:"length"`
}

A SlabSlice is a contiguous region within a Slab. Note that the offset and length always refer to the reconstructed data, and therefore may not necessarily be aligned to a leaf or chunk boundary. Use the SectorRegion method to compute the chunk-aligned offset and length.

func (SlabSlice) Decrypt

func (ss SlabSlice) Decrypt(shards [][]byte)

Decrypt xors shards with the keystream derived from s.Key (starting at the slice offset), using a different nonce for each shard.

func (SlabSlice) Recover

func (ss SlabSlice) Recover(w io.Writer, shards [][]byte) error

Recover recovers a slice of slab data from the supplied shards.

func (SlabSlice) SectorRegion

func (ss SlabSlice) SectorRegion() (offset, length uint32)

SectorRegion returns the offset and length of the sector region that must be downloaded in order to recover the data referenced by the SlabSlice.

Jump to

Keyboard shortcuts

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