nodeagent

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 23 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 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