Skip to content

Commit

Permalink
bump to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yiguo committed Jun 26, 2024
1 parent 9deff15 commit 893c20a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,50 @@ This is an Xray wrapper focusing on improving the experience of [Xray-core](http

3. If your issue is about some Platform development, like iOS or Android, it will be just closed.

# Break changes

From 3.0.0, all apis have changed to base64-encoded-string-based, including paramters and return value.

The reasons are as bellow.

1. We must be careful when using cgo. Always remember to free c-strings we pass to cgo and get from cgo. If there are many string paramters in the function, it will be a nightmare. So we just keep one string parameter and one string return value for every function.

2. The string paramter and string return value may be transfered between languages, like go -> swift/kotlin/cpp -> dart, using their ffi. Some characters may be wrong when they are encoded and decoded many times. So encoding string to ascii characters will be a better choice, and we just choose base64.

# Features

## nodep

### clash.go

parse Clash and Clash.Meta config.

### file.go

write data to file.

### memory.go
### generate_share.go

try to control the max memory.
convert v2rayN subscriptions to Xray Json.

### port.go
convert VMessAEAD/VLESS sharing protocol to Xray Json.

get free port.
### measure.go

### share.go
ping xray outbound.

convert v2rayN subscriptions to Xray Json.
### memory.go

convert VMessAEAD/VLESS sharing protocol to Xray Json.
try to control the max memory.

### subscription.go
### parse_share.go

convert Xray Json to subscription links.

### port.go

get free port.

### vmess.go

convert VMessQRCode to Xray Json.
Expand All @@ -48,10 +66,6 @@ support flattening outbounds.

## xray

### geo_cut.go

cut geosite.data 和 geoip.data.

### geo.go

read geosite.dat and geoip.dat, generate json file and count rules, including Attribute.
Expand All @@ -78,20 +92,28 @@ start and stop Xray instance.

## lib package

### build.sh
### build

generate xcframework and aar.
build libXray, currently support android and apple.

It will always use the latest Xray-core.

### controller.go
### controller.go && dns.go

experimental Android support.

register a controller to protect all connections.

Because there is no api to reset effectiveListener, Only run them once when app running.

### dns.go

experimental Android support.

register a controller to protect default dns queries.

If the xray server address is a domain, InitDns will be useful to resolve the "first connection" problem.

### nodep_wrapper.go

export nodep.
Expand Down
1 change: 0 additions & 1 deletion dns_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var (
)

// Give a callback when parsing server domain. Useful for Android development.
// this function is under development, and there is no guarantee for its availability.
// It depends on xray:api:beta
func InitDns(controller DialerController, dns string) {
if dnsDialer != nil {
Expand Down
2 changes: 1 addition & 1 deletion nodep/measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
PingDelayError int64 = 10000
)

// Find the delay and ip of some outbound.
// get the delay of some outbound.
// 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.
// proxy means the local http/socks5 proxy, like "socks5://[::1]:1080".
Expand Down
1 change: 0 additions & 1 deletion nodep_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type getFreePortsResponse struct {

// Wrapper of nodep.GetFreePorts
// count means how many ports you need.
// return ports divided by ":", like "1080:1081"
func GetFreePorts(count int) string {
var response nodep.CallResponse[*getFreePortsResponse]
ports, err := nodep.GetFreePorts(count)
Expand Down
17 changes: 1 addition & 16 deletions xray_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ type loadGeoDataRequest struct {
}

// 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(base64Text string) string {
var response nodep.CallResponse[string]
req, err := base64.StdEncoding.DecodeString(base64Text)
Expand All @@ -42,12 +39,7 @@ type pingRequest struct {
Proxy string `json:"proxy,omitempty"`
}

// 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.
// proxy means the local http/socks5 proxy, like "socks5://[::1]:1080".
// Ping Xray config and get the delay of its outbound.
func Ping(base64Text string) string {
var response nodep.CallResponse[int64]
req, err := base64.StdEncoding.DecodeString(base64Text)
Expand All @@ -69,8 +61,6 @@ type queryStatsResponse struct {
}

// 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(base64Text string) string {
var response nodep.CallResponse[*queryStatsResponse]
server, err := base64.StdEncoding.DecodeString(base64Text)
Expand Down Expand Up @@ -105,8 +95,6 @@ type testXrayRequest struct {
}

// Test Xray Config.
// datDir means the dir which geosite.dat and geoip.dat are in.
// configPath means the config.json file path.
func TestXray(base64Text string) string {
var response nodep.CallResponse[string]
req, err := base64.StdEncoding.DecodeString(base64Text)
Expand All @@ -129,9 +117,6 @@ type runXrayRequest struct {
}

// 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(base64Text string) string {
var response nodep.CallResponse[string]
req, err := base64.StdEncoding.DecodeString(base64Text)
Expand Down

0 comments on commit 893c20a

Please sign in to comment.