noderead

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package noderead reads a node's own earnings from inside its running container, for a provider whose account API cannot give a balance or a lifetime. It ports the web worker's app/node_read.py.

Mysterium is the case it exists for: the MystNodes cloud's earningsTotal is a trailing 30-day sum that rises and falls as days leave the window, and its per-node lifetime comes back as 0. The node itself knows both, through TequilAPI, which listens on loopback inside the container. The catalog says how to ask it, in collector.node_read: a read-only command to run in the container and the regexes that pick the node id, the unsettled balance and the lifetime total out of what it prints.

The command comes from the vendored catalog, never from a request, and only the matched groups leave this package.

Index

Constants

View Source
const MysteriumTequilAPI = "http://127.0.0.1:4050"

MysteriumTequilAPI is the native Mysterium node's TequilAPI. The catalog's native command binds it to 127.0.0.1 and leaves the port at the node's default, 4050.

View Source
const ReadTimeout = 10 * time.Second

ReadTimeout bounds one container's read, as the web worker's READ_TIMEOUT does.

Variables

View Source
var ErrNotDeclared = errors.New("the catalog declares no node_read for this service")

ErrNotDeclared means the service's catalog entry declares no usable node_read, so the caller keeps whatever it did before.

View Source
var NativeReaders = map[string]NativeOutput{
	"mysterium": func(ctx context.Context) (string, error) {
		return TequilAPIOutput(ctx, localClient, MysteriumTequilAPI)
	},
}

NativeReaders are the services whose node can be read natively, by slug. A service that declares node_read but has no entry here is not read when it runs natively.

Functions

func TequilAPIOutput

func TequilAPIOutput(ctx context.Context, client *http.Client, base string) (string, error)

TequilAPIOutput does in Go what Mysterium's node_read command does in its container, and prints the same text: the first identity from /identities, that identity's answer, then a newline and the settlement history when it can be read. A failed history read leaves the figures, as the command's `|| true` does.

Types

type NativeOutput

type NativeOutput func(ctx context.Context) (string, error)

NativeOutput produces, without a container, the text a service's node_read command prints inside one. It exists for a node Desktop runs as a native process, where the catalog's sh and wget command cannot run (no sh on Windows, no wget on a Mac). The text then goes through the same regexes as a container's.

type Output

type Output struct {
	Instance int
	Text     string
	ExitCode int
	// Err is set when the command could not be run at all.
	Err error
}

Output is what one command printed in one container.

type Reader

type Reader struct {
	Command []string
	// contains filtered or unexported fields
}

Reader is a compiled collector.node_read.

func Compile

func Compile(spec *catalog.NodeRead) (*Reader, bool)

Compile returns the reader a catalog entry declares, or false when it declares none or a malformed one: no command, or a node, balance or lifetime pattern that does not compile or has no group. The two settled sums are used only when both compile with exactly one group, as the web does.

func (*Reader) Extract

func (r *Reader) Extract(output string) (Reading, bool)

Extract picks the node's id, unsettled balance and lifetime out of the command's output, or returns false when any is missing. A lifetime below the balance is not a reading: everything waiting to settle is part of what the node ever earned.

type Reading

type Reading struct {
	// Instance is which copy of the service the container is (1 for the first).
	Instance int     `json:"instance"`
	Node     string  `json:"node,omitempty"`
	Balance  float64 `json:"balance"`
	Lifetime float64 `json:"lifetime"`
	// SettledNet and SettledFees are what the node's settlements paid to the wallet
	// and what the provider kept, in any one unit; nil when not known.
	SettledNet  *float64 `json:"settledNet,omitempty"`
	SettledFees *float64 `json:"settledFees,omitempty"`
	// Error is set, and the figures are not, when the read did not work.
	Error string `json:"error,omitempty"`
}

Reading is one node's figures, or why there are none.

func ReadAll

func ReadAll(ctx context.Context, run Runner, slug string, r *Reader) ([]Reading, error)

ReadAll returns one reading per running copy of the service: its figures when the read worked, its Error when it did not.

func ReadNative

func ReadNative(ctx context.Context, read NativeOutput, r *Reader) []Reading

ReadNative reads a natively run node through its NativeOutput: one reading, for the one process.

func (Reading) OK

func (r Reading) OK() bool

OK reports whether the reading carries figures.

type Runner

type Runner interface {
	ExecRunning(ctx context.Context, slug string, cmd []string, timeout time.Duration) ([]Output, error)
}

Runner runs a command in every running container CashPilot manages for a service. The Docker runtime implements it; a runtime with no containers answers with an error, so nothing is read.

Jump to

Keyboard shortcuts

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