xray

package
v2.8.9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package xray provides integration with the Xray proxy core. It includes API client functionality, configuration management, traffic monitoring, and process control for Xray instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAccessLogPath

func GetAccessLogPath() (string, error)

GetAccessLogPath reads the Xray config and returns the access log file path.

func GetAccessPersistentLogPath

func GetAccessPersistentLogPath() string

GetAccessPersistentLogPath returns the path to the persistent access log file.

func GetAccessPersistentPrevLogPath

func GetAccessPersistentPrevLogPath() string

GetAccessPersistentPrevLogPath returns the path to the previous persistent access log file.

func GetBinaryName

func GetBinaryName() string

GetBinaryName returns the Xray binary filename for the current OS and architecture.

func GetBinaryPath

func GetBinaryPath() string

GetBinaryPath returns the full path to the Xray binary executable.

func GetConfigPath

func GetConfigPath() string

GetConfigPath returns the path to the Xray configuration file in the binary folder.

func GetGeoipPath

func GetGeoipPath() string

GetGeoipPath returns the path to the geoip data file used by Xray.

func GetGeositePath

func GetGeositePath() string

GetGeositePath returns the path to the geosite data file used by Xray.

func GetIPLimitBannedLogPath

func GetIPLimitBannedLogPath() string

GetIPLimitBannedLogPath returns the path to the banned IP log file.

func GetIPLimitBannedPrevLogPath

func GetIPLimitBannedPrevLogPath() string

GetIPLimitBannedPrevLogPath returns the path to the previous banned IP log file.

func GetIPLimitLogPath

func GetIPLimitLogPath() string

GetIPLimitLogPath returns the path to the IP limit log file.

Types

type ClientTraffic

type ClientTraffic struct {
	Id         int    `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
	InboundId  int    `json:"inboundId" form:"inboundId"`
	Enable     bool   `json:"enable" form:"enable"`
	Email      string `json:"email" form:"email" gorm:"unique"`
	UUID       string `json:"uuid" form:"uuid" gorm:"-"`
	SubId      string `json:"subId" form:"subId" gorm:"-"`
	Up         int64  `json:"up" form:"up"`
	Down       int64  `json:"down" form:"down"`
	AllTime    int64  `json:"allTime" form:"allTime"`
	ExpiryTime int64  `json:"expiryTime" form:"expiryTime"`
	Total      int64  `json:"total" form:"total"`
	Reset      int    `json:"reset" form:"reset" gorm:"default:0"`
	LastOnline int64  `json:"lastOnline" form:"lastOnline" gorm:"default:0"`
}

ClientTraffic represents traffic statistics and limits for a specific client. It tracks upload/download usage, expiry times, and online status for inbound clients.

type Config

type Config struct {
	LogConfig        json_util.RawMessage `json:"log"`
	RouterConfig     json_util.RawMessage `json:"routing"`
	DNSConfig        json_util.RawMessage `json:"dns"`
	InboundConfigs   []InboundConfig      `json:"inbounds"`
	OutboundConfigs  json_util.RawMessage `json:"outbounds"`
	Transport        json_util.RawMessage `json:"transport"`
	Policy           json_util.RawMessage `json:"policy"`
	API              json_util.RawMessage `json:"api"`
	Stats            json_util.RawMessage `json:"stats"`
	Reverse          json_util.RawMessage `json:"reverse"`
	FakeDNS          json_util.RawMessage `json:"fakedns"`
	Observatory      json_util.RawMessage `json:"observatory"`
	BurstObservatory json_util.RawMessage `json:"burstObservatory"`
	Metrics          json_util.RawMessage `json:"metrics"`
}

Config represents the complete Xray configuration structure. It contains all sections of an Xray config file including inbounds, outbounds, routing, etc.

func (*Config) Equals

func (c *Config) Equals(other *Config) bool

Equals compares two Config instances for deep equality.

type InboundConfig

type InboundConfig struct {
	Listen         json_util.RawMessage `json:"listen"` // listen cannot be an empty string
	Port           int                  `json:"port"`
	Protocol       string               `json:"protocol"`
	Settings       json_util.RawMessage `json:"settings"`
	StreamSettings json_util.RawMessage `json:"streamSettings"`
	Tag            string               `json:"tag"`
	Sniffing       json_util.RawMessage `json:"sniffing"`
}

InboundConfig represents an Xray inbound configuration. It defines how Xray accepts incoming connections including protocol, port, and settings.

func (*InboundConfig) Equals

func (c *InboundConfig) Equals(other *InboundConfig) bool

Equals compares two InboundConfig instances for deep equality.

type LogWriter

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

LogWriter processes and filters log output from the Xray process, handling crash detection and message filtering.

func NewLogWriter

func NewLogWriter() *LogWriter

NewLogWriter returns a new LogWriter for processing Xray log output.

func (*LogWriter) Write

func (lw *LogWriter) Write(m []byte) (n int, err error)

Write processes and filters log output from the Xray process, handling crash detection and message filtering.

type Process

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

Process wraps an Xray process instance and provides management methods.

func NewProcess

func NewProcess(xrayConfig *Config) *Process

NewProcess creates a new Xray process and sets up cleanup on garbage collection.

func (*Process) GetAPIPort

func (p *Process) GetAPIPort() int

GetAPIPort returns the API port used by the Xray process.

func (*Process) GetConfig

func (p *Process) GetConfig() *Config

GetConfig returns the configuration used by the Xray process.

func (Process) GetErr

func (p Process) GetErr() error

GetErr returns the last error encountered by the Xray process.

func (*Process) GetOnlineClients

func (p *Process) GetOnlineClients() []string

GetOnlineClients returns the list of online clients for the Xray process.

func (Process) GetResult

func (p Process) GetResult() string

GetResult returns the last log line or error from the Xray process.

func (*Process) GetUptime

func (p *Process) GetUptime() uint64

GetUptime returns the uptime of the Xray process in seconds.

func (Process) GetVersion

func (p Process) GetVersion() string

GetVersion returns the version string of the Xray process.

func (Process) IsRunning

func (p Process) IsRunning() bool

IsRunning returns true if the Xray process is currently running.

func (*Process) SetOnlineClients

func (p *Process) SetOnlineClients(users []string)

SetOnlineClients sets the list of online clients for the Xray process.

func (Process) Start

func (p Process) Start() (err error)

Start launches the Xray process with the current configuration.

func (Process) Stop

func (p Process) Stop() error

Stop terminates the running Xray process.

type Traffic

type Traffic struct {
	IsInbound  bool
	IsOutbound bool
	Tag        string
	Up         int64
	Down       int64
}

Traffic represents network traffic statistics for Xray connections. It tracks upload and download bytes for inbound or outbound traffic.

type XrayAPI

type XrayAPI struct {
	HandlerServiceClient *command.HandlerServiceClient
	StatsServiceClient   *statsService.StatsServiceClient
	// contains filtered or unexported fields
}

XrayAPI is a gRPC client for managing Xray core configuration, inbounds, outbounds, and statistics.

func (*XrayAPI) AddInbound

func (x *XrayAPI) AddInbound(inbound []byte) error

AddInbound adds a new inbound configuration to the Xray core via gRPC.

func (*XrayAPI) AddUser

func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]any) error

AddUser adds a user to an inbound in the Xray core using the specified protocol and user data.

func (*XrayAPI) Close

func (x *XrayAPI) Close()

Close closes the gRPC connection and resets the XrayAPI client state.

func (*XrayAPI) DelInbound

func (x *XrayAPI) DelInbound(tag string) error

DelInbound removes an inbound configuration from the Xray core by tag.

func (*XrayAPI) GetTraffic

func (x *XrayAPI) GetTraffic(reset bool) ([]*Traffic, []*ClientTraffic, error)

GetTraffic queries traffic statistics from the Xray core, optionally resetting counters.

func (*XrayAPI) Init

func (x *XrayAPI) Init(apiPort int) error

Init connects to the Xray API server and initializes handler and stats service clients.

func (*XrayAPI) RemoveUser

func (x *XrayAPI) RemoveUser(inboundTag, email string) error

RemoveUser removes a user from an inbound in the Xray core by email.

Jump to

Keyboard shortcuts

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