libXray

package module
v0.0.0-...-b3f6881 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 7 Imported by: 0

README

libXray

简体中文

This is a wrapper around Xray-core to improve the client development experience.

Note

  1. This repository has few maintainers. If you do not report a bug or initiate a PR, your issue will be ignored.
  2. This repository does not guarantee API stability, you need to adapt it yourself.
  3. This repository is only compatible with the latest release of Xray-core.

Features

build

Compile script. It is recommended to always use this script to compile libXray. We will not answer questions caused by using other compilation methods.

You need to put Xray-core and libXray in the same directory to compile.

Usage
python3 build/main.py android
python3 build/main.py apple gomobile
python3 build/main.py apple go
python3 build/main.py linux
python3 build/main.py windows
Android

use gomobile .

iOS && macOS
1. use gomobile

Need "iOS Simulator Runtime".

This is the best choice for general scenarios and will not conflict with other frameworks.

Supports iOS, iOSSimulator, macOS, macCatalyst.

But it is not possible to set the minimum macOS version, which will cause some warnings when compiling. And it does not support tvOS.

2. use cgo

Need "iOS Simulator Runtime" and "tvOS Simulator Runtime".

Support more compilation options, output c header files.

This works well when you use ffi for integration. For example, integration with swift, kotlin, dart.

Support iOS, iOSSimulator, macOS, tvOS.

Note: The product LibXray.xcframework does not contain module.modulemap. When using swift, you need to create a bridge file.

Linux

depend on gcc and g++.

Windows

depend on LLVM MinGW, you can install it using winget.

winget install MartinStorsjo.LLVM-MinGW.UCRT

controller

Used to solve the socket protect problem on Android.

dns

Used to solve server address resolution issues on Android, Linux, and Windows. If not handled, the DNS traffic will be resent to the tun device, resulting in failure to initiate a connection.

geo

count

Read geo files and count the categories and rules.

read

Read the Xray Json configuration and extract the geo file name used.

thin

Read the Xray Json configuration and cut the geo file used.

main

Download geosite.dat and geoip.dat and count them.

memory

Only executed on iOS, GC is initiated once a second. This can alleviate memory pressure on iOS.

nodep

file

Write data to a file.

measure

Speed ​​test the Xray configuration.

model

The response body of the wrapper interface.

port

Get free ports.

share

libXray uses sendThrough to store outbound names.

clash_meta

Parse Clash.Meta configuration.

generate_share

convert Xray Json to VMessAEAD/VLESS sharing protocol.

parse_share

convert VMessAEAD/VLESS sharing protocol to Xray Json.

convert VMessQRCode to Xray Json.

vmess

convert VMessQRCode to Xray Json.

xray_json

Some tools used to parse shared links.

xray

ping

Latency testing.

stats

Refer to the following configuration:

{
  "metrics" : {
    "tag" : "metrics",
    "listen": "[::1]:49227",
  },
  "policy" : {
    "system" : {
      "statsInboundDownlink" : true,
      "statsInboundUplink" : true,
      "statsOutboundDownlink" : true,
      "statsOutboundUplink" : true
    }
  },
  "stats" : {}
}

Note:

  1. When testing latency or validating configuration, make sure metrics is null.

  2. When enabling metrics, the Xray-core instance needs to be run in a child process.

validation

Verify the Xray configuration.

xray

Start and stop Xray instances.

nodep_wrapper

export nodep.

xray_wrapper

export xray.

Credits

Project X

VMessPing

FreePort

License

This repository is based on the MIT License.

Documentation

Overview

libXray is an Xray wrapper focusing on improving the experience of Xray-core mobile development.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertShareLinksToXrayJson

func ConvertShareLinksToXrayJson(base64Text string) string

Convert share text to XrayJson support XrayJson, v2rayN plain text, v2rayN base64 text, Clash.Meta yaml

func ConvertXrayJsonToShareLinks(base64Text string) string

Convert XrayJson to share links. VMess will generate VMessAEAD link.

func CountGeoData

func CountGeoData(base64Text string) string

Read geo data and write all codes to text file.

func GetFreePorts

func GetFreePorts(count int) string

Wrapper of nodep.GetFreePorts count means how many ports you need.

func Ping

func Ping(base64Text string) string

Ping Xray config and get the delay of its outbound.

func QueryStats

func QueryStats(base64Text string) string

query inbound and outbound stats.

func ReadGeoFiles

func ReadGeoFiles(base64Text string) string

thin geo data

func RunXray

func RunXray(base64Text string) string

Run Xray instance.

func StopXray

func StopXray() string

Stop Xray instance.

func TestXray

func TestXray(base64Text string) string

Test Xray Config.

func ThinGeoData

func ThinGeoData(base64Text string) string

thin geo data

func XrayVersion

func XrayVersion() string

Xray's version

Types

type CountGeoDataRequest

type CountGeoDataRequest struct {
	DatDir  string `json:"datDir,omitempty"`
	Name    string `json:"name,omitempty"`
	GeoType string `json:"geoType,omitempty"`
}

type RunXrayRequest

type RunXrayRequest struct {
	DatDir     string `json:"datDir,omitempty"`
	ConfigPath string `json:"configPath,omitempty"`
}

type TestXrayRequest

type TestXrayRequest struct {
	DatDir     string `json:"datDir,omitempty"`
	ConfigPath string `json:"configPath,omitempty"`
}

type ThinGeoDataRequest

type ThinGeoDataRequest struct {
	DatDir     string `json:"datDir,omitempty"`
	ConfigPath string `json:"configPath,omitempty"`
	DstDir     string `json:"dstDir,omitempty"`
}

Directories

Path Synopsis
build
template command

Jump to

Keyboard shortcuts

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