renter

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: 30 Imported by: 2

Documentation

Overview

Package renter is responsible for uploading and downloading files on the sia network.

Index

Constants

View Source
const (

	// DefaultStreamCacheSize is the default cache size of the /renter/stream cache in
	// chunks, the user can set a custom cache size through the API
	DefaultStreamCacheSize = 2

	// DefaultMaxDownloadSpeed is set to zero to indicate no limit, the user
	// can set a custom MaxDownloadSpeed through the API
	DefaultMaxDownloadSpeed = 0

	// DefaultMaxUploadSpeed is set to zero to indicate no limit, the user
	// can set a custom MaxUploadSpeed through the API
	DefaultMaxUploadSpeed = 0
)
View Source
const (

	// PersistFilename is the filename to be used when persisting renter information to a JSON file
	PersistFilename = "renter.json"
	// ShareExtension is the extension to be used
	ShareExtension = ".sia"
	// SiaDirMetadata is the name of the metadata file for the sia directory
	SiaDirMetadata = ".siadir"
)

Variables

View Source
var (
	// ErrEmptyFilename is an error when filename is empty
	ErrEmptyFilename = errors.New("filename must be a nonempty string")
	// 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")
)
View Source
var (
	//ErrBadFile is an error when a file does not qualify as .sia file
	ErrBadFile = errors.New("not a .sia file")
	// ErrIncompatible is an error when file is not compatible with current version
	ErrIncompatible = errors.New("file is not compatible with current version")
	// ErrNoNicknames is an error when no nickname is given
	ErrNoNicknames = errors.New("at least one nickname must be supplied")
	// ErrNonShareSuffix is an error when the suffix of a file does not match the defined share extension
	ErrNonShareSuffix = errors.New("suffix of file must be " + ShareExtension)
)
View Source
var (

	// RemoteRepairDownloadThreshold defines the threshold in percent under
	// which the renter starts repairing a file that is not available on disk.
	RemoteRepairDownloadThreshold = build.Select(build.Var{
		Dev:      0.25,
		Standard: 0.25,
		Testing:  0.25,
	}).(float64)
)

Functions

func NewDownloadDestinationBuffer

func NewDownloadDestinationBuffer(length, pieceSize uint64) downloadDestinationBuffer

NewDownloadDestinationBuffer allocates the necessary number of shards for the downloadDestinationBuffer and returns the new buffer.

Types

type Renter

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

A Renter is responsible for tracking all of the files that a user has uploaded to Sia, as well as the locations and health of these files.

TODO: Separate the workerPool to have its own mutex. The workerPool doesn't interfere with any of the other fields in the renter, should be fine for it to have a separate mutex, that way operations on the worker pool don't block operations on other parts of the struct. If we're going to do it that way, might make sense to split the worker pool off into it's own struct entirely the same way that we split of the memoryManager entirely.

func New

func New(g modules.Gateway, cs modules.ConsensusSet, wallet modules.Wallet, tpool modules.TransactionPool, persistDir string) (*Renter, error)

New returns an initialized renter.

func NewCustomRenter

func NewCustomRenter(g modules.Gateway, cs modules.ConsensusSet, tpool modules.TransactionPool, hdb hostDB, hc hostContractor, persistDir string, deps modules.Dependencies) (*Renter, error)

NewCustomRenter initializes a renter and returns it.

func (*Renter) ActiveHosts

func (r *Renter) ActiveHosts() []modules.HostDBEntry

ActiveHosts returns an array of hostDB's active hosts

func (*Renter) AllHosts

func (r *Renter) AllHosts() []modules.HostDBEntry

AllHosts returns an array of all hosts

func (*Renter) CancelContract

func (r *Renter) CancelContract(id types.FileContractID) error

CancelContract cancels a renter's contract by ID by setting goodForRenew and goodForUpload to false

func (*Renter) ClearDownloadHistory

func (r *Renter) ClearDownloadHistory(after, before time.Time) error

ClearDownloadHistory clears the renter's download history inclusive of the provided before and after timestamps

TODO: This function can be improved by implementing a binary search, the trick will be making the binary search be just as readable while handling all the edge cases

func (*Renter) Close

func (r *Renter) Close() error

Close closes the Renter and its dependencies

func (*Renter) ContractUtility

func (r *Renter) ContractUtility(pk types.SiaPublicKey) (modules.ContractUtility, bool)

ContractUtility returns the utility field for a given contract, along with a bool indicating if it exists.

func (*Renter) Contracts

func (r *Renter) Contracts() []modules.RenterContract

Contracts returns an array of host contractor's staticContracts

func (*Renter) CreateDir

func (r *Renter) CreateDir(siaPath string) error

CreateDir creates a directory for the renter

func (*Renter) CurrentPeriod

func (r *Renter) CurrentPeriod() types.BlockHeight

CurrentPeriod returns the host contractor's current period

func (*Renter) DeleteFile

func (r *Renter) DeleteFile(nickname string) error

DeleteFile removes a file entry from the renter and deletes its data from the hosts it is stored on.

TODO: The data is not cleared from any contracts where the host is not immediately online.

func (*Renter) Download

Download performs a file download using the passed parameters and blocks until the download is finished.

func (*Renter) DownloadAsync

func (r *Renter) DownloadAsync(p modules.RenterDownloadParameters) error

DownloadAsync performs a file download using the passed parameters without blocking until the download is finished.

func (*Renter) DownloadHistory

func (r *Renter) DownloadHistory() []modules.DownloadInfo

DownloadHistory returns the list of downloads that have been performed. Will include downloads that have not yet completed. Downloads will be roughly, but not precisely, sorted according to start time.

TODO: Currently the DownloadHistory only contains downloads from this session, does not contain downloads that were executed for the purposes of repairing, and has no way to clear the download history if it gets long or unwieldy. It's not entirely certain which of the missing features are actually desirable, please consult core team + app dev community before deciding what to implement.

func (*Renter) EstimateHostScore

func (r *Renter) EstimateHostScore(e modules.HostDBEntry) modules.HostScoreBreakdown

EstimateHostScore returns the estimated host score

func (*Renter) File

func (r *Renter) File(siaPath string) (modules.FileInfo, error)

File returns file from siaPath queried by user. Update based on FileList

func (*Renter) FileList

func (r *Renter) FileList(filter ...*regexp.Regexp) []modules.FileInfo

FileList returns all of the files that the renter has or a filtered list if a compiled Regexp is supplied. Filtering is applied to the hyperspace path.

func (*Renter) Host

func (r *Renter) Host(spk types.SiaPublicKey) (modules.HostDBEntry, bool)

Host returns the host associated with the given public key

func (*Renter) InitialScanComplete

func (r *Renter) InitialScanComplete() (bool, error)

InitialScanComplete returns a boolean indicating if the initial scan of the hostdb is completed.

func (*Renter) LoadSharedFiles

func (r *Renter) LoadSharedFiles(filename string) ([]string, error)

LoadSharedFiles loads a .sia file into the renter. It returns the nicknames of the loaded files.

func (*Renter) LoadSharedFilesASCII

func (r *Renter) LoadSharedFilesASCII(asciiSia string) ([]string, error)

LoadSharedFilesASCII loads an ASCII-encoded .sia file into the renter. It returns the nicknames of the loaded files.

func (*Renter) OldContracts

func (r *Renter) OldContracts() []modules.RenterContract

OldContracts returns an array of host contractor's oldContracts

func (*Renter) PeriodSpending

func (r *Renter) PeriodSpending() modules.ContractorSpending

PeriodSpending returns the host contractor's period spending

func (*Renter) PriceEstimation

func (r *Renter) PriceEstimation() modules.RenterPriceEstimation

PriceEstimation estimates the cost in siacoins of performing various storage and data operations.

TODO: Make this function line up with the actual settings in the renter. Perhaps even make it so it uses the renter's actual contracts if it has any.

func (*Renter) ProcessConsensusChange

func (r *Renter) ProcessConsensusChange(cc modules.ConsensusChange)

ProcessConsensusChange returns the process consensus change

func (*Renter) ProcessHeaderConsensusChange added in v0.2.3

func (r *Renter) ProcessHeaderConsensusChange(hcc modules.HeaderConsensusChange)

ProcessHeaderConsensusChange will reset the lastEstimation

func (*Renter) RenameFile

func (r *Renter) RenameFile(currentName, newName string) error

RenameFile takes an existing file and changes the nickname. The original file must exist, and there must not be any file that already has the replacement nickname.

func (*Renter) ScoreBreakdown

func (r *Renter) ScoreBreakdown(e modules.HostDBEntry) modules.HostScoreBreakdown

ScoreBreakdown returns the score breakdown

func (*Renter) SetFileTrackingPath

func (r *Renter) SetFileTrackingPath(siaPath, newPath string) error

SetFileTrackingPath sets the on-disk location of an uploaded file to a new value. Useful if files need to be moved on disk. SetFileTrackingPath will check that a file exists at the new location and it ensures that it has the right size, but it can't check that the content is the same. Therefore the caller is responsible for not accidentally corrupting the uploaded file by providing a different file with the same size.

func (*Renter) SetSettings

func (r *Renter) SetSettings(s modules.RenterSettings) error

SetSettings will update the settings for the renter.

NOTE: This function can't be atomic. Typically we try to have user requests be atomic, so that either everything changes or nothing changes, but since these changes happen progressively, it's possible for some of the settings (like the allowance) to succeed, but then if the bandwidth limits for example are bad, then the allowance will update but the bandwidth will not update.

func (*Renter) Settings

func (r *Renter) Settings() modules.RenterSettings

Settings returns the host contractor's allowance

func (*Renter) ShareFiles

func (r *Renter) ShareFiles(paths []string, shareDest string) error

ShareFiles writes an .sia file to disk to be shared with others.

func (*Renter) ShareFilesASCII

func (r *Renter) ShareFilesASCII(paths []string) (asciiSia string, err error)

ShareFilesASCII creates an ASCII-encoded '.sia' file.

func (*Renter) Streamer

func (r *Renter) Streamer(siaPath string) (string, io.ReadSeeker, error)

Streamer creates an io.ReadSeeker that can be used to stream downloads from the sia network.

func (*Renter) Upload

func (r *Renter) Upload(up modules.FileUploadParams) error

Upload instructs the renter to start tracking a file. The renter will automatically upload and repair tracked files using a background loop.

Directories

Path Synopsis
Package contractor is responsible for forming and renewing file contracts with hosts.
Package contractor is responsible for forming and renewing file contracts with hosts.
Package hostdb provides a HostDB object that implements the renter.hostDB interface.
Package hostdb provides a HostDB object that implements the renter.hostDB interface.

Jump to

Keyboard shortcuts

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