Documentation ¶
Index ¶
- func ApplyUpdates(updates ...writeaheadlog.Update) error
- func IsSiaFileUpdate(update writeaheadlog.Update) bool
- func NewRSCode(nData, nParity int) (modules.ErasureCoder, error)
- type FileChunk
- type FileData
- type Piece
- type RSCode
- type SiaFile
- func (sf *SiaFile) AccessTime() time.Time
- func (sf *SiaFile) AddPiece(pk types.SiaPublicKey, chunkIndex, pieceIndex uint64, merkleRoot crypto.Hash) error
- func (sf *SiaFile) Available(offline map[string]bool) bool
- func (sf *SiaFile) ChangeTime() time.Time
- func (sf *SiaFile) ChunkIndexByOffset(offset uint64) (chunkIndex uint64, off uint64)
- func (sf *SiaFile) ChunkSize() uint64
- func (sf *SiaFile) CreateTime() time.Time
- func (sf *SiaFile) Delete() error
- func (sf *SiaFile) Deleted() bool
- func (sf *SiaFile) ErasureCode() modules.ErasureCoder
- func (sf *SiaFile) Expiration(contracts map[string]modules.RenterContract) types.BlockHeight
- func (sf *SiaFile) HostPublicKeys() []types.SiaPublicKey
- func (sf *SiaFile) HyperspacePath() string
- func (sf *SiaFile) LocalPath() string
- func (sf *SiaFile) MasterKey() crypto.CipherKey
- func (sf *SiaFile) ModTime() time.Time
- func (sf *SiaFile) Mode() os.FileMode
- func (sf *SiaFile) NumChunks() uint64
- func (sf *SiaFile) PieceSize() uint64
- func (sf *SiaFile) Pieces(chunkIndex uint64) ([][]Piece, error)
- func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[string]bool) float64
- func (sf *SiaFile) Rename(newHyperspacePath, newSiaFilePath string) error
- func (sf *SiaFile) SetLocalPath(path string) error
- func (sf *SiaFile) SetMode(mode os.FileMode) error
- func (sf *SiaFile) Size() uint64
- func (sf *SiaFile) UID() string
- func (sf *SiaFile) UpdateAccessTime() error
- func (sf *SiaFile) UploadProgress() float64
- func (sf *SiaFile) UploadedBytes() uint64
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.
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 ¶
Encode splits data into equal-length pieces, some containing the original data and some containing parity data.
func (*RSCode) EncodeShards ¶
EncodeShards creates the parity shards for an already sharded input.
func (*RSCode) MinPieces ¶
MinPieces return the minimum number of pieces that must be present to recover the original data.
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 ¶
NewFromFileData creates a new SiaFile from a FileData object that was previously created from a legacy file.
func (*SiaFile) AccessTime ¶
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) ChangeTime ¶
ChangeTime returns the ChangeTime timestamp of the file.
func (*SiaFile) ChunkIndexByOffset ¶
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) CreateTime ¶
CreateTime returns the CreateTime timestamp of the file.
func (*SiaFile) Delete ¶
Delete removes the file from disk and marks it as deleted. Once the file is deleted, certain methods should return an error.
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
HyperspacePath returns the file's sia path.
func (*SiaFile) NumChunks ¶
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) Pieces ¶
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 ¶
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) SetLocalPath ¶
SetLocalPath changes the local path of the file which is used to repair the file from disk.
func (*SiaFile) UpdateAccessTime ¶
UpdateAccessTime updates the AccessTime timestamp to the current time.
func (*SiaFile) UploadProgress ¶
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 ¶
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.