xray

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 20 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 (
	// 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

View Source
var (
	HTTPInboundPort  = 2080
	SOCKSInboundPort = 2081
)

Local proxy ports (proxy mode). Defaults; the user can change them (SetPorts), and the choice is kept in ports.json in Kite's config folder.

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 SetPorts added in v0.24.0

func SetPorts(http, socks int) error

SetPorts changes the local proxy ports for the next connection and saves them.

func TUNAddress added in v0.11.0

func TUNAddress(n int) string

TUNAddress is the address of the n-th TUN adapter; each has its own, since adapters from earlier connections linger until Kite exits.

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"`
	Since   int64  `json:"since,omitempty"` // unix ms when the connection came up
}

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