ant

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 23 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

This section is empty.

Variables

This section is empty.

Functions

func MerkleRoot

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

MerkleRoot calculates merkle root of the file given in reader

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 {
	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) 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) UpdateSiad added in v1.0.2

func (a *Ant) UpdateSiad(logger *persist.Logger, siadPath string) error

UpdateSiad updates ant to use the given siad binary.

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
}

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

type JobRunner

type JobRunner struct {
	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

Jump to

Keyboard shortcuts

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