Skip to content

Commit

Permalink
move file positions
Browse files Browse the repository at this point in the history
  • Loading branch information
yiguous committed Nov 17, 2023
1 parent 8cf4ec4 commit b30ea8b
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 107 deletions.
78 changes: 36 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,95 +16,89 @@ This is an Xray wrapper focusing on improving the experience of [Xray-core](http

### clash.go

转换 Clash yaml,Clash.Meta yaml Xray Json
convert Clash yaml,Clash.Meta yaml to Xray Json.

### file.go

文件写入。

### measure.go

基于 http/socks5 proxy 进行延迟测试。

基于 geoip.dat 进行 geolocation。

TCPPing。
write data to file.

### memory.go

强制 GC。
try to control the max memory.

### port.go

获取空闲端口。
get free port.

### share.go

转换 v2rayN 订阅为 Xray Json
convert v2rayN subscriptions to Xray Json.

转换 VMessAEAD/VLESS 分享为 Xray Json
convert VMessAEAD/VLESS sharing protocol to Xray Json.

### subscription.go

转换 Xray Json 为订阅文本。
convert Xray Json to subscription links.

### vmess.go

转换 VMessQRCode Xray Json
convert VMessQRCode to Xray Json.

### xray_json.go

Xray 配置的子集,为出口节点添加了 Name 字段,便于 App 内进行解析。
subset of Xray config, add name field to outbound.

支持 flatten outbounds
support flattening outbounds.

## lib package
## xray

### build.sh
### geo_cut.go

编译脚本。一键生成 xcframeworkaar。
cut geosite.datageoip.data.

### controller.go
### geo.go

实验性的 Android 支持 。
read geosite.dat and geoip.dat, generate json file and count rules, including Attribute.

### geo_cut.go
### ping.go

剪切 geosite.data 和 geoip.data 。
test the delay.

### geo.go
### stats.go

读取 geo site dat,生成类别名称文件并统计规则数量,包含 Attribute。
read the

读取 geo ip dat,生成类别名称文件并统计规则数量。
### uuid.go

### nodep_wrapper.go
convert custom text to uuid.

获取空闲端口。
### validation.go

转换分享文本为 Xray Json。
test Xray config.

转换 Xray Json 为分享文本。
### xray.go

### ping.go
start and stop Xray instance.

测速。
## lib package

### stats.go
### build.sh

统计。
generate xcframework and aar.

### uuid.go
It will always use the latest Xray-core.

转换自定义文本为 uuid。
### controller.go

### validation.go
experimental Android support.

测试 Xray 配置文件。
### nodep_wrapper.go

### xray.go
export nodep.

### xray_wrapper.go

启动和停止 Xray 。
export xray.

## Credits

Expand Down
15 changes: 11 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/bash

go mod tidy
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
go get -d golang.org/x/mobile/cmd/gomobile
prepare_go() {
rm -f go.mod
go mod init github.com/xtls/libxray

go mod tidy
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
go get -d golang.org/x/mobile/cmd/gomobile
}


build_apple() {
rm -fr *.xcframework
Expand All @@ -21,6 +27,7 @@ download_geo() {
}

echo "will build libxray for $1"
prepare_go
download_geo
if [ "$1" != "apple" ]; then
build_android
Expand Down
54 changes: 1 addition & 53 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
module github.com/xtls/libxray

go 1.21.1

require (
github.com/xtls/xray-core v1.8.4
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pires/go-proxyproto v0.7.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.3 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/refraction-networking/utls v1.4.3 // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
github.com/sagernet/sing v0.2.9 // indirect
github.com/sagernet/sing-shadowsocks v0.2.4 // indirect
github.com/sagernet/wireguard-go v0.0.0-20221116151939-c99467f53f2c // indirect
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
github.com/xtls/reality v0.0.0-20230828171259-e426190d57f6 // indirect
go.uber.org/atomic v1.11.0 // indirect
go4.org/netipx v0.0.0-20230824141953-6213f710f925 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect
golang.org/x/mobile v0.0.0-20231006135142-2b44d11868fe // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.16.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gvisor.dev/gvisor v0.0.0-20230822212503-5bf4e5f98744 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
go 1.21.3
2 changes: 1 addition & 1 deletion geo.go → xray/geo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion geo_cut.go → xray/geo_cut.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion ping.go → xray/ping.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion stats.go → xray/stats.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion uuid.go → xray/uuid.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

import (
"github.com/xtls/xray-core/common/uuid"
Expand Down
2 changes: 1 addition & 1 deletion validation.go → xray/validation.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package libXray
package xray

// Test Xray Config.
// datDir means the dir which geosite.dat and geoip.dat are in.
Expand Down
3 changes: 1 addition & 2 deletions xray.go → xray/xray.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// libXray is an Xray wrapper focusing on improving the experience of Xray-core mobile development.
package libXray
package xray

import (
"os"
Expand Down
73 changes: 73 additions & 0 deletions xray_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// libXray is an Xray wrapper focusing on improving the experience of Xray-core mobile development.
package libXray

import (
"github.com/xtls/libxray/xray"
)

// Read geo data and cut the codes we need.
// datDir means the dir which geo dat are in.
// dstDir means the dir which new geo dat are in.
// cutCodePath means geoCutCode json file path
//
// This function is used to reduce memory when init instance.
// You can cut the country codes which rules and nameservers contain.
func CutGeoData(datDir string, dstDir string, cutCodePath string) string {
return xray.CutGeoData(datDir, dstDir, cutCodePath)
}

// Read geo data and write all codes to text file.
// datDir means the dir which geo dat are in.
// name means the geo dat file name, like "geosite", "geoip"
// geoType must be the value of geoType
func LoadGeoData(datDir string, name string, geoType string) string {
return xray.LoadGeoData(datDir, name, geoType)
}

// Ping Xray config and find the delay and country code of its outbound.
// datDir means the dir which geosite.dat and geoip.dat are in.
// configPath means the config.json file path.
// timeout means how long the http request will be cancelled if no response, in units of seconds.
// url means the website we use to test speed. "https://www.google.com" is a good choice for most cases.
// times means how many times we should test the url.
// proxy means the local http/socks5 proxy, like "socks5://[::1]:1080".
func Ping(datDir string, configPath string, timeout int, url string, times int, proxy string) string {
return xray.Ping(datDir, configPath, timeout, url, times, proxy)
}

// query system stats and outbound stats.
// server means The API server address, like "127.0.0.1:8080".
// dir means the dir which result json will be wrote to.
func QueryStats(server string, dir string) string {
return xray.QueryStats(server, dir)
}

// convert text to uuid
func CustomUUID(text string) string {
return xray.CustomUUID(text)
}

// Test Xray Config.
// datDir means the dir which geosite.dat and geoip.dat are in.
// configPath means the config.json file path.
func TestXray(datDir string, configPath string) string {
return xray.TestXray(datDir, configPath)
}

// Run Xray instance.
// datDir means the dir which geosite.dat and geoip.dat are in.
// configPath means the config.json file path.
// maxMemory means the soft memory limit of golang, see SetMemoryLimit to find more information.
func RunXray(datDir string, configPath string, maxMemory int64) string {
return xray.RunXray(datDir, configPath, maxMemory)
}

// Stop Xray instance.
func StopXray() string {
return xray.StopXray()
}

// Xray's version
func XrayVersion() string {
return xray.XrayVersion()
}

0 comments on commit b30ea8b

Please sign in to comment.