rhp

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContractRevisionLimit is returned when a contract revision would
	// exceed the maximum revision number.
	ErrContractRevisionLimit = errors.New("max revision number reached")
	// ErrContractProofWindowStarted is returned when a contract revision is
	// attempted after the proof window has started.
	ErrContractProofWindowStarted = errors.New("proof window has started")
	// ErrContractExpired is returned when a contract revision is attempted
	// after the contract has expired.
	ErrContractExpired = errors.New("contract has expired")

	// ErrInvalidSectorLength is returned when a sector is not the correct
	// length.
	ErrInvalidSectorLength = errors.New("length of sector data must be exactly 4MiB")

	// ErrTrimOutOfBounds is returned when a trim operation exceeds the total
	// number of sectors
	ErrTrimOutOfBounds = errors.New("trim size exceeds number of sectors")
	// ErrSwapOutOfBounds is returned when one of the swap indices exceeds the
	// total number of sectors
	ErrSwapOutOfBounds = errors.New("swap index is out of bounds")
	// ErrUpdateOutOfBounds is returned when the update index exceeds the total
	// number of sectors
	ErrUpdateOutOfBounds = errors.New("update index is out of bounds")
	// ErrOffsetOutOfBounds is returned when the offset exceeds and length
	// exceed the sector size.
	ErrOffsetOutOfBounds = errors.New("update section is out of bounds")
	// ErrUpdateProofSize is returned when a proof is requested for an update
	// operation that is not a multiple of 64 bytes.
	ErrUpdateProofSize = errors.New("update section is not a multiple of the segment size")
)
View Source
var (
	// ErrTxnMissingContract is returned if the transaction set does not contain
	// any transactions or if the transaction does not contain exactly one
	// contract.
	ErrTxnMissingContract = errors.New("transaction set does not contain a file contract")
	// ErrHostInternalError is returned if the host encountered an error during
	// an RPC that doesn't need to be broadcast to the renter (e.g. insufficient
	// funds).
	ErrHostInternalError = errors.New("internal error")
	// ErrInvalidRenterSignature is returned when a contract's renter signature
	// is invalid.
	ErrInvalidRenterSignature = errors.New("invalid renter signature")
	// ErrNotAcceptingContracts is returned when the host is not accepting
	// contracts.
	ErrNotAcceptingContracts = errors.New("host is not accepting contracts")
)
View Source
var (
	// ErrContractRequired is returned when a contract is required to execute a
	// program but is not provided
	ErrContractRequired = errors.New("contract required")
)
View Source
var (
	// ErrNoPriceTable is returned if a price table is requested but the UID
	// does not exist or has expired.
	ErrNoPriceTable = errors.New("no price table found")
)

Functions

This section is empty.

Types

type AccountManager

type AccountManager interface {
	Balance(accountID rhp3.Account) (types.Currency, error)
	Credit(req accounts.FundAccountWithContract, refund bool) (balance types.Currency, err error)
	Budget(accountID rhp3.Account, amount types.Currency) (*accounts.Budget, error)
}

An AccountManager manages deposits and withdrawals for accounts.

type ChainManager

type ChainManager interface {
	TipState() consensus.State
}

A ChainManager provides access to the current state of the blockchain.

type ContractManager

type ContractManager interface {
	// Contract returns the last revision of the contract with the given ID.
	Contract(id types.FileContractID) (contracts.Contract, error)

	// Lock locks the contract with the given ID. Will wait for the given
	// duration before giving up. Unlock must be called to unlock the
	// contract.
	Lock(ctx context.Context, id types.FileContractID) (contracts.SignedRevision, error)
	// Unlock unlocks the contract with the given ID.
	Unlock(id types.FileContractID)

	// AddContract adds a new contract to the manager.
	AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, initialUsage contracts.Usage) error
	// RenewContract renews an existing contract.
	RenewContract(renewal contracts.SignedRevision, existing contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, clearingUsage, renewalUsage contracts.Usage) error
	// ReviseContract atomically revises a contract and its sector roots
	ReviseContract(contractID types.FileContractID) (*contracts.ContractUpdater, error)
}

A ContractManager manages the set of contracts that the host is currently storing data for

type RegistryManager

type RegistryManager interface {
	Get(key rhp3.RegistryKey) (rhp3.RegistryValue, error)
	Put(value rhp3.RegistryEntry, expirationHeight uint64) (rhp3.RegistryValue, error)
	Entries() (count uint64, max uint64, err error)
}

A RegistryManager manages registry entries stored in a RegistryStore.

type SessionHandler

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

A SessionHandler handles the host side of the renter-host protocol and manages renter sessions

func NewSessionHandler

func NewSessionHandler(l net.Listener, hostKey types.PrivateKey, chain ChainManager, tpool TransactionPool, wallet Wallet, accounts AccountManager, contracts ContractManager, registry RegistryManager, storage StorageManager, settings SettingsReporter, monitor rhp.DataMonitor, sessions SessionReporter, log *zap.Logger) (*SessionHandler, error)

NewSessionHandler creates a new SessionHandler

func (*SessionHandler) Close

func (sh *SessionHandler) Close() error

Close closes the session handler and stops accepting new connections.

func (*SessionHandler) HostKey

func (sh *SessionHandler) HostKey() types.UnlockKey

HostKey returns the host's ed25519 public key

func (*SessionHandler) LocalAddr

func (sh *SessionHandler) LocalAddr() string

LocalAddr returns the address the host is listening on.

func (*SessionHandler) PriceTable

func (sh *SessionHandler) PriceTable() (rhp3.HostPriceTable, error)

PriceTable returns the session handler's current price table.

func (*SessionHandler) Serve

func (sh *SessionHandler) Serve() error

Serve starts the host RPC server.

func (*SessionHandler) WebSocketHandler

func (sh *SessionHandler) WebSocketHandler() http.HandlerFunc

WebSocketHandler returns an http.Handler that upgrades the connection to a WebSocket and then passes the connection to the RHP3 host transport.

type SessionReporter added in v0.2.0

type SessionReporter interface {
	StartSession(conn *rhp.Conn, proto string, version int) (sessionID rhp.UID, end func())
	StartRPC(sessionID rhp.UID, rpc types.Specifier) (rpcID rhp.UID, end func(contracts.Usage, error))
}

SessionReporter reports session metrics

type SettingsReporter

type SettingsReporter interface {
	Settings() settings.Settings
	BandwidthLimiters() (ingress, egress *rate.Limiter)
}

A SettingsReporter reports the host's current configuration.

type StorageManager

type StorageManager interface {
	Usage() (used, total uint64, _ error)

	// LockSector locks the sector with the given root. If the sector does not
	// exist, an error is returned. Release must be called when the sector is no
	// longer needed.
	LockSector(root types.Hash256) (func() error, error)
	// Write writes a sector to persistent storage. release should only be
	// called after the contract roots have been committed to prevent the
	// sector from being deleted.
	Write(root types.Hash256, data *[rhp2.SectorSize]byte) (release func() error, _ error)
	// Read reads the sector with the given root from the manager.
	Read(root types.Hash256) (*[rhp2.SectorSize]byte, error)
	// Sync syncs the data files of changed volumes.
	Sync() error

	// AddTemporarySectors adds the given sectors to the storage manager.
	// as temporary sectors. Temporary sectors are short-lived sectors not
	// associated with a contract.
	AddTemporarySectors([]storage.TempSector) error
}

A StorageManager manages the storage of sectors on disk.

type TransactionPool

type TransactionPool interface {
	AcceptTransactionSet([]types.Transaction) error
	RecommendedFee() types.Currency
}

A TransactionPool broadcasts transactions to the network.

type Wallet

type Wallet interface {
	Address() types.Address
	FundTransaction(txn *types.Transaction, amount types.Currency) ([]types.Hash256, func(), error)
	SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
}

A Wallet manages funds and signs transactions

Jump to

Keyboard shortcuts

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