Documentation ¶
Index ¶
- Variables
- func ApplyUpdates(updates ...writeaheadlog.Update) error
- func ExtractSegment(pieces [][]byte, segmentIndex int, segmentSize uint64) [][]byte
- func IsSiaFileUpdate(update writeaheadlog.Update) bool
- func NewRSCode(nData, nParity int) (modules.ErasureCoder, error)
- func NewRSSubCode(nData, nParity int, segmentSize uint64) (modules.ErasureCoder, error)
- type BubbledMetadata
- type CachedHealthMetadata
- type Chunk
- type FileChunk
- type FileData
- type HostPublicKey
- type Piece
- type RSCode
- func (rs *RSCode) Encode(data []byte) ([][]byte, error)
- func (rs *RSCode) EncodeShards(pieces [][]byte) ([][]byte, error)
- func (rs *RSCode) MinPieces() int
- func (rs *RSCode) NumPieces() int
- func (rs *RSCode) Recover(pieces [][]byte, n uint64, w io.Writer) error
- func (rs *RSCode) SupportsPartialEncoding() bool
- func (rs *RSCode) Type() modules.ErasureCoderType
- type RSSubCode
- func (rs *RSSubCode) Encode(data []byte) ([][]byte, error)
- func (rs *RSSubCode) EncodeShards(pieces [][]byte) ([][]byte, error)
- func (rs *RSSubCode) Recover(pieces [][]byte, n uint64, w io.Writer) error
- func (rs *RSSubCode) SupportsPartialEncoding() bool
- func (rs *RSSubCode) Type() modules.ErasureCoderType
- 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) ChangeTime() time.Time
- func (sf *SiaFile) ChunkHealth(index int, offlineMap map[string]bool, goodForRenewMap map[string]bool) float64
- 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) Health(offline map[string]bool, goodForRenew map[string]bool) (float64, float64, uint64)
- func (sf *SiaFile) HealthPercentage(health float64) float64
- func (sf *SiaFile) HostPublicKeys() (spks []types.SiaPublicKey)
- func (sf *SiaFile) LastHealthCheckTime() time.Time
- func (sf *SiaFile) LocalPath() string
- func (sf *SiaFile) MarkAllHealthyChunksAsUnstuck(offline map[string]bool, goodForRenew map[string]bool) (err error)
- func (sf *SiaFile) MarkAllUnhealthyChunksAsStuck(offline map[string]bool, goodForRenew map[string]bool) (err error)
- 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) NumStuckChunks() uint64
- func (sf *SiaFile) PieceSize() uint64
- func (sf *SiaFile) Pieces(chunkIndex uint64) ([][]Piece, error)
- func (sf *SiaFile) RecentRepairTime() time.Time
- func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[string]bool) float64
- func (sf *SiaFile) Rename(newSiaPath modules.SiaPath, newSiaFilePath string) error
- func (sf *SiaFile) SetLocalPath(path string) error
- func (sf *SiaFile) SetMode(mode os.FileMode) error
- func (sf *SiaFile) SetStuck(index uint64, stuck bool) (err error)
- func (sf *SiaFile) SiaPath() modules.SiaPath
- func (sf *SiaFile) Size() uint64
- func (sf *SiaFile) Snapshot() *Snapshot
- func (sf *SiaFile) SnapshotReader() (*SnapshotReader, error)
- func (sf *SiaFile) StuckChunkByIndex(index uint64) bool
- func (sf *SiaFile) UID() string
- func (sf *SiaFile) UpdateAccessTime() error
- func (sf *SiaFile) UpdateCachedHealthMetadata(metadata CachedHealthMetadata) error
- func (sf *SiaFile) UpdateLastHealthCheckTime() error
- func (sf *SiaFile) UpdateRecentRepairTime() error
- func (sf *SiaFile) UpdateUsedHosts(used []types.SiaPublicKey) error
- func (sf *SiaFile) UploadProgress() float64
- func (sf *SiaFile) UploadedBytes() uint64
- type SiaFileSet
- func (sfs *SiaFileSet) Delete(siaPath modules.SiaPath) error
- func (sfs *SiaFileSet) Exists(siaPath modules.SiaPath) bool
- func (sfs *SiaFileSet) NewFromLegacyData(fd FileData) (*SiaFileSetEntry, error)
- func (sfs *SiaFileSet) NewSiaFile(up modules.FileUploadParams, masterKey crypto.CipherKey, fileSize uint64, ...) (*SiaFileSetEntry, error)
- func (sfs *SiaFileSet) Open(siaPath modules.SiaPath) (*SiaFileSetEntry, error)
- func (sfs *SiaFileSet) Rename(siaPath, newSiaPath modules.SiaPath) error
- type SiaFileSetEntry
- type Snapshot
- func (s *Snapshot) ChunkIndexByOffset(offset uint64) (chunkIndex uint64, off uint64)
- func (s *Snapshot) ChunkSize() uint64
- func (s *Snapshot) ErasureCode() modules.ErasureCoder
- func (s *Snapshot) MasterKey() crypto.CipherKey
- func (s *Snapshot) Mode() os.FileMode
- func (s *Snapshot) NumChunks() uint64
- func (s *Snapshot) PieceSize() uint64
- func (s *Snapshot) Pieces(chunkIndex uint64) ([][]Piece, error)
- func (s *Snapshot) SiaPath() modules.SiaPath
- func (s *Snapshot) Size() uint64
- type SnapshotReader
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPathOverload is an error when a file already exists at that location ErrPathOverload = errors.New("a file already exists at that location") // ErrUnknownPath is an error when a file cannot be found with the given path ErrUnknownPath = errors.New("no file known with that path") // ErrUnknownThread is an error when a SiaFile is trying to be closed by a // thread that is not in the threadMap ErrUnknownThread = errors.New("thread should not be calling Close(), does not have control of the siafile") )
Functions ¶
func ApplyUpdates ¶
func ApplyUpdates(updates ...writeaheadlog.Update) error
ApplyUpdates is a wrapper for applyUpdates that uses the production dependencies.
func ExtractSegment ¶
ExtractSegment is a convenience method that extracts the data of the segment at segmentIndex from pieces.
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.
func NewRSSubCode ¶
func NewRSSubCode(nData, nParity int, segmentSize uint64) (modules.ErasureCoder, error)
NewRSSubCode creates a new Reed-Solomon encoder/decoder using the supplied parameters.
Types ¶
type BubbledMetadata ¶
type BubbledMetadata struct { Health float64 LastHealthCheckTime time.Time ModTime time.Time NumStuckChunks uint64 RecentRepairTime time.Time Redundancy float64 Size uint64 StuckHealth float64 }
BubbledMetadata is the metadata of a siafile that gets bubbled
type CachedHealthMetadata ¶
CachedHealthMetadata is a healper struct that contains the siafile health metadata fields that are cached
type Chunk ¶
type Chunk struct {
Pieces [][]Piece
}
Chunk is an exported chunk. It contains exported pieces.
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 HostPublicKey ¶
type HostPublicKey struct { PublicKey types.SiaPublicKey // public key of host Used bool // indicates if we currently use this host }
HostPublicKey is an entry in the HostPubKey table.
func (HostPublicKey) MarshalSia ¶
func (hpk HostPublicKey) MarshalSia(w io.Writer) error
MarshalSia implements the encoding.SiaMarshaler interface.
func (*HostPublicKey) UnmarshalSia ¶
func (hpk *HostPublicKey) UnmarshalSia(r io.Reader) error
UnmarshalSia implements the encoding.SiaUnmarshaler interface.
type Piece ¶
type Piece struct { HostPubKey types.SiaPublicKey // public key of the host MerkleRoot crypto.Hash // merkle root of the piece }
Piece is an exported piece. It contains a resolved public key instead of the table offset.
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.
func (*RSCode) Recover ¶
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.
func (*RSCode) SupportsPartialEncoding ¶
SupportsPartialEncoding returns false for the basic reed-solomon encoder.
func (*RSCode) Type ¶
func (rs *RSCode) Type() modules.ErasureCoderType
Type returns the erasure coders type identifier.
type RSSubCode ¶
type RSSubCode struct { RSCode // contains filtered or unexported fields }
RSSubCode is a Reed-Solomon encoder/decoder. It implements the modules.ErasureCoder interface in a way that every crypto.SegmentSize bytes of encoded data can be recovered separately.
func (*RSSubCode) Encode ¶
Encode splits data into equal-length pieces, some containing the original data and some containing parity data.
func (*RSSubCode) EncodeShards ¶
EncodeShards encodes data in a way that every segmentSize bytes of the encoded data can be decoded independently.
func (*RSSubCode) Recover ¶
Recover accepts encoded pieces and decodes the segment at segmentIndex. The size of the decoded data is segmentSize * dataPieces.
func (*RSSubCode) SupportsPartialEncoding ¶
SupportsPartialEncoding returns true for the custom reed-solomon encoder.
func (*RSSubCode) Type ¶
func (rs *RSSubCode) Type() modules.ErasureCoderType
Type returns the erasure coders type identifier.
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 is a wrapper for loadSiaFile that uses the production dependencies.
func New ¶
func New(siaPath modules.SiaPath, siaFilePath, source string, wal *writeaheadlog.WAL, erasureCode modules.ErasureCoder, masterKey crypto.CipherKey, fileSize uint64, fileMode os.FileMode) (*SiaFile, error)
New create a new SiaFile.
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) ChunkHealth ¶
func (sf *SiaFile) ChunkHealth(index int, offlineMap map[string]bool, goodForRenewMap map[string]bool) float64
ChunkHealth returns the health of the chunk which is defined as the percent of parity pieces remaining.
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) Health ¶
func (sf *SiaFile) Health(offline map[string]bool, goodForRenew map[string]bool) (float64, float64, uint64)
Health calculates the health of the file to be used in determining repair priority. Health of the file is the lowest health of any of the chunks and is defined as the percent of parity pieces remaining. Additionally the NumStuckChunks will be updated for the SiaFile and returned
health = 0 is full redundancy, health <= 1 is recoverable, health > 1 needs to be repaired from disk
func (*SiaFile) HealthPercentage ¶
HealthPercentage returns the health in a more human understandable format out of 100%
func (*SiaFile) HostPublicKeys ¶
func (sf *SiaFile) HostPublicKeys() (spks []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) LastHealthCheckTime ¶
LastHealthCheckTime returns the LastHealthCheckTime timestamp of the file
func (*SiaFile) MarkAllHealthyChunksAsUnstuck ¶
func (sf *SiaFile) MarkAllHealthyChunksAsUnstuck(offline map[string]bool, goodForRenew map[string]bool) (err error)
MarkAllHealthyChunksAsUnstuck marks all health chunks as unstuck in the siafile
func (*SiaFile) MarkAllUnhealthyChunksAsStuck ¶
func (sf *SiaFile) MarkAllUnhealthyChunksAsStuck(offline map[string]bool, goodForRenew map[string]bool) (err error)
MarkAllUnhealthyChunksAsStuck marks all unhealthy chunks as stuck in the siafile
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) NumStuckChunks ¶
NumStuckChunks returns the Number of Stuck Chunks recorded in the file's metadata
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) RecentRepairTime ¶
RecentRepairTime returns the RecentRepairTime timestamp of the file
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) SnapshotReader ¶
func (sf *SiaFile) SnapshotReader() (*SnapshotReader, error)
SnapshotReader creates a io.ReadCloser that can be used to read the raw Siafile from disk.
func (*SiaFile) StuckChunkByIndex ¶
StuckChunkByIndex returns if the chunk at the index is marked as Stuck or not
func (*SiaFile) UpdateAccessTime ¶
UpdateAccessTime updates the AccessTime timestamp to the current time.
func (*SiaFile) UpdateCachedHealthMetadata ¶
func (sf *SiaFile) UpdateCachedHealthMetadata(metadata CachedHealthMetadata) error
UpdateCachedHealthMetadata updates the siafile metadata fields that are the cached health values
func (*SiaFile) UpdateLastHealthCheckTime ¶
UpdateLastHealthCheckTime updates the LastHealthCheckTime timestamp to the current time.
func (*SiaFile) UpdateRecentRepairTime ¶
UpdateRecentRepairTime updates the RecentRepairTime timestamp to the current time.
func (*SiaFile) UpdateUsedHosts ¶
func (sf *SiaFile) UpdateUsedHosts(used []types.SiaPublicKey) error
UpdateUsedHosts updates the 'Used' flag for the entries in the pubKeyTable of the SiaFile. The keys of all used hosts should be passed to the method and the SiaFile will update the flag for hosts it knows of to 'true' and set hosts which were not passed in to 'false'.
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.
type SiaFileSet ¶
type SiaFileSet struct {
// contains filtered or unexported fields
}
SiaFileSet is a helper struct responsible for managing the renter's siafiles in memory
func NewSiaFileSet ¶
func NewSiaFileSet(filesDir string, wal *writeaheadlog.WAL) *SiaFileSet
NewSiaFileSet initializes and returns a SiaFileSet
func (*SiaFileSet) Delete ¶
func (sfs *SiaFileSet) Delete(siaPath modules.SiaPath) error
Delete deletes the SiaFileSetEntry's SiaFile
func (*SiaFileSet) Exists ¶
func (sfs *SiaFileSet) Exists(siaPath modules.SiaPath) bool
Exists checks to see if a file with the provided siaPath already exists in the renter
func (*SiaFileSet) NewFromLegacyData ¶
func (sfs *SiaFileSet) NewFromLegacyData(fd FileData) (*SiaFileSetEntry, error)
NewFromLegacyData creates a new SiaFile from data that was previously loaded from a legacy file.
func (*SiaFileSet) NewSiaFile ¶
func (sfs *SiaFileSet) NewSiaFile(up modules.FileUploadParams, masterKey crypto.CipherKey, fileSize uint64, fileMode os.FileMode) (*SiaFileSetEntry, error)
NewSiaFile create a new SiaFile, adds it to the SiaFileSet, adds the thread to the threadMap, and returns the SiaFileSetEntry. Since this method returns the SiaFileSetEntry, wherever NewSiaFile is called there should be a Close called on the SiaFileSetEntry to avoid the file being stuck in memory due the thread never being removed from the threadMap
func (*SiaFileSet) Open ¶
func (sfs *SiaFileSet) Open(siaPath modules.SiaPath) (*SiaFileSetEntry, error)
Open returns the siafile from the SiaFileSet for the corresponding key and adds the thread to the entry's threadMap. If the siafile is not in memory it will load it from disk
type SiaFileSetEntry ¶
type SiaFileSetEntry struct {
// contains filtered or unexported fields
}
SiaFileSetEntry is the exported struct that is returned to the thread accessing the SiaFile and the Entry
func (*SiaFileSetEntry) Close ¶
func (entry *SiaFileSetEntry) Close() error
Close will close the set entry, removing the entry from memory if there are no other entries using the siafile.
Note that 'Close' grabs a lock on the SiaFileSet, do not call this function while holding a lock on the SiafileSet - standard concurrency conventions though dictate that you should not be calling exported / capitalized functions while holding a lock anyway, but this function is particularly sensitive to that.
func (*SiaFileSetEntry) CopyEntry ¶
func (entry *SiaFileSetEntry) CopyEntry() *SiaFileSetEntry
CopyEntry returns a copy of the SiaFileSetEntry
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is a snapshot of a SiaFile. A snapshot is a deep-copy and can be accessed without locking at the cost of being a frozen readonly representation of a siafile which only exists in memory.
func (*Snapshot) 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 (*Snapshot) ErasureCode ¶
func (s *Snapshot) ErasureCode() modules.ErasureCoder
ErasureCode returns the erasure coder used by the file.
func (*Snapshot) 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 (*Snapshot) Pieces ¶
Pieces returns all the pieces for a chunk in a slice of slices that contains all the pieces for a certain index.
type SnapshotReader ¶
type SnapshotReader struct {
// contains filtered or unexported fields
}
SnapshotReader is a helper type that allows reading a raw SiaFile from disk while keeping the file in memory locked.
func (*SnapshotReader) Close ¶
func (sfr *SnapshotReader) Close() error
Close closes the underlying file.