siafile

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2018 License: MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyUpdates

func ApplyUpdates(updates ...writeaheadlog.Update) error

ApplyUpdates applies a number of writeaheadlog updates to the corresponding SiaFile. This method can apply updates from different SiaFiles and should only be run before the SiaFiles are loaded from disk right after the startup of siad. Otherwise we might run into concurrency issues.

func IsSiaFileUpdate

func IsSiaFileUpdate(update writeaheadlog.Update) bool

IsSiaFileUpdate is a helper method that makes sure that a wal update belongs to the SiaFile package.

func NewRSCode

func NewRSCode(nData, nParity int) (modules.ErasureCoder, error)

NewRSCode creates a new Reed-Solomon encoder/decoder using the supplied parameters.

Types

type FileChunk

type FileChunk struct {
	Pieces [][]Piece
}

FileChunk is a helper struct that contains data about a chunk.

type FileData

type FileData struct {
	Name        string
	FileSize    uint64
	MasterKey   [crypto.EntropySize]byte
	ErasureCode modules.ErasureCoder
	RepairPath  string
	PieceSize   uint64
	Mode        os.FileMode
	Deleted     bool
	UID         string
	Chunks      []FileChunk
}

FileData is a helper struct that contains all the relevant information of a file. It simplifies passing the necessary data between modules and keeps the interface clean.

type Piece

type Piece struct {
	HostPubKey types.SiaPublicKey // public key of the host
	MerkleRoot crypto.Hash        // merkle root of the piece
}

Piece represents a single piece of a chunk on disk

type RSCode

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

RSCode is a Reed-Solomon encoder/decoder. It implements the modules.ErasureCoder interface.

func (*RSCode) Encode

func (rs *RSCode) Encode(data []byte) ([][]byte, error)

Encode splits data into equal-length pieces, some containing the original data and some containing parity data.

func (*RSCode) EncodeShards

func (rs *RSCode) EncodeShards(pieces [][]byte, pieceSize uint64) ([][]byte, error)

EncodeShards creates the parity shards for an already sharded input.

func (*RSCode) MinPieces

func (rs *RSCode) MinPieces() int

MinPieces return the minimum number of pieces that must be present to recover the original data.

func (*RSCode) NumPieces

func (rs *RSCode) NumPieces() int

NumPieces returns the number of pieces returned by Encode.

func (*RSCode) Recover

func (rs *RSCode) Recover(pieces [][]byte, n uint64, w io.Writer) error

Recover recovers the original data from pieces and writes it to w. pieces should be identical to the slice returned by Encode (length and order must be preserved), but with missing elements set to nil.

type SiaFile

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

SiaFile is the disk format for files uploaded to the Sia network. It contains all the necessary information to recover a file from its hosts and allows for easy constant-time updates of the file without having to read or write the whole file.

func LoadSiaFile

func LoadSiaFile(path string, wal *writeaheadlog.WAL) (*SiaFile, error)

LoadSiaFile loads a SiaFile from disk.

func New

func New(siaFilePath, siaPath, source string, wal *writeaheadlog.WAL, erasureCode modules.ErasureCoder, masterKey crypto.CipherKey, fileSize uint64, fileMode os.FileMode) (*SiaFile, error)

New create a new SiaFile.

func NewFromFileData

func NewFromFileData(fd FileData) (*SiaFile, error)

NewFromFileData creates a new SiaFile from a FileData object that was previously created from a legacy file.

func (*SiaFile) AccessTime

func (sf *SiaFile) AccessTime() time.Time

AccessTime returns the AccessTime timestamp of the file.

func (*SiaFile) AddPiece

func (sf *SiaFile) AddPiece(pk types.SiaPublicKey, chunkIndex, pieceIndex uint64, merkleRoot crypto.Hash) error

AddPiece adds an uploaded piece to the file. It also updates the host table if the public key of the host is not already known.

func (*SiaFile) Available

func (sf *SiaFile) Available(offline map[string]bool) bool

Available indicates whether the file is ready to be downloaded.

func (*SiaFile) ChangeTime

func (sf *SiaFile) ChangeTime() time.Time

ChangeTime returns the ChangeTime timestamp of the file.

func (*SiaFile) ChunkIndexByOffset

func (sf *SiaFile) ChunkIndexByOffset(offset uint64) (chunkIndex uint64, off uint64)

ChunkIndexByOffset will return the chunkIndex that contains the provided offset of a file and also the relative offset within the chunk. If the offset is out of bounds, chunkIndex will be equal to NumChunk().

func (*SiaFile) ChunkSize

func (sf *SiaFile) ChunkSize() uint64

ChunkSize returns the size of a single chunk of the file.

func (*SiaFile) CreateTime

func (sf *SiaFile) CreateTime() time.Time

CreateTime returns the CreateTime timestamp of the file.

func (*SiaFile) Delete

func (sf *SiaFile) Delete() error

Delete removes the file from disk and marks it as deleted. Once the file is deleted, certain methods should return an error.

func (*SiaFile) Deleted

func (sf *SiaFile) Deleted() bool

Deleted indicates if this file has been deleted by the user.

func (*SiaFile) ErasureCode

func (sf *SiaFile) ErasureCode() modules.ErasureCoder

ErasureCode returns the erasure coder used by the file.

func (*SiaFile) Expiration

func (sf *SiaFile) Expiration(contracts map[string]modules.RenterContract) types.BlockHeight

Expiration returns the lowest height at which any of the file's contracts will expire.

func (*SiaFile) HostPublicKeys

func (sf *SiaFile) HostPublicKeys() []types.SiaPublicKey

HostPublicKeys returns all the public keys of hosts the file has ever been uploaded to. That means some of those hosts might no longer be in use.

func (*SiaFile) HyperspacePath added in v0.2.3

func (sf *SiaFile) HyperspacePath() string

HyperspacePath returns the file's sia path.

func (*SiaFile) LocalPath

func (sf *SiaFile) LocalPath() string

LocalPath returns the path of the local data of the file.

func (*SiaFile) MasterKey

func (sf *SiaFile) MasterKey() crypto.CipherKey

MasterKey returns the masterkey used to encrypt the file.

func (*SiaFile) ModTime

func (sf *SiaFile) ModTime() time.Time

ModTime returns the ModTime timestamp of the file.

func (*SiaFile) Mode

func (sf *SiaFile) Mode() os.FileMode

Mode returns the FileMode of the SiaFile.

func (*SiaFile) NumChunks

func (sf *SiaFile) NumChunks() uint64

NumChunks returns the number of chunks the file consists of. This will return the number of chunks the file consists of even if the file is not fully uploaded yet.

func (*SiaFile) PieceSize

func (sf *SiaFile) PieceSize() uint64

PieceSize returns the size of a single piece of the file.

func (*SiaFile) Pieces

func (sf *SiaFile) Pieces(chunkIndex uint64) ([][]Piece, error)

Pieces returns all the pieces for a chunk in a slice of slices that contains all the pieces for a certain index.

func (*SiaFile) Redundancy

func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[string]bool) float64

Redundancy returns the redundancy of the least redundant chunk. A file becomes available when this redundancy is >= 1. Assumes that every piece is unique within a file contract. -1 is returned if the file has size 0. It takes two arguments, a map of offline contracts for this file and a map that indicates if a contract is goodForRenew.

func (*SiaFile) Rename

func (sf *SiaFile) Rename(newHyperspacePath, newSiaFilePath string) error

Rename changes the name of the file to a new one.

func (*SiaFile) SetLocalPath

func (sf *SiaFile) SetLocalPath(path string) error

SetLocalPath changes the local path of the file which is used to repair the file from disk.

func (*SiaFile) SetMode

func (sf *SiaFile) SetMode(mode os.FileMode) error

SetMode sets the filemode of the sia file.

func (*SiaFile) Size

func (sf *SiaFile) Size() uint64

Size returns the file's size.

func (*SiaFile) UID

func (sf *SiaFile) UID() string

UID returns a unique identifier for this file.

func (*SiaFile) UpdateAccessTime

func (sf *SiaFile) UpdateAccessTime() error

UpdateAccessTime updates the AccessTime timestamp to the current time.

func (*SiaFile) UploadProgress

func (sf *SiaFile) UploadProgress() float64

UploadProgress indicates what percentage of the file (plus redundancy) has been uploaded. Note that a file may be Available long before UploadProgress reaches 100%, and UploadProgress may report a value greater than 100%.

func (*SiaFile) UploadedBytes

func (sf *SiaFile) UploadedBytes() uint64

UploadedBytes indicates how many bytes of the file have been uploaded via current file contracts. Note that this includes padding and redundancy, so uploadedBytes can return a value much larger than the file's original filesize.

Jump to

Keyboard shortcuts

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