renterutil

package
v0.0.0-...-004b060 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package renterutil provides convenience functions for common renter actions.

Index

Constants

This section is empty.

Variables

View Source
var ErrAppendOnly = errors.New("file is append-only")

ErrAppendOnly is returned for seek operations on append-only files.

View Source
var ErrCanceled = errors.New("canceled")

ErrCanceled indicates that the Operation was canceled.

View Source
var ErrNotReadable = errors.New("file is not readable")

ErrNotReadable is returned for read operations on write-only files.

View Source
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

type DialStatsUpdate struct {
	Host  hostdb.HostPublicKey `json:"host"`
	Stats proto.DialStats      `json:"stats"`
}

DialStatsUpdate records metrics about dialing a host.

type DirQueueUpdate

type DirQueueUpdate struct {
	Filename string
	Filesize int64
}

A DirQueueUpdate indicates that a file has been queued as part of a multi- file Operation.

type DirSkipUpdate

type DirSkipUpdate struct {
	Filename string
	Err      error
}

A DirSkipUpdate indicates that a file has been skipped as part of a multi- file Operation.

type DownloadStatsUpdate

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

type FileIter func() (string, string, error)

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

func NewRecursiveFileIter(dir, metaDir string) FileIter

NewRecursiveFileIter returns a FileIter that iterates over a nested set of directories.

func NewRecursiveMetaFileIter

func NewRecursiveMetaFileIter(metaDir, dir string) FileIter

NewRecursiveMetaFileIter returns a FileIter that iterates over a nested set of directories, metafiles first.

func NewShallowFileIter

func NewShallowFileIter(dir, metaDir string) FileIter

NewShallowFileIter returns a FileIter that iterates over a single directory.

type HostSet

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

A HostSet is a collection of renter-host protocol sessions.

func NewHostSet

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.

func (*HostSet) Close

func (set *HostSet) Close() error

Close closes all of the Downloaders in the set.

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.

func (*Operation) Canceled

func (op *Operation) Canceled() bool

Canceled returns whether op was canceled.

func (*Operation) Err

func (op *Operation) Err() error

Err returns the error that caused op to fail. It is only valid after the Updates channel has been closed.

func (*Operation) Updates

func (op *Operation) Updates() <-chan interface{}

Updates returns op's update channel. Callers should use a type switch to distinguish between various types of update. The channel is closed when op completes.

type PseudoFS

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

PseudoFS implements a filesystem by downloading data from Sia hosts.

func NewFileSystem

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) Chmod

func (fs *PseudoFS) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*PseudoFS) Close

func (fs *PseudoFS) Close() error

Close closes the filesystem by flushing any uncommitted writes, closing any open files, and terminating all active host sessions.

func (*PseudoFS) Create

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

func (fs *PseudoFS) Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory with the specified name and permission bits (before umask).

func (*PseudoFS) MkdirAll

func (fs *PseudoFS) MkdirAll(path string, perm os.FileMode) error

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

func (fs *PseudoFS) Open(name string) (*PseudoFile, error)

Open opens the named file for reading. The returned file is read-only.

func (*PseudoFS) OpenFile

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) Remove

func (fs *PseudoFS) Remove(name string) error

Remove removes the named file or (empty) directory.

func (*PseudoFS) RemoveAll

func (fs *PseudoFS) RemoveAll(path string) error

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).

func (*PseudoFS) Rename

func (fs *PseudoFS) Rename(oldname, newname string) error

Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories.

func (*PseudoFS) Stat

func (fs *PseudoFS) Stat(name string) (os.FileInfo, error)

Stat returns the FileInfo structure describing file.

type PseudoFile

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

func (pf PseudoFile) Close() error

Close implements io.Closer.

func (PseudoFile) Name

func (pf PseudoFile) Name() string

Name returns the file's name, as passed to OpenFile.

func (PseudoFile) Read

func (pf PseudoFile) Read(p []byte) (int, error)

Read implements io.Reader.

func (PseudoFile) ReadAt

func (pf PseudoFile) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt.

func (PseudoFile) Readdir

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

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

func (pf PseudoFile) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (PseudoFile) Stat

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

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

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.

func (PseudoFile) Write

func (pf PseudoFile) Write(p []byte) (int, error)

Write implements io.Writer.

func (PseudoFile) WriteAt

func (pf PseudoFile) WriteAt(p []byte, off int64) (int, error)

WriteAt implements io.WriterAt.

type SHARDClient

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

A SHARDClient communicates with a SHARD server. It satisfies the renter.HostKeyResolver interface.

func NewSHARDClient

func NewSHARDClient(addr string) *SHARDClient

NewSHARDClient returns a SHARDClient that communicates with the SHARD server at the specified address.

func (*SHARDClient) ChainHeight

func (c *SHARDClient) ChainHeight() (types.BlockHeight, error)

ChainHeight returns the current block height.

func (*SHARDClient) ResolveHostKey

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

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

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

func NewSiadClient(addr, password string) *SiadClient

NewSiadClient returns a SiadClient that communicates with the siad API server at the specified address.

func (*SiadClient) AcceptTransactionSet

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

func (c *SiadClient) ChainHeight() (types.BlockHeight, error)

ChainHeight returns the current block height.

func (*SiadClient) FeeEstimate

func (c *SiadClient) FeeEstimate() (minFee, maxFee types.Currency, err error)

FeeEstimate returns the current estimate for transaction fees, in Hastings per byte.

func (*SiadClient) Hosts

func (c *SiadClient) Hosts() ([]hostdb.HostPublicKey, error)

Hosts returns the public keys of every host that has announced on the blockchain.

func (*SiadClient) NewWalletAddress

func (c *SiadClient) NewWalletAddress() (types.UnlockHash, error)

NewWalletAddress returns a new address generated by the wallet.

func (*SiadClient) ResolveHostKey

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

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

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

func (c *SiadClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)

UnlockConditions returns the UnlockConditions that correspond to the specified address.

func (*SiadClient) UnspentOutputs

func (c *SiadClient) UnspentOutputs() ([]modules.UnspentOutput, error)

UnspentOutputs returns the set of outputs tracked by the wallet that are spendable.

type TransferProgressUpdate

type TransferProgressUpdate struct {
	Total       int64
	Start       int64
	Transferred int64
}

A TransferProgressUpdate details the number of bytes transferred during the course of an Operation.

type UploadStatsUpdate

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

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

WalrusClient wraps the walrus API. It satisfies the proto.Wallet and proto.TransactionPool interfaces.

func NewWalrusClient

func NewWalrusClient(addr string) *WalrusClient

NewWalrusClient returns a WalrusClient that communicates with the walrus server at the specified address.

func (*WalrusClient) AcceptTransactionSet

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

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

func (c *WalrusClient) NewWalletAddress() (types.UnlockHash, error)

NewWalletAddress returns a new address generated by the wallet.

func (*WalrusClient) SignTransaction

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

func (c *WalrusClient) UnlockConditions(addr types.UnlockHash) (types.UnlockConditions, error)

UnlockConditions returns the UnlockConditions that correspond to the specified address.

func (*WalrusClient) UnspentOutputs

func (c *WalrusClient) UnspentOutputs() ([]modules.UnspentOutput, error)

UnspentOutputs returns the set of outputs tracked by the wallet that are spendable.

Jump to

Keyboard shortcuts

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