xray

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package xray runs xray-core (github.com/xtls/xray-core) as an in-process Go library: it builds a config from a server profile and starts/stops an xray-core instance, in proxy mode (local HTTP/SOCKS) or TUN mode.

Index

Constants

View Source
const (
	HTTPInboundPort  = 2080
	SOCKSInboundPort = 2081

	// TUN adapter settings. Each connection gets its own 172.19.N.1/30
	// (see manager.go); the kill switch allows all of 172.19.0.0/16.
	TUNMask = "255.255.255.252"
	TUNDNS  = "1.1.1.1"
)

Variables

This section is empty.

Functions

func CoreVersion added in v0.7.0

func CoreVersion() string

CoreVersion returns the embedded xray-core version, for the About panel. xray-core doesn't expose a runtime version constant, so this reads the resolved module version straight from the Go module graph instead.

func LogFilePath

func LogFilePath() string

LogFilePath returns where xray-core's own error log is written.

func TUNAddress added in v0.11.0

func TUNAddress(n int) string

TUNAddress is the adapter address for the n-th TUN connection. A new one each time, since a lingering adapter from a previous connection may still hold the old address.

Types

type Manager

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

Manager owns the lifecycle of a single running xray-core instance.

func NewManager

func NewManager() *Manager

func (*Manager) Restart

func (m *Manager) Restart(server profile.Server, mode Mode) error

func (*Manager) Start

func (m *Manager) Start(server profile.Server, mode Mode) error

func (*Manager) Status

func (m *Manager) Status() Status

func (*Manager) Stop

func (m *Manager) Stop() error

func (*Manager) Traffic

func (m *Manager) Traffic() Traffic

Traffic reads the "proxy" outbound's cumulative byte counters from xray-core's stats.Manager (enabled via the policy block in config.go).

type Mode

type Mode = string

Mode selects what xray-core listens on: a local HTTP/SOCKS proxy ("proxy") or a TUN adapter capturing all system traffic ("tun").

const (
	ModeProxy Mode = "proxy"
	ModeTUN   Mode = "tun"
)

type State

type State string
const (
	StateStopped  State = "stopped"
	StateStarting State = "starting"
	StateRunning  State = "running"
	StateError    State = "error"
)

type Status

type Status struct {
	State   State  `json:"state"`
	Server  string `json:"server,omitempty"`
	Mode    Mode   `json:"mode,omitempty"`
	Message string `json:"message,omitempty"`
}

type Traffic

type Traffic struct {
	Uplink   int64 `json:"uplink"`
	Downlink int64 `json:"downlink"`
}

Jump to

Keyboard shortcuts

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