ant

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package ant provides an abstraction for the functionality of 'ants' in the antfarm. Ants are Sia clients that have a myriad of user stories programmed as their behavior and report their successfullness at each user store.

Index

Constants

View Source
const (
	// NumPorts stores number of network ports an ant has: API, host, RPC,
	// SiaMux and SiaMux websocket port.
	NumPorts = 5
)

Variables

View Source
var (
	// Allowance is the set of allowance settings that will be used by
	// renter
	Allowance = modules.Allowance{
		Funds:       types.NewCurrency64(20e3).Mul(types.SiacoinPrecision),
		Hosts:       4,
		Period:      renterAllowancePeriod,
		RenewWindow: renterAllowancePeriod / 4,

		ExpectedStorage:    10e9,
		ExpectedUpload:     2e9 / renterAllowancePeriod,
		ExpectedDownload:   1e12 / renterAllowancePeriod,
		ExpectedRedundancy: 3.0,
		MaxPeriodChurn:     2.5e9,
	}
)

Functions

func GetAddr added in v1.1.2

func GetAddr() (string, error)

GetAddr returns a free random port. Address is returned in the format of ":port". It seems that checking a free port by Golang net.Listen() or by net.Dial()/DialTimeout() affects OS operations on the checked port and it lowered stability of starting siad or Antfarm services. So on Linux and in Gitlab CI we check for free ports via ss command line utility which keeps Antfarm much more stable.

func GetAddrs added in v1.1.2

func GetAddrs(n int) ([]string, error)

GetAddrs returns n free listening ports. Addresses are returned in the format of ":port".

func MerkleRoot

func MerkleRoot(r io.Reader) (h crypto.Hash, err error)

MerkleRoot calculates merkle root of the file given in reader

func NameGeneric added in v1.1.0

func NameGeneric(i int) string

NameGeneric returns standardized ant name of generic ant type by the given ant index.

func NameHost added in v1.1.0

func NameHost(i int) string

NameHost returns standardized ant name of host ant type by the given ant index.

func NameMiner added in v1.1.0

func NameMiner(i int) string

NameMiner returns standardized ant name of miner ant type by the given ant index.

func NameRenter added in v1.1.0

func NameRenter(i int) string

NameRenter returns standardized ant name of renter ant type by the given ant index.

func SprintJSON added in v1.0.2

func SprintJSON(v interface{}) (string, error)

SprintJSON is a wrapper for json.MarshalIndent

Types

type Ant

type Ant struct {
	StaticClient *client.Client `json:"-"`

	APIAddr string
	RPCAddr string

	Config AntConfig

	Jr *JobRunner

	// A variable to track which blocks + heights the sync detector has seen
	// for this ant. The map will just keep growing, but it shouldn't take up a
	// prohibitive amount of space.
	SeenBlocks map[types.BlockHeight]types.BlockID `json:"-"`
	// contains filtered or unexported fields
}

An Ant is a Sia Client programmed with network user stories. It executes these user stories and reports on their successfulness.

func New

func New(antsSyncWG *sync.WaitGroup, logger *persist.Logger, config AntConfig) (*Ant, error)

New creates a new Ant using the configuration passed through `config`.

func (*Ant) BlockHeight

func (a *Ant) BlockHeight() types.BlockHeight

BlockHeight returns the highest block height seen by the ant.

func (*Ant) Close

func (a *Ant) Close() error

Close releases all resources created by the ant, including the Siad subprocess.

func (*Ant) HasRenterTypeJob

func (a *Ant) HasRenterTypeJob() bool

HasRenterTypeJob returns true if the ant has renter type of job (renter or autoRenter)

func (*Ant) PrintDebugInfo added in v1.1.0

func (a *Ant) PrintDebugInfo(contractInfo, hostInfo, renterInfo bool) error

PrintDebugInfo prints out helpful debug information, arguments define what is printed.

func (*Ant) StartJob

func (a *Ant) StartJob(antsSyncWG *sync.WaitGroup, job string, args ...interface{}) error

StartJob starts the job indicated by `job` after an ant has been initialized. Arguments are passed to the job using args.

func (*Ant) StartSiad added in v1.1.0

func (a *Ant) StartSiad(siadPath string) error

StartSiad starts ant using the given siad binary on the previously closed ant.

func (*Ant) UpdateSiad added in v1.0.2

func (a *Ant) UpdateSiad(siadPath string) error

UpdateSiad updates ant to use the given siad binary.

func (*Ant) WaitConfirmedSiacoinBalance added in v1.1.0

func (a *Ant) WaitConfirmedSiacoinBalance(cmpOp BalanceComparisonOperator, value types.Currency, timeout time.Duration) error

WaitConfirmedSiacoinBalance waits until ant wallet confirmed Siacoins meet comparison condition.

func (*Ant) WaitForBlockHeight added in v1.1.0

func (a *Ant) WaitForBlockHeight(blockHeight types.BlockHeight, timeout, frequency time.Duration) error

WaitForBlockHeight blocks until the ant reaches the given block height or the timeout is reached.

func (*Ant) WaitForContractsToRenew added in v1.1.0

func (a *Ant) WaitForContractsToRenew(contractsCount int, timeout time.Duration) error

WaitForContractsToRenew blocks until renter contracts are renewed.

func (*Ant) WaitForRenterWorkersPriceTableUpdatesAndCooldown added in v1.1.2

func (a *Ant) WaitForRenterWorkersPriceTableUpdatesAndCooldown(priceTableUpdateTimeout, cooldownTimeout time.Duration) error

WaitForRenterWorkersPriceTableUpdatesAndCooldown blocks until renter workers price tables are updated and none of renter workers are on cooldown.

func (*Ant) WalletAddress

func (a *Ant) WalletAddress() (*types.UnlockHash, error)

WalletAddress returns a wallet address that this ant can receive coins on.

type AntConfig

type AntConfig struct {
	SiadConfig

	Name            string `json:",omitempty"`
	Jobs            []string
	DesiredCurrency uint64

	InitialWalletSeed string
}

AntConfig represents a configuration object passed to New(), used to configure a newly created Sia Ant.

type BalanceComparisonOperator added in v1.1.0

type BalanceComparisonOperator string

BalanceComparisonOperator defines type for comparison operators enum

const (
	BalanceLess           BalanceComparisonOperator = "less then"
	BalanceLessOrEqual    BalanceComparisonOperator = "less then or equal"
	BalanceEquals         BalanceComparisonOperator = "equal"
	BalanceGreaterOrEqual BalanceComparisonOperator = "greater then or equal"
	BalanceGreater        BalanceComparisonOperator = "greater then"
)

BalanceComparisonOperator constants define values for balance comparison operators enum

type JobRunner

type JobRunner struct {
	StaticWalletSeed string

	StaticTG threadgroup.ThreadGroup
	// contains filtered or unexported fields
}

A JobRunner is used to start up jobs on the running Sia node.

func (*JobRunner) NewRenterJob

func (j *JobRunner) NewRenterJob() RenterJob

NewRenterJob returns new renter job

func (*JobRunner) Stop

func (j *JobRunner) Stop() error

Stop signals all running jobs to stop and blocks until the jobs have finished stopping.

func (*JobRunner) WaitForRenterUploadReady

func (j *JobRunner) WaitForRenterUploadReady() error

WaitForRenterUploadReady waits for renter upload ready with default timeout, data pieces and parity pieces if the ant has renter job. If the ant doesn't have renter job, it returns an error.

type RenterFile

type RenterFile struct {
	MerkleRoot crypto.Hash
	SourceFile string
}

RenterFile stores the location and checksum of a file active on the renter.

type RenterJob

type RenterJob struct {
	Files []RenterFile
	// contains filtered or unexported fields
}

RenterJob contains statefulness that is used to drive the renter. Most importantly, it contains a list of files that the renter is currently uploading to the network.

func (*RenterJob) Download

func (r *RenterJob) Download(siaPath modules.SiaPath, destPath string) error

Download will download the given file from the network to the given destination path.

func (*RenterJob) Upload

func (r *RenterJob) Upload(fileSize uint64) (siaPath modules.SiaPath, err error)

Upload will upload a file with given size to the network.

type SiadConfig

type SiadConfig struct {
	APIAddr                       string
	APIPassword                   string
	DataDir                       string
	HostAddr                      string
	RPCAddr                       string
	SiadPath                      string
	SiaMuxAddr                    string
	SiaMuxWsAddr                  string
	AllowHostLocalNetAddress      bool
	RenterDisableIPViolationCheck bool
}

SiadConfig contains the necessary config information to create a new siad instance

type Type added in v1.1.0

type Type string

Type defines type for ant Type enum

const (
	TypeHost    Type = "Host"
	TypeMiner   Type = "Miner"
	TypeRenter  Type = "Renter"
	TypeGeneric Type = "Generic"
)

Type constants define values for ant Type enum

Jump to

Keyboard shortcuts

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