fahapi

package module
v0.0.0-...-7267c4f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 14 Imported by: 1

README

GoDoc

Folding@home client API wrapper for Go

package main

import "github.com/MakotoE/go-fahapi"

func main() {
	api, err := fahapi.Dial(fahapi.DefaultAddr)
	if err != nil {
		panic(err)
	}
	defer api.Close()

	if err := api.PauseAll(); err != nil {
		panic(err)
	}

	if err := api.UnpauseAll(); err != nil {
		panic(err)
	}
}

Prefer Rust?

Documentation

Overview

Folding@home client API wrapper for Go

Example
api, err := Dial(DefaultAddr)
if err != nil {
	panic(err)
}
defer api.Close()

if err := api.PauseAll(); err != nil {
	panic(err)
}

if err := api.UnpauseAll(); err != nil {
	panic(err)
}
Output:

Index

Examples

Constants

View Source
const (
	LogUpdatesStart   = LogUpdatesArg("start")
	LogUpdatesRestart = LogUpdatesArg("restart")
	LogUpdatesStop    = LogUpdatesArg("stop")
)

Variables

View Source
var DefaultAddr = &net.TCPAddr{Port: 36330}

DefaultAddr is the default TCP address of the FAH client.

Functions

func ParsePyONString

func ParsePyONString(b []byte) (string, error)

func UnmarshalPyON

func UnmarshalPyON(b []byte, dst interface{}) error

Types

type API

type API struct {
	*Connection
	// contains filtered or unexported fields
}

API contains the client connection. Use Dial() to get a new instance, and api.Close() to close the connection.

func Dial

func Dial(addr *net.TCPAddr) (*API, error)

Dial connects to your FAH client. DefaultAddr is the default client address.

func (*API) AlwaysOn

func (a *API) AlwaysOn(slot int) error

AlwaysOn sets a slot to be always on. (Not sure if this does anything at all.)

func (*API) Configured

func (a *API) Configured() (bool, error)

Configured returns true if the client has set a user, team or passkey.

func (*API) DoCycle

func (a *API) DoCycle() error

DoCycle runs one client cycle.

func (*API) DownloadCore

func (a *API) DownloadCore(coreType string, url *url.URL) error

DownloadCore downloads a core. NOT TESTED.

func (*API) Finish

func (a *API) Finish(slot int) error

Finish pauses a slot when its current work unit is completed. Deprecated: use FinishSlot().

func (*API) FinishAll

func (a *API) FinishAll() error

FinishAll pauses all slots one-by-one when their current work unit is completed.

func (*API) FinishSlot

func (a *API) FinishSlot(slot int) error

FinishSlot pauses a slot when its current work unit is completed.

func (*API) Help

func (a *API) Help() (string, error)

Help returns a listing of the FAH API commands.

func (*API) Info

func (a *API) Info() ([][]interface{}, error)

Info returns FAH build and machine info. See InfoStruct().

func (*API) InfoStruct

func (a *API) InfoStruct(dst *Info) error

InfoStruct converts Info() data into a structure. Consider this interface to be very unstable.

func (*API) LogUpdates

func (a *API) LogUpdates(arg LogUpdatesArg) (string, error)

LogUpdates enables or disables log updates. Returns current log.

func (*API) NumSlots

func (a *API) NumSlots() (int, error)

NumSlots returns the number of slots.

func (*API) OnIdle

func (a *API) OnIdle(slot int) error

OnIdle sets a slot to run only when idle.

func (*API) OnIdleAll

func (a *API) OnIdleAll() error

OnIdle sets all slots to run only when idle.

func (*API) OptionsGet

func (a *API) OptionsGet(dst *Options) error

OptionsGet returns the FAH client options.

func (*API) OptionsSet

func (a *API) OptionsSet(key string, value interface{}) error

OptionsSet sets an option. value argument is turned into a string using fmt.Sprintf().

func (*API) PPD

func (a *API) PPD() (float64, error)

PPD returns the total estimated points per day for all slots.

func (*API) PauseAll

func (a *API) PauseAll() error

PauseAll pauses all slots.

func (*API) PauseSlot

func (a *API) PauseSlot(slot int) error

PauseSlot pauses a slot.

func (*API) QueueInfo

func (a *API) QueueInfo() ([]SlotQueueInfo, error)

QueueInfo returns info about the current work unit.

func (*API) RequestID

func (a *API) RequestID() error

RequestID requests an ID from the assignment server.

func (*API) RequestWS

func (a *API) RequestWS() error

RequestWS requests work server assignment from the assignment server.

func (*API) Screensaver

func (a *API) Screensaver() error

Screensaver unpauses all slots which are paused waiting for a screensaver and pause them again on disconnect.

func (*API) Shutdown

func (a *API) Shutdown() error

Shutdown ends all FAH processes.

func (*API) SimulationInfo

func (a *API) SimulationInfo(slot int, dst *SimulationInfo) error

SimulationInfo returns the simulation information for a slot.

func (*API) SlotDelete

func (a *API) SlotDelete(slot int) error

SlotDelete deletes a slot.

func (*API) SlotInfo

func (a *API) SlotInfo() ([]SlotInfo, error)

SlotInfo returns information about each slot.

func (*API) SlotOptionsGet

func (a *API) SlotOptionsGet(slot int, dst *SlotOptions) error

func (*API) SlotOptionsSet

func (a *API) SlotOptionsSet(slot int, key string, value interface{}) error

func (*API) UnpauseAll

func (a *API) UnpauseAll() error

UnpauseAll unpauses all slots.

func (*API) UnpauseSlot

func (a *API) UnpauseSlot(slot int) error

UnpauseSlot unpauses a slot.

func (*API) Uptime

func (a *API) Uptime() (FAHDuration, error)

Uptime returns FAH uptime.

func (*API) WaitForUnits

func (a *API) WaitForUnits() error

WaitForUnits blocks until all slots are paused.

type Connection

type Connection struct {
	*net.TCPConn
	Addr net.TCPAddr // Reconnects to this address on disconnection.
}

Connection holds the TCP connection to the FAH client. None of its methods are goroutine-safe.

func DialConnection

func DialConnection(addr *net.TCPAddr) (*Connection, error)

func (*Connection) Exec

func (c *Connection) Exec(command string, buffer *bytes.Buffer) error

Exec executes a command on the FAH client and writes the response to buffer.

func (*Connection) ExecEval

func (c *Connection) ExecEval(command string, buffer *bytes.Buffer) error

ExecEval executes commands which do not return a trailing newline.

type FAHDuration

type FAHDuration time.Duration

FAHDuration may be "unknowntime", which can be checked by calling duration.UnknownTime().

func ParseFAHDuration

func ParseFAHDuration(s string) (FAHDuration, error)

func (FAHDuration) String

func (f FAHDuration) String() string

func (FAHDuration) UnknownTime

func (f FAHDuration) UnknownTime() bool

func (*FAHDuration) UnmarshalJSON

func (f *FAHDuration) UnmarshalJSON(b []byte) error

type FAHTime

type FAHTime time.Time

FAHTime can be invalid, which can be checked with time.Invalid().

func ParseFAHTime

func ParseFAHTime(s string) (FAHTime, error)

func (FAHTime) Invalid

func (t FAHTime) Invalid() bool

func (FAHTime) String

func (t FAHTime) String() string

func (*FAHTime) UnmarshalJSON

func (t *FAHTime) UnmarshalJSON(b []byte) error

type Info

type Info struct {
	FAHClient struct {
		Version   string
		Author    string
		Copyright string
		Homepage  string
		Date      string
		Time      string
		Revision  string
		Branch    string
		Compiler  string
		Options   string
		Platform  string
		Bits      string
		Mode      string
		Args      string
		Config    string
	}
	CBang struct {
		Date     string
		Time     string
		Revision string
		Branch   string
		Compiler string
		Options  string
		Platform string
		Bits     string
		Mode     string
	}
	System struct {
		CPU        string
		CPUID      string
		CPUs       StringInt
		Memory     string
		FreeMemory string
		Threads    string
		OSVersion  string
		HasBattery string
		OnBattery  string
		UTCOffset  string
		PID        string
		CWD        string
		OS         string
		OSArch     string
		GPUs       StringInt
	}
	LibFAH struct {
		Date     string
		Time     string
		Revision string
		Branch   string
		Compiler string
		Options  string
		Platform string
		Bits     string
		Mode     string
	}
}

func (*Info) FromSlice

func (i *Info) FromSlice(src [][]interface{}) error

type LogUpdatesArg

type LogUpdatesArg string

type Options

type Options struct {
	Allow                  string     `json:"allow"`
	CaptureDirectory       string     `json:"capture-directory"`
	CaptureOnError         StringBool `json:"capture-on-error"`
	CapturePackets         StringBool `json:"capture-packets"`
	CaptureRequests        StringBool `json:"capture-requests"`
	CaptureResponses       StringBool `json:"capture-responses"`
	CaptureSockets         StringBool `json:"capture-sockets"`
	Cause                  string     `json:"cause"`
	CertificateFile        string     `json:"certificate-file"`
	Checkpoint             StringInt  `json:"checkpoint"`
	Child                  StringBool `json:"child"`
	ClientSubtype          string     `json:"client-subtype"`
	ClientThreads          StringInt  `json:"client-threads"`
	ClientType             string     `json:"client-type"`
	CommandAddress         string     `json:"command-address"`
	CommandAllowNoPass     string     `json:"command-allow-no-pass"`
	Deny                   string     `json:"deny"`
	CommandDenyNoPass      string     `json:"command-deny-no-pass"`
	CommandEnable          StringBool `json:"command-enable"`
	CommandPort            StringInt  `json:"command-port"`
	ConfigRotate           StringBool `json:"config-rotate"`
	ConfigRotateDir        string     `json:"config-rotate-dir"`
	ConfigRotateMax        StringInt  `json:"config-rotate-max"`
	ConnectionTimeout      StringInt  `json:"connection-timeout"`
	CorePriority           string     `json:"core-priority"`
	CpuSpecies             string     `json:"cpu-species"`
	CpuType                string     `json:"cpu-type"`
	CpuUsage               StringInt  `json:"cpu-usage"`
	Cpus                   StringInt  `json:"cpus"`
	CrlFile                string     `json:"crl-file"`
	CudaIndex              string     `json:"cuda-index"`
	CycleRate              StringInt  `json:"cycle-rate"`
	Cycles                 StringInt  `json:"cycles"`
	Daemon                 StringBool `json:"daemon"`
	DebugSockets           StringBool `json:"debug-sockets"`
	DisableSleepWhenActive StringBool `json:"disable-sleep-when-active"`
	DisableViz             StringBool `json:"disable-viz"`
	DumpAfterDeadline      StringBool `json:"dump-after-deadline"`
	ExceptionLocations     StringBool `json:"exception-locations"`
	ExitWhenDone           StringBool `json:"exit-when-done"`
	ExtraCoreArgs          string     `json:"extra-core-args"`
	FoldAnon               StringBool `json:"fold-anon"`
	Gpu                    StringBool `json:"gpu"`
	GpuIndex               string     `json:"gpu-index"`
	GpuUsage               StringInt  `json:"gpu-usage"`
	GuiEnabled             StringBool `json:"gui-enabled"`
	HttpAddresses          string     `json:"http-addresses"`
	HttpsAddresses         string     `json:"https-addresses"`
	Idle                   StringBool `json:"idle"`
	Log                    string     `json:"log"`
	LogColor               StringBool `json:"log-color"`
	LogCrlf                StringBool `json:"log-crlf"`
	LogDate                StringBool `json:"log-date"`
	LogDatePeriodically    StringInt  `json:"log-date-periodically"`
	LogDomain              StringBool `json:"log-domain"`
	LogDomainLevels        string     `json:"log-domain-levels"`
	LogHeader              StringBool `json:"log-header"`
	LogLevel               StringBool `json:"log-level"`
	LogNoInfoHeader        StringBool `json:"log-no-info-header"`
	LogRedirect            StringBool `json:"log-redirect"`
	LogRotate              StringBool `json:"log-rotate"`
	LogRotateDir           string     `json:"log-rotate-dir"`
	LogRotateMax           StringInt  `json:"log-rotate-max"`
	LogShortLevel          StringBool `json:"log-short-level"`
	LogSimpleDomains       StringBool `json:"log-simple-domains"`
	LogThreadId            StringBool `json:"log-thread-id"`
	LogThreadPrefix        StringBool `json:"log-thread-prefix"`
	LogTime                StringBool `json:"log-time"`
	LogToScreen            StringBool `json:"log-to-screen"`
	LogTruncate            StringBool `json:"log-truncate"`
	MachineId              StringInt  `json:"machine-id"`
	MaxConnectTime         StringInt  `json:"max-connect-time"`
	MaxConnections         StringInt  `json:"max-connections"`
	MaxPacketSize          string     `json:"max-packet-size"`
	MaxQueue               StringInt  `json:"max-queue"`
	MaxRequestLength       StringInt  `json:"max-request-length"`
	MaxShutdownWait        StringInt  `json:"max-shutdown-wait"`
	MaxSlotErrors          StringInt  `json:"max-slot-errors"`
	MaxUnitErrors          StringInt  `json:"max-unit-errors"`
	MaxUnits               StringInt  `json:"max-units"`
	Memory                 string     `json:"memory"`
	MinConnectTime         StringInt  `json:"min-connect-time"`
	NextUnitPercentage     StringInt  `json:"next-unit-percentage"`
	Priority               string     `json:"priority"`
	NoAssembly             StringBool `json:"no-assembly"`
	OpenWebControl         StringBool `json:"open-web-control"`
	OpenclIndex            string     `json:"opencl-index"`
	OsSpecies              string     `json:"os-species"`
	OsType                 string     `json:"os-type"`
	Passkey                string     `json:"passkey"`
	Password               string     `json:"password"`
	PauseOnBattery         StringBool `json:"pause-on-battery"`
	PauseOnStart           StringBool `json:"pause-on-start"`
	Paused                 StringBool `json:"paused"`
	Pid                    StringBool `json:"pid"`
	PidFile                string     `json:"pid-file"`
	Power                  Power      `json:"power"`
	PrivateKeyFile         string     `json:"private-key-file"`
	ProjectKey             StringInt  `json:"project-key"`
	Proxy                  string     `json:"proxy"`
	ProxyEnable            StringBool `json:"proxy-enable"`
	ProxyPass              string     `json:"proxy-pass"`
	ProxyUser              string     `json:"proxy-user"`
	Respawn                StringBool `json:"respawn"`
	Service                StringBool `json:"service"`
	ServiceDescription     string     `json:"service-description"`
	ServiceRestart         StringBool `json:"service-restart"`
	ServiceRestartDelay    StringInt  `json:"service-restart-delay"`
	SessionCookie          string     `json:"session-cookie"`
	SessionLifetime        StringInt  `json:"session-lifetime"`
	SessionTimeout         StringInt  `json:"session-timeout"`
	Smp                    StringBool `json:"smp"`
	StackTraces            StringBool `json:"stack-traces"`
	StallDetectionEnabled  StringBool `json:"stall-detection-enabled"`
	StallPercent           StringInt  `json:"stall-percent"`
	StallTimeout           StringInt  `json:"stall-timeout"`
	Team                   StringInt  `json:"team"`
	User                   string     `json:"user"`
	Verbosity              StringInt  `json:"verbosity"`
	WebAllow               string     `json:"web-allow"`
	WebDeny                string     `json:"web-deny"`
	WebEnable              StringBool `json:"web-enable"`
}

type Power

type Power string
const (
	PowerNull   Power = ""
	PowerLight  Power = "LIGHT"
	PowerMedium Power = "MEDIUM"
	PowerFull   Power = "FULL"
)

func NewPower

func NewPower(s string) (Power, error)

func (*Power) UnmarshalJSON

func (p *Power) UnmarshalJSON(b []byte) error

type SimulationInfo

type SimulationInfo struct {
	User            string  `json:"user"`
	Team            string  `json:"team"`
	Project         int     `json:"project"`
	Run             int     `json:"run"`
	Clone           int     `json:"clone"`
	Gen             int     `json:"gen"`
	CoreType        int     `json:"core_type"`
	Core            string  `json:"core"`
	TotalIterations int     `json:"total_iterations"`
	IterationsDone  int     `json:"iterations_done"`
	Energy          int     `json:"energy"`
	Temperature     int     `json:"temperature"`
	StartTime       FAHTime `json:"start_time"`
	Timeout         int     `json:"timeout"`
	Deadline        int     `json:"deadline"`
	ETA             int     `json:"eta"`
	Progress        float64 `json:"progress"`
	Slot            int     `json:"slot"`
}

type SlotInfo

type SlotInfo struct {
	ID          string                 `json:"id"`
	Status      string                 `json:"status"`
	Description string                 `json:"description"`
	Options     map[string]interface{} `json:"options"`
	Reason      string                 `json:"reason"`
	Idle        bool                   `json:"idle"`
}

type SlotOptions

type SlotOptions struct {
	MachineID string     `json:"machine-id"`
	Paused    StringBool `json:"paused"`
}

type SlotQueueInfo

type SlotQueueInfo struct {
	ID             string      `json:"id"`
	State          string      `json:"state"`
	Error          string      `json:"error"`
	Project        int         `json:"project"`
	Run            int         `json:"run"`
	Clone          int         `json:"clone"`
	Gen            int         `json:"gen"`
	Core           string      `json:"core"`
	Unit           string      `json:"unit"`
	PercentDone    string      `json:"percentdone"`
	ETA            FAHDuration `json:"eta"`
	PPD            StringInt   `json:"ppd"`
	CreditEstimate StringInt   `json:"creditestimate"`
	WaitingOn      string      `json:"waitingon"`
	NextAttempt    FAHDuration `json:"nextattempt"`
	TimeRemaining  FAHDuration `json:"timeremaining"`
	TotalFrames    int         `json:"totalframes"`
	FramesDone     int         `json:"framesdone"`
	Assigned       FAHTime     `json:"assigned"`
	Timeout        FAHTime     `json:"timeout"`
	Deadline       FAHTime     `json:"deadline"`
	WS             string      `json:"ws"`
	CS             string      `json:"cs"`
	Attempts       int         `json:"attempts"`
	Slot           string      `json:"slot"`
	TPF            FAHDuration `json:"tpf"`
	BaseCredit     StringInt   `json:"basecredit"`
}

type StringBool

type StringBool bool

func (*StringBool) UnmarshalJSON

func (s *StringBool) UnmarshalJSON(b []byte) error

type StringInt

type StringInt int

func (*StringInt) FromString

func (i *StringInt) FromString(s string) error

func (*StringInt) UnmarshalJSON

func (i *StringInt) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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