utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRouteToHost         = errors.New("no route to host")
	ErrNoSuchHost            = errors.New("no such host")
	ErrConnectionRefused     = errors.New("connection refused")
	ErrConnectionTimedOut    = errors.New("connection timed out")
	ErrConnectionResetByPeer = errors.New("connection reset by peer")
	ErrIOTimeout             = errors.New("i/o timeout")
)

Common i/o related errors

View Source
var (

	// ErrHostTooManyAddresses is returned by the worker API when a host has
	// more than two addresses of the same type.
	ErrHostTooManyAddresses = errors.New("host has more than two addresses, or two of the same type")
)

Functions

func AddressesToSubnets added in v1.1.0

func AddressesToSubnets(resolvedAddresses []string) ([]string, error)

func Auth added in v1.1.0

func Auth(password string, unauthenticatedDownloads bool) func(http.Handler) http.Handler

func DoRequest added in v1.1.0

func DoRequest(req *http.Request, resp interface{}) (http.Header, int, error)

func HumanReadableSize added in v1.1.0

func HumanReadableSize(b int) string

func IsErr

func IsErr(err error, target error) bool

IsErr can be used to compare an error to a target and also works when used on errors that haven't been wrapped since it will fall back to a string comparison. Useful to check errors returned over the network.

func IsSynced added in v1.1.0

func IsSynced(b types.Block) bool

func IsVersion added in v1.1.0

func IsVersion(str string) bool

IsVersion returns whether str is a valid release version with no -rc component.

func ListenTCP added in v1.1.0

func ListenTCP(addr string, logger *zap.Logger) (net.Listener, error)

func OpenBrowser added in v1.1.0

func OpenBrowser(url string) error

func ResolveHostIP added in v1.0.8

func ResolveHostIP(ctx context.Context, hostIP string) (ips []string, private bool, _ error)

func VersionCmp added in v1.1.0

func VersionCmp(a, b string) int

VersionCmp returns an int indicating the difference between a and b. It follows the convention of bytes.Compare and big.Cmp:

-1 if a <  b
 0 if a == b
+1 if a >  b

One important quirk is that "1.1.0" is considered newer than "1.1", despite being numerically equal.

func WrapErr added in v1.1.0

func WrapErr(ctx context.Context, fnName string, err *error)

WrapErr can be used to defer wrapping an error which is then decorated with the provided function name. If the context contains a cause error, it will also be included in the wrapping.

Types

type AccountsKey added in v1.1.0

type AccountsKey types.PrivateKey

func (*AccountsKey) DeriveAccountKey added in v1.1.0

func (key *AccountsKey) DeriveAccountKey(hk types.PublicKey) types.PrivateKey

DeriveAccountKey derives an account plus key for a given host and worker. Each worker has its own account for a given host. That makes concurrency around keeping track of an accounts balance and refilling it a lot easier in a multi-worker setup.

type DataPoints added in v1.1.0

type DataPoints struct {
	stats.Float64Data
	// contains filtered or unexported fields
}

func NewDataPoints added in v1.1.0

func NewDataPoints(halfLife time.Duration) *DataPoints

func (*DataPoints) Average added in v1.1.0

func (a *DataPoints) Average() float64

func (*DataPoints) P90 added in v1.1.0

func (a *DataPoints) P90() float64

func (*DataPoints) Recompute added in v1.1.0

func (a *DataPoints) Recompute()

func (*DataPoints) Track added in v1.1.0

func (a *DataPoints) Track(p float64)

type Float64Data added in v1.1.0

type Float64Data = stats.Float64Data

type MasterKey added in v1.1.0

type MasterKey [32]byte

func (*MasterKey) DeriveAccountsKey added in v1.1.0

func (key *MasterKey) DeriveAccountsKey(workerID string) AccountsKey

DeriveAccountsKey derives an accounts key from a masterkey which is used to derive individual account keys from.

func (*MasterKey) DeriveContractKey added in v1.1.0

func (key *MasterKey) DeriveContractKey(hostKey types.PublicKey) types.PrivateKey

DeriveContractKey derives a contract key from a masterkey which is used to form, renew and revise contracts.

type TreeMux added in v1.0.8

type TreeMux struct {
	Handler http.Handler
	Sub     map[string]TreeMux
}

func (TreeMux) ServeHTTP added in v1.0.8

func (t TreeMux) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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