nodeagent

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package nodeagent runs xray-core on a node and keeps it aligned with the configuration the panel pushes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *config.Agent, log *slog.Logger) *Agent

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run keeps a control stream to the panel open, reconnecting with backoff for as long as the process lives.

type Counter

type Counter struct {
	Uplink   uint64
	Downlink uint64
}

type Hysteria added in v0.11.0

type Hysteria struct {
	// contains filtered or unexported fields
}

Hysteria supervises the hysteria2 process, beside the xray one rather than instead of it: a node can serve both, and the two share nothing but the fact that something has to keep them alive.

It is deliberately a separate type from Xray rather than a refactor of it. The xray path is what every existing node runs, and generalising a working supervisor to fit a second engine is a change with no upside for the nodes already out there.

func NewHysteria added in v0.11.0

func NewHysteria(binary, workDir string, log *slog.Logger) *Hysteria

func NewSingBox added in v0.12.0

func NewSingBox(binary, workDir string, log *slog.Logger) *Hysteria

NewSingBox supervises sing-box with the same machinery. The two differ only in the binary, the file name and the arguments — everything about keeping a process alive and swapping its config is identical, and duplicating it would mean fixing the next bug twice.

func (*Hysteria) Apply added in v0.11.0

func (h *Hysteria) Apply(ctx context.Context, config []byte, hash string) error

Apply writes the config and restarts, unless the config is byte-identical to what is already running — restarting on an unchanged document would drop every live connection for nothing.

func (*Hysteria) Available added in v0.11.0

func (h *Hysteria) Available() bool

Available reports whether the binary is actually installed. A node that was enrolled before hysteria2 existed has no such binary, and the honest answer to a hysteria config arriving there is an error the panel can show — not a silent no-op that looks like success.

func (*Hysteria) ConfigHash added in v0.11.0

func (h *Hysteria) ConfigHash() string

func (*Hysteria) Running added in v0.11.0

func (h *Hysteria) Running() bool

func (*Hysteria) Stop added in v0.11.0

func (h *Hysteria) Stop()

type SystemSnapshot

type SystemSnapshot struct {
	Hostname      string
	OS            string
	Arch          string
	Kernel        string
	CPUCount      int
	CPUModel      string
	TotalRAMBytes uint64
	UsedRAMBytes  uint64
	CPUUsage      float64
	LoadAvg1      float64
}

SystemSnapshot is the host telemetry the agent reports with each heartbeat.

func Snapshot

func Snapshot() SystemSnapshot

type Traffic

type Traffic struct {
	Users    map[string]*Counter
	Inbounds map[string]*Counter
}

Traffic is one measurement window read from xray's stats API.

type Xray

type Xray struct {
	// contains filtered or unexported fields
}

Xray supervises the xray-core process.

func NewXray

func NewXray(binary, workDir, apiAddr string, log *slog.Logger) *Xray

func (*Xray) Apply

func (x *Xray) Apply(ctx context.Context, config []byte, hash string) error

Apply writes a new configuration and restarts xray. The previous config is kept so a rejected document can be rolled back without contacting the panel.

func (*Xray) CollectTraffic

func (x *Xray) CollectTraffic(ctx context.Context) (*Traffic, error)

CollectTraffic reads and resets the counters, so every call returns the delta since the previous one. Reading with reset is what keeps the agent stateless.

func (*Xray) ConfigHash

func (x *Xray) ConfigHash() string

func (*Xray) LoadPersistedHash

func (x *Xray) LoadPersistedHash()

LoadPersistedHash restores the hash of the config left on disk by a previous run, so a restarted agent can tell the panel it is already up to date.

func (*Xray) Logs

func (x *Xray) Logs(n int) []string

Logs returns the most recent n log lines, oldest first.

func (*Xray) Running

func (x *Xray) Running() bool

Running reports whether a supervised process is currently alive.

func (*Xray) Start

func (x *Xray) Start(ctx context.Context) error

Start launches xray with whatever config is already on disk.

func (*Xray) StartedAt

func (x *Xray) StartedAt() time.Time

func (*Xray) Stop

func (x *Xray) Stop()

Stop terminates the process, escalating to SIGKILL if it ignores the first signal.

func (*Xray) Version

func (x *Xray) Version() string

Version reports the xray-core version, or "unknown" if the binary is missing.

Jump to

Keyboard shortcuts

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