worker

package
v1.1.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 43 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShuttingDown = errors.New("worker is shutting down")
)

Functions

func GougingCheckerFromContext

func GougingCheckerFromContext(ctx context.Context, criticalMigration bool) (gouging.Checker, error)

Types

type AccountStore

type AccountStore interface {
	Accounts(ctx context.Context) ([]api.Account, error)
	AddBalance(ctx context.Context, id rhpv3.Account, hk types.PublicKey, amt *big.Int) error

	LockAccount(ctx context.Context, id rhpv3.Account, hostKey types.PublicKey, exclusive bool, duration time.Duration) (api.Account, uint64, error)
	UnlockAccount(ctx context.Context, id rhpv3.Account, lockID uint64) error

	SetBalance(ctx context.Context, id rhpv3.Account, hk types.PublicKey, amt *big.Int) error
	ScheduleSync(ctx context.Context, id rhpv3.Account, hk types.PublicKey) error
}

An AccountStore manages ephemaral accounts state.

type Client

type Client struct {
	*client.Client
}

re-export the client

func NewClient

func NewClient(address, password string) *Client

type ContractLocker

type ContractLocker interface {
	AcquireContract(ctx context.Context, fcid types.FileContractID, priority int, d time.Duration) (lockID uint64, err error)
	KeepaliveContract(ctx context.Context, fcid types.FileContractID, lockID uint64, d time.Duration) (err error)
	ReleaseContract(ctx context.Context, fcid types.FileContractID, lockID uint64) (err error)
}

type ContractSpendingRecorder

type ContractSpendingRecorder interface {
	Record(rev types.FileContractRevision, cs api.ContractSpending)
	Stop(context.Context)
}

type ContractStore added in v1.0.2

type ContractStore interface {
	Contract(ctx context.Context, id types.FileContractID) (api.ContractMetadata, error)
	ContractSize(ctx context.Context, id types.FileContractID) (api.ContractSize, error)
	ContractRoots(ctx context.Context, id types.FileContractID) ([]types.Hash256, []types.Hash256, error)
	Contracts(ctx context.Context, opts api.ContractsOpts) ([]api.ContractMetadata, error)
	RenewedContract(ctx context.Context, renewedFrom types.FileContractID) (api.ContractMetadata, error)
}

type Host added in v0.7.0

type Host interface {
	PublicKey() types.PublicKey

	DownloadSector(ctx context.Context, w io.Writer, root types.Hash256, offset, length uint32, overpay bool) error
	UploadSector(ctx context.Context, sectorRoot types.Hash256, sector *[rhpv2.SectorSize]byte, rev types.FileContractRevision) error

	PriceTable(ctx context.Context, rev *types.FileContractRevision) (api.HostPriceTable, types.Currency, error)
	PriceTableUnpaid(ctx context.Context) (hpt api.HostPriceTable, err error)
	FetchRevision(ctx context.Context, fetchTimeout time.Duration) (types.FileContractRevision, error)

	FundAccount(ctx context.Context, balance types.Currency, rev *types.FileContractRevision) error
	SyncAccount(ctx context.Context, rev *types.FileContractRevision) error

	RenewContract(ctx context.Context, rrr api.RHPRenewRequest) (_ rhpv2.ContractRevision, _ []types.Transaction, _, _ types.Currency, err error)
}

type HostErrorSet

type HostErrorSet map[types.PublicKey]error

A HostErrorSet is a collection of errors from various hosts.

func (HostErrorSet) Error

func (hes HostErrorSet) Error() string

Error implements error.

func (HostErrorSet) NumGouging added in v0.7.0

func (hes HostErrorSet) NumGouging() (n int)

NumGouging returns numbers of host that errored out due to price gouging.

type HostManager added in v0.7.0

type HostManager interface {
	Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr string) Host
}

type HostStore added in v1.0.3

type HostStore interface {
	RecordHostScans(ctx context.Context, scans []api.HostScan) error
	RecordPriceTables(ctx context.Context, priceTableUpdate []api.HostPriceTableUpdate) error
	RecordContractSpending(ctx context.Context, records []api.ContractSpendingRecord) error

	Host(ctx context.Context, hostKey types.PublicKey) (api.Host, error)
}

type Memory added in v0.7.0

type Memory interface {
	Release()
	ReleaseSome(amt uint64)
}

type MemoryManager added in v0.7.0

type MemoryManager interface {
	Status() api.MemoryStatus
	AcquireMemory(ctx context.Context, amt uint64) Memory
	Limit(amt uint64) (MemoryManager, error)
}

MemoryManager helps regulate processes that use a lot of memory. Such as uploads and downloads.

type ObjectStore added in v0.7.0

type ObjectStore interface {
	// NOTE: used for download
	DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) error
	FetchPartialSlab(ctx context.Context, key object.EncryptionKey, offset, length uint32) ([]byte, error)
	Slab(ctx context.Context, key object.EncryptionKey) (object.Slab, error)

	// NOTE: used for upload
	AddObject(ctx context.Context, bucket, path, contractSet string, o object.Object, opts api.AddObjectOptions) error
	AddMultipartPart(ctx context.Context, bucket, path, contractSet, ETag, uploadID string, partNumber int, slices []object.SlabSlice) (err error)
	AddPartialSlab(ctx context.Context, data []byte, minShards, totalShards uint8, contractSet string) (slabs []object.SlabSlice, slabBufferMaxSizeSoftReached bool, err error)
	AddUploadingSector(ctx context.Context, uID api.UploadID, id types.FileContractID, root types.Hash256) error
	FinishUpload(ctx context.Context, uID api.UploadID) error
	MarkPackedSlabsUploaded(ctx context.Context, slabs []api.UploadedPackedSlab) error
	TrackUpload(ctx context.Context, uID api.UploadID) error
	UpdateSlab(ctx context.Context, s object.Slab, contractSet string) error

	// NOTE: used by worker
	Bucket(_ context.Context, bucket string) (api.Bucket, error)
	Object(ctx context.Context, bucket, path string, opts api.GetObjectOptions) (api.ObjectsResponse, error)
	DeleteObject(ctx context.Context, bucket, path string, opts api.DeleteObjectOptions) error
	MultipartUpload(ctx context.Context, uploadID string) (resp api.MultipartUpload, err error)
	PackedSlabsForUpload(ctx context.Context, lockingDuration time.Duration, minShards, totalShards uint8, set string, limit int) ([]api.PackedSlab, error)
}

type SettingStore added in v1.0.6

type SettingStore interface {
	GougingParams(ctx context.Context) (api.GougingParams, error)
	UploadParams(ctx context.Context) (api.UploadParams, error)
}

type Syncer added in v1.0.6

type Syncer interface {
	BroadcastTransaction(ctx context.Context, txns []types.Transaction) error
	SyncerPeers(ctx context.Context) (resp []string, err error)
}

type UploadOption added in v0.6.0

type UploadOption func(*uploadParameters)

func WithBlockHeight added in v0.6.0

func WithBlockHeight(bh uint64) UploadOption

func WithContractSet added in v0.6.0

func WithContractSet(contractSet string) UploadOption

func WithCustomEncryptionOffset added in v0.6.0

func WithCustomEncryptionOffset(offset uint64) UploadOption

func WithCustomKey added in v0.6.0

func WithCustomKey(ec object.EncryptionKey) UploadOption

func WithMimeType added in v0.6.0

func WithMimeType(mimeType string) UploadOption

func WithObjectUserMetadata added in v1.0.3

func WithObjectUserMetadata(metadata api.ObjectUserMetadata) UploadOption

func WithPacking added in v0.6.0

func WithPacking(packing bool) UploadOption

func WithPartNumber added in v1.0.7

func WithPartNumber(partNumber int) UploadOption

func WithUploadID added in v1.0.7

func WithUploadID(uploadID string) UploadOption

type Wallet added in v1.0.6

type Wallet interface {
	WalletDiscard(ctx context.Context, txn types.Transaction) error
	WalletFund(ctx context.Context, txn *types.Transaction, amount types.Currency, useUnconfirmedTxns bool) ([]types.Hash256, []types.Transaction, error)
	WalletPrepareForm(ctx context.Context, renterAddress types.Address, renterKey types.PublicKey, renterFunds, hostCollateral types.Currency, hostKey types.PublicKey, hostSettings rhpv2.HostSettings, endHeight uint64) (txns []types.Transaction, err error)
	WalletPrepareRenew(ctx context.Context, revision types.FileContractRevision, hostAddress, renterAddress types.Address, renterKey types.PrivateKey, renterFunds, minNewCollateral, maxFundAmount types.Currency, pt rhpv3.HostPriceTable, endHeight, windowSize, expectedStorage uint64) (api.WalletPrepareRenewResponse, error)
	WalletSign(ctx context.Context, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
}

type WebhookStore added in v1.0.8

type WebhookStore interface {
	RegisterWebhook(ctx context.Context, webhook webhooks.Webhook) error
	UnregisterWebhook(ctx context.Context, webhook webhooks.Webhook) error
}

type Worker added in v1.1.0

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

A worker talks to Sia hosts to perform contract and storage operations within a renterd system.

func New

func New(cfg config.Worker, masterKey [32]byte, b Bus, l *zap.Logger) (*Worker, error)

New returns an HTTP handler that serves the worker API.

func (*Worker) GetObject added in v1.1.0

func (w *Worker) GetObject(ctx context.Context, bucket, path string, opts api.DownloadObjectOptions) (*api.GetObjectResponse, error)

func (*Worker) Handler added in v1.1.0

func (w *Worker) Handler() http.Handler

Handler returns an HTTP handler that serves the worker API.

func (*Worker) HeadObject added in v1.1.0

func (w *Worker) HeadObject(ctx context.Context, bucket, path string, opts api.HeadObjectOptions) (*api.HeadObjectResponse, error)

func (*Worker) Host added in v1.1.0

func (w *Worker) Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr string) Host

func (*Worker) Setup added in v1.1.0

func (w *Worker) Setup(ctx context.Context, apiURL, apiPassword string) error

Setup register event webhooks that enable the worker cache.

func (*Worker) Shutdown added in v1.1.0

func (w *Worker) Shutdown(ctx context.Context) error

Shutdown shuts down the worker.

func (*Worker) UploadMultipartUploadPart added in v1.1.0

func (w *Worker) UploadMultipartUploadPart(ctx context.Context, r io.Reader, bucket, path, uploadID string, partNumber int, opts api.UploadMultipartUploadPartOptions) (*api.UploadMultipartUploadPartResponse, error)

func (*Worker) UploadObject added in v1.1.0

func (w *Worker) UploadObject(ctx context.Context, r io.Reader, bucket, path string, opts api.UploadObjectOptions) (*api.UploadObjectResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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