Documentation ¶
Overview ¶
Package renterutil provides convenience functions for common renter actions.
Index ¶
- Variables
- func Checkup(contracts renter.ContractSet, m *renter.MetaFile, hkr renter.HostKeyResolver) <-chan CheckupResult
- func ScanHosts(hosts []hostdb.HostPublicKey, hkr renter.HostKeyResolver) <-chan ScanResult
- type CheckupResult
- type DialStatsUpdate
- type DirQueueUpdate
- type DirSkipUpdate
- type DownloadStatsUpdate
- type FileIter
- type HostSet
- type MigrateDirIter
- type MigrateSkipUpdate
- type Operation
- func MigrateDirDirect(newcontracts renter.ContractSet, nextFile MigrateDirIter, ...) *Operation
- func MigrateDirFile(newcontracts renter.ContractSet, nextFile FileIter, hkr renter.HostKeyResolver, ...) *Operation
- func MigrateDirRemote(newcontracts renter.ContractSet, nextFile MigrateDirIter, ...) *Operation
- func MigrateDirect(newcontracts, oldcontracts renter.ContractSet, m *renter.MetaFile, ...) *Operation
- func MigrateFile(f *os.File, newcontracts renter.ContractSet, m *renter.MetaFile, ...) *Operation
- func MigrateRemote(newcontracts, oldcontracts renter.ContractSet, m *renter.MetaFile, ...) *Operation
- type PseudoFS
- func (fs *PseudoFS) Chmod(name string, mode os.FileMode) error
- func (fs *PseudoFS) Close() error
- func (fs *PseudoFS) Create(name string, minShards int) (*PseudoFile, error)
- func (fs *PseudoFS) Mkdir(name string, perm os.FileMode) error
- func (fs *PseudoFS) MkdirAll(path string, perm os.FileMode) error
- func (fs *PseudoFS) Open(name string) (*PseudoFile, error)
- func (fs *PseudoFS) OpenFile(name string, flag int, perm os.FileMode, minShards int) (*PseudoFile, error)
- func (fs *PseudoFS) Remove(name string) error
- func (fs *PseudoFS) RemoveAll(path string) error
- func (fs *PseudoFS) Rename(oldname, newname string) error
- func (fs *PseudoFS) Stat(name string) (os.FileInfo, error)
- type PseudoFile
- func (pf PseudoFile) Close() error
- func (pf PseudoFile) Name() string
- func (pf PseudoFile) Read(p []byte) (int, error)
- func (pf PseudoFile) ReadAt(p []byte, off int64) (int, error)
- func (pf PseudoFile) Readdir(n int) ([]os.FileInfo, error)
- func (pf PseudoFile) Readdirnames(n int) ([]string, error)
- func (pf PseudoFile) Seek(offset int64, whence int) (int64, error)
- func (pf PseudoFile) Stat() (os.FileInfo, error)
- func (pf PseudoFile) Sync() error
- func (pf PseudoFile) Truncate(size int64) error
- func (pf PseudoFile) Write(p []byte) (int, error)
- func (pf PseudoFile) WriteAt(p []byte, off int64) (int, error)
- type SHARDClient
- type ScanResult
- type SiadClient
- func (c *SiadClient) AcceptTransactionSet(txnSet []types.Transaction) error
- func (c *SiadClient) ChainHeight() (types.BlockHeight, error)
- func (c *SiadClient) FeeEstimate() (minFee, maxFee types.Currency, err error)
- func (c *SiadClient) LookupHost(prefix string) (hostdb.HostPublicKey, error)
- func (c *SiadClient) NewWalletAddress() (types.UnlockHash, error)
- func (c *SiadClient) ResolveHostKey(pubkey hostdb.HostPublicKey) (modules.NetAddress, error)
- func (c *SiadClient) SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error
- func (c *SiadClient) Synced() (bool, error)
- func (c *SiadClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)
- func (c *SiadClient) UnspentOutputs() ([]modules.UnspentOutput, error)
- type TransferProgressUpdate
- type UploadStatsUpdate
- type WalrusClient
- func (c *WalrusClient) AcceptTransactionSet(txnSet []types.Transaction) error
- func (c *WalrusClient) FeeEstimate() (minFee, maxFee types.Currency, err error)
- func (c *WalrusClient) NewWalletAddress() (types.UnlockHash, error)
- func (c *WalrusClient) SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error
- func (c *WalrusClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)
- func (c *WalrusClient) UnspentOutputs() ([]modules.UnspentOutput, error)
Constants ¶
This section is empty.
Variables ¶
var ErrAppendOnly = errors.New("file is append-only")
ErrAppendOnly is returned for seek operations on append-only files.
var ErrCanceled = errors.New("canceled")
ErrCanceled indicates that the Operation was canceled.
var ErrNotReadable = errors.New("file is not readable")
ErrNotReadable is returned for read operations on write-only files.
var ErrNotWriteable = errors.New("file is not writeable")
ErrNotWriteable is returned for write operations on read-only files.
Functions ¶
func Checkup ¶
func Checkup(contracts renter.ContractSet, m *renter.MetaFile, hkr renter.HostKeyResolver) <-chan CheckupResult
Checkup attempts to download a random slice from each host storing the data referenced by m. It reports whether the download was successful, along with network metrics.
func ScanHosts ¶
func ScanHosts(hosts []hostdb.HostPublicKey, hkr renter.HostKeyResolver) <-chan ScanResult
ScanHosts scans the provided hosts in parallel and reports their settings, along with network metrics.
Types ¶
type CheckupResult ¶
type CheckupResult struct { Host hostdb.HostPublicKey Latency time.Duration Bandwidth float64 // Mbps Error error }
A CheckupResult contains the result of a host checkup.
func CheckupContract ¶
func CheckupContract(contract *renter.Contract, hkr renter.HostKeyResolver) CheckupResult
CheckupContract attempts to download a random sector from the specified contract. It reports whether the download was successful, along with network metrics. Note that unlike Checkup, CheckupContracts cannot verify the integrity of the downloaded sector.
type DialStatsUpdate ¶ added in v0.2.0
type DialStatsUpdate struct { Host hostdb.HostPublicKey `json:"host"` Stats proto.DialStats `json:"stats"` }
DialStatsUpdate records metrics about dialing a host.
type DirQueueUpdate ¶
A DirQueueUpdate indicates that a file has been queued as part of a multi- file Operation.
type DirSkipUpdate ¶
A DirSkipUpdate indicates that a file has been skipped as part of a multi- file Operation.
type DownloadStatsUpdate ¶ added in v0.2.0
type DownloadStatsUpdate struct { Host hostdb.HostPublicKey `json:"host"` Stats proto.DownloadStats `json:"stats"` }
DownloadStatsUpdate records metrics about downloading sector data from a host.
func DownloadChunkShards ¶
func DownloadChunkShards(hosts []*renter.ShardDownloader, chunkIndex int64, minShards int, cancel <-chan struct{}) (shards [][]byte, shardLen int, stats []DownloadStatsUpdate, err error)
DownloadChunkShards downloads the shards of chunkIndex from hosts in parallel. shardLen is the length of the first non-nil shard.
The shards returned by DownloadChunkShards are only valid until the next call to Sector on the shard's corresponding proto.Downloader.
type FileIter ¶
FileIter is an iterator that returns the next filepath and the filepath of the file's metafile. It should return io.EOF to signal the end of iteration.
func NewRecursiveFileIter ¶
NewRecursiveFileIter returns a FileIter that iterates over a nested set of directories.
func NewRecursiveMetaFileIter ¶
NewRecursiveMetaFileIter returns a FileIter that iterates over a nested set of directories, metafiles first.
func NewShallowFileIter ¶
NewShallowFileIter returns a FileIter that iterates over a single directory.
type HostSet ¶ added in v0.2.0
type HostSet struct {
// contains filtered or unexported fields
}
A HostSet is a collection of renter-host protocol sessions.
func NewHostSet ¶ added in v0.2.0
func NewHostSet(contracts renter.ContractSet, hkr renter.HostKeyResolver, currentHeight types.BlockHeight) *HostSet
NewHostSet creates a HostSet composed of one protocol session per contract. If a session cannot be established, that contract is skipped; these errors are exposed via the acquire method.
type MigrateDirIter ¶
type MigrateDirIter func() (string, renter.ContractSet, error)
MigrateDirIter is an iterator that returns the next metafile path and the ContractSet containing the metafile's contracts. It should return io.EOF to signal the end of iteration.
func NewRecursiveMigrateDirIter ¶
func NewRecursiveMigrateDirIter(metaDir, contractDir string) MigrateDirIter
NewRecursiveMigrateDirIter returns a MigrateDirIter that iterates over a nested set of directories.
type MigrateSkipUpdate ¶
type MigrateSkipUpdate struct { Host hostdb.HostPublicKey Err error }
A MigrateSkipUpdate indicates that a host will not be migrated to.
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
An Operation represents a long-running operation, such as an upload, download, or migration.
func MigrateDirDirect ¶
func MigrateDirDirect(newcontracts renter.ContractSet, nextFile MigrateDirIter, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateDirDirect runs the MigrateDirect process on each metafile in a directory.
func MigrateDirFile ¶
func MigrateDirFile(newcontracts renter.ContractSet, nextFile FileIter, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateDirFile runs the MigrateFile process on each metafile in a directory, using it's corresponding file on disk. The directory structure of the files and metafiles must match.
func MigrateDirRemote ¶
func MigrateDirRemote(newcontracts renter.ContractSet, nextFile MigrateDirIter, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateDirRemote runs the MigrateRemote process on each metafile in a directory.
func MigrateDirect ¶
func MigrateDirect(newcontracts, oldcontracts renter.ContractSet, m *renter.MetaFile, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateDirect transfers file shards from one set of hosts to another. Each "old" host is paired with a "new" host, and the shards of each old host are downloaded and reuploaded to their corresponding new host.
Unlike the other Migrate functions, MigrateDirect will continue migrating even if some old hosts become unreachable.
func MigrateFile ¶
func MigrateFile(f *os.File, newcontracts renter.ContractSet, m *renter.MetaFile, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateFile uploads file shards to a new set of hosts. The shards are retrieved by erasure-encoding f.
func MigrateRemote ¶
func MigrateRemote(newcontracts, oldcontracts renter.ContractSet, m *renter.MetaFile, hkr renter.HostKeyResolver, height types.BlockHeight) *Operation
MigrateRemote uploads file shards to a new set of hosts. The shards are retrieved by downloading the file from the current set of hosts. (However, MigrateRemote never downloads from hosts that are not in the new set.)
func (*Operation) Cancel ¶
func (op *Operation) Cancel()
Cancel cancels op, causing Err to report ErrCanceled.
type PseudoFS ¶ added in v0.2.0
type PseudoFS struct {
// contains filtered or unexported fields
}
PseudoFS implements a filesystem by downloading data from Sia hosts.
func NewFileSystem ¶ added in v0.2.0
func NewFileSystem(root string, contracts renter.ContractSet, hkr renter.HostKeyResolver, currentHeight types.BlockHeight) *PseudoFS
NewFileSystem returns a new pseudo-filesystem rooted at root, which must be a directory containing only metafiles and other directories.
func (*PseudoFS) Close ¶ added in v0.2.0
Close closes the filesystem by flushing any uncommitted writes, closing any open files, and terminating all active host sessions.
func (*PseudoFS) Create ¶ added in v0.2.0
func (fs *PseudoFS) Create(name string, minShards int) (*PseudoFile, error)
Create creates the named file with the specified redundancy and mode 0666 (before umask), truncating it if it already exists. The returned file has mode O_RDWR.
func (*PseudoFS) Mkdir ¶ added in v0.2.0
Mkdir creates a new directory with the specified name and permission bits (before umask).
func (*PseudoFS) MkdirAll ¶ added in v0.2.0
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (*PseudoFS) Open ¶ added in v0.2.0
func (fs *PseudoFS) Open(name string) (*PseudoFile, error)
Open opens the named file for reading. The returned file is read-only.
func (*PseudoFS) OpenFile ¶ added in v0.2.0
func (fs *PseudoFS) OpenFile(name string, flag int, perm os.FileMode, minShards int) (*PseudoFile, error)
OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (os.O_RDONLY etc.) and perm (before umask), if applicable.
func (*PseudoFS) RemoveAll ¶ added in v0.2.0
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
type PseudoFile ¶ added in v0.2.0
type PseudoFile struct {
// contains filtered or unexported fields
}
A PseudoFile presents a file-like interface for a metafile stored on Sia hosts.
func (PseudoFile) Close ¶ added in v0.2.0
func (pf PseudoFile) Close() error
Close implements io.Closer.
func (PseudoFile) Name ¶ added in v0.2.0
func (pf PseudoFile) Name() string
Name returns the file's name, as passed to OpenFile.
func (PseudoFile) Read ¶ added in v0.2.0
func (pf PseudoFile) Read(p []byte) (int, error)
Read implements io.Reader.
func (PseudoFile) ReadAt ¶ added in v0.2.0
func (pf PseudoFile) ReadAt(p []byte, off int64) (int, error)
ReadAt implements io.ReaderAt.
func (PseudoFile) Readdir ¶ added in v0.2.0
func (pf PseudoFile) Readdir(n int) ([]os.FileInfo, error)
Readdir reads the contents of the directory associated with pf and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.
If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.
func (PseudoFile) Readdirnames ¶ added in v0.2.0
func (pf PseudoFile) Readdirnames(n int) ([]string, error)
Readdirnames reads and returns a slice of names from the directory pf.
If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error.
func (PseudoFile) Seek ¶ added in v0.2.0
func (pf PseudoFile) Seek(offset int64, whence int) (int64, error)
Seek implements io.Seeker.
func (PseudoFile) Stat ¶ added in v0.2.0
func (pf PseudoFile) Stat() (os.FileInfo, error)
Stat returns the FileInfo structure describing the file. If the file is a metafile, its renter.MetaIndex will be available via the Sys method.
func (PseudoFile) Sync ¶ added in v0.2.0
func (pf PseudoFile) Sync() error
Sync commits the current contents of the file to stable storage. Any new data will be uploaded to hosts, and the metafile will be atomically updated to match the current state of the file. Calling Sync on one file may cause other files to be synced as well. Sync typically results in a full sector of data being uploaded to each host.
func (PseudoFile) Truncate ¶ added in v0.2.0
func (pf PseudoFile) Truncate(size int64) error
Truncate changes the size of the file. It does not change the I/O offset. The new size must not exceed the current size.
type SHARDClient ¶ added in v0.2.0
type SHARDClient struct {
// contains filtered or unexported fields
}
A SHARDClient communicates with a SHARD server. It satisfies the renter.HostKeyResolver interface.
func NewSHARDClient ¶ added in v0.2.0
func NewSHARDClient(addr string) *SHARDClient
NewSHARDClient returns a SHARDClient that communicates with the SHARD server at the specified address.
func (*SHARDClient) ChainHeight ¶ added in v0.2.0
func (c *SHARDClient) ChainHeight() (types.BlockHeight, error)
ChainHeight returns the current block height.
func (*SHARDClient) LookupHost ¶ added in v0.2.0
func (c *SHARDClient) LookupHost(prefix string) (hostdb.HostPublicKey, error)
LookupHost returns the host public key matching the specified prefix.
func (*SHARDClient) ResolveHostKey ¶ added in v0.2.0
func (c *SHARDClient) ResolveHostKey(pubkey hostdb.HostPublicKey) (modules.NetAddress, error)
ResolveHostKey resolves a host public key to that host's most recently announced network address.
func (*SHARDClient) Synced ¶ added in v0.2.0
func (c *SHARDClient) Synced() (bool, error)
Synced returns whether the SHARD server is synced.
type ScanResult ¶
type ScanResult struct { Host hostdb.ScannedHost Error error }
A ScanResult contains the result of a host scan.
type SiadClient ¶ added in v0.2.0
type SiadClient struct {
// contains filtered or unexported fields
}
SiadClient wraps the siad API client. It satisfies the proto.Wallet, proto.TransactionPool, and renter.HostKeyResolver interfaces. The proto.Wallet methods require that the wallet is unlocked.
func NewSiadClient ¶ added in v0.2.0
func NewSiadClient(addr, password string) *SiadClient
NewSiadClient returns a SiadClient that communicates with the siad API server at the specified address.
func (*SiadClient) AcceptTransactionSet ¶ added in v0.2.0
func (c *SiadClient) AcceptTransactionSet(txnSet []types.Transaction) error
AcceptTransactionSet submits a transaction set to the transaction pool, where it will be broadcast to other peers.
func (*SiadClient) ChainHeight ¶ added in v0.2.0
func (c *SiadClient) ChainHeight() (types.BlockHeight, error)
ChainHeight returns the current block height.
func (*SiadClient) FeeEstimate ¶ added in v0.2.0
func (c *SiadClient) FeeEstimate() (minFee, maxFee types.Currency, err error)
FeeEstimate returns the current estimate for transaction fees, in Hastings per byte.
func (*SiadClient) LookupHost ¶ added in v0.2.0
func (c *SiadClient) LookupHost(prefix string) (hostdb.HostPublicKey, error)
LookupHost returns the host public key matching the specified prefix.
func (*SiadClient) NewWalletAddress ¶ added in v0.2.0
func (c *SiadClient) NewWalletAddress() (types.UnlockHash, error)
NewWalletAddress returns a new address generated by the wallet.
func (*SiadClient) ResolveHostKey ¶ added in v0.2.0
func (c *SiadClient) ResolveHostKey(pubkey hostdb.HostPublicKey) (modules.NetAddress, error)
ResolveHostKey resolves a host public key to that host's most recently announced network address.
func (*SiadClient) SignTransaction ¶ added in v0.2.0
func (c *SiadClient) SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error
SignTransaction adds the specified signatures to the transaction using private keys known to the wallet.
func (*SiadClient) Synced ¶ added in v0.2.0
func (c *SiadClient) Synced() (bool, error)
Synced returns whether the siad node believes it is fully synchronized with the rest of the network.
func (*SiadClient) UnlockConditions ¶ added in v0.2.0
func (c *SiadClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)
UnlockConditions returns the UnlockConditions that correspond to the specified address.
func (*SiadClient) UnspentOutputs ¶ added in v0.2.0
func (c *SiadClient) UnspentOutputs() ([]modules.UnspentOutput, error)
UnspentOutputs returns the set of outputs tracked by the wallet that are spendable.
type TransferProgressUpdate ¶
A TransferProgressUpdate details the number of bytes transferred during the course of an Operation.
type UploadStatsUpdate ¶ added in v0.2.0
type UploadStatsUpdate struct { Host hostdb.HostPublicKey `json:"host"` Stats proto.UploadStats `json:"stats"` }
UploadStatsUpdate records metrics about uploading sector data to a host.
type WalrusClient ¶ added in v0.2.0
type WalrusClient struct {
// contains filtered or unexported fields
}
WalrusClient wraps the walrus API. It satisfies the proto.Wallet and proto.TransactionPool interfaces.
func NewWalrusClient ¶ added in v0.2.0
func NewWalrusClient(addr string) *WalrusClient
NewWalrusClient returns a WalrusClient that communicates with the walrus server at the specified address.
func (*WalrusClient) AcceptTransactionSet ¶ added in v0.2.0
func (c *WalrusClient) AcceptTransactionSet(txnSet []types.Transaction) error
AcceptTransactionSet submits a transaction set to the transaction pool, where it will be broadcast to other peers.
func (*WalrusClient) FeeEstimate ¶ added in v0.2.0
func (c *WalrusClient) FeeEstimate() (minFee, maxFee types.Currency, err error)
FeeEstimate returns the current estimate for transaction fees, in Hastings per byte.
func (*WalrusClient) NewWalletAddress ¶ added in v0.2.0
func (c *WalrusClient) NewWalletAddress() (types.UnlockHash, error)
NewWalletAddress returns a new address generated by the wallet.
func (*WalrusClient) SignTransaction ¶ added in v0.2.0
func (c *WalrusClient) SignTransaction(txn *types.Transaction, toSign []crypto.Hash) error
SignTransaction adds the specified signatures to the transaction using private keys known to the wallet.
func (*WalrusClient) UnlockConditions ¶ added in v0.2.0
func (c *WalrusClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)
UnlockConditions returns the UnlockConditions that correspond to the specified address.
func (*WalrusClient) UnspentOutputs ¶ added in v0.2.0
func (c *WalrusClient) UnspentOutputs() ([]modules.UnspentOutput, error)
UnspentOutputs returns the set of outputs tracked by the wallet that are spendable.