Skip to content

Commit 25f7657

Browse files
Merge pull request WireGuard#12 from amnezia-vpn/feature/xray-merge
Feature/xray merge
2 parents 69669bb + ed6807c commit 25f7657

File tree

5 files changed

+416
-6
lines changed

5 files changed

+416
-6
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let package = Package(
3131
"go.mod",
3232
"go.sum",
3333
"api-apple.go",
34+
"api-xray.go",
3435
"Makefile"
3536
],
3637
publicHeadersPath: ".",

Sources/WireGuardKitGo/api-xray.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package main
2+
3+
import "C"
4+
import (
5+
"github.com/amnezia-vpn/amnezia-libxray/nodep"
6+
"github.com/amnezia-vpn/amnezia-libxray/xray"
7+
)
8+
9+
// Read geo data and cut the codes we need.
10+
// datDir means the dir which geo dat are in.
11+
// dstDir means the dir which new geo dat are in.
12+
// cutCodePath means geoCutCode json file path
13+
//
14+
// This function is used to reduce memory when init instance.
15+
// You can cut the country codes which rules and nameservers contain.
16+
//
17+
//export LibXrayCutGeoData
18+
func LibXrayCutGeoData(datDir, dstDir, cutCodePath *C.char) *C.char {
19+
err := xray.CutGeoData(C.GoString(datDir), C.GoString(dstDir), C.GoString(cutCodePath))
20+
return C.CString(nodep.WrapError(err))
21+
}
22+
23+
// Read geo data and write all codes to text file.
24+
// datDir means the dir which geo dat are in.
25+
// name means the geo dat file name, like "geosite", "geoip"
26+
// geoType must be the value of geoType
27+
//
28+
//export LibXrayLoadGeoData
29+
func LibXrayLoadGeoData(datDir, name, geoType *C.char) *C.char {
30+
err := xray.LoadGeoData(C.GoString(datDir), C.GoString(name), C.GoString(geoType))
31+
return C.CString(nodep.WrapError(err))
32+
}
33+
34+
// Ping Xray config and find the delay and country code of its outbound.
35+
// datDir means the dir which geosite.dat and geoip.dat are in.
36+
// configPath means the config.json file path.
37+
// timeout means how long the http request will be cancelled if no response, in units of seconds.
38+
// url means the website we use to test speed. "https://www.google.com" is a good choice for most cases.
39+
// proxy means the local http/socks5 proxy, like "socks5://[::1]:1080".
40+
//
41+
//export LibXrayPing
42+
func LibXrayPing(datDir, configPath *C.char, timeout int, url, proxy *C.char) *C.char {
43+
return C.CString(xray.Ping(C.GoString(datDir), C.GoString(configPath), timeout, C.GoString(url), C.GoString(proxy)))
44+
}
45+
46+
// query system stats and outbound stats.
47+
// server means The API server address, like "127.0.0.1:8080".
48+
// dir means the dir which result json will be wrote to.
49+
//
50+
//export LibXrayQueryStats
51+
func LibXrayQueryStats(server, dir *C.char) *C.char {
52+
err := xray.QueryStats(C.GoString(server), C.GoString(dir))
53+
return C.CString(nodep.WrapError(err))
54+
}
55+
56+
// convert text to uuid
57+
//
58+
//export LibXrayCustomUUID
59+
func LibXrayCustomUUID(text *C.char) *C.char {
60+
return C.CString(xray.CustomUUID(C.GoString(text)))
61+
}
62+
63+
// Test Xray Config.
64+
// datDir means the dir which geosite.dat and geoip.dat are in.
65+
// configPath means the config.json file path.
66+
//
67+
//export LibXrayTestXray
68+
func LibXrayTestXray(datDir, configPath *C.char) *C.char {
69+
err := xray.TestXray(C.GoString(datDir), C.GoString(configPath))
70+
return C.CString(nodep.WrapError(err))
71+
}
72+
73+
// Run Xray instance.
74+
// datDir means the dir which geosite.dat and geoip.dat are in.
75+
// configPath means the config.json file path.
76+
// maxMemory means the soft memory limit of golang, see SetMemoryLimit to find more information.
77+
//
78+
//export LibXrayRunXray
79+
func LibXrayRunXray(datDir, configPath *C.char, maxMemory int64) *C.char {
80+
err := xray.RunXray(C.GoString(datDir), C.GoString(configPath), maxMemory)
81+
return C.CString(nodep.WrapError(err))
82+
}
83+
84+
// Stop Xray instance.
85+
//
86+
//export LibXrayStopXray
87+
func LibXrayStopXray() *C.char {
88+
err := xray.StopXray()
89+
return C.CString(nodep.WrapError(err))
90+
}
91+
92+
// Xray's version
93+
//
94+
//export LibXrayXrayVersion
95+
func LibXrayXrayVersion() *C.char {
96+
return C.CString(xray.XrayVersion())
97+
}

Sources/WireGuardKitGo/go.mod

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,54 @@ module github.com/amnezia-vpn/amneziawg-apple
33
go 1.22.3
44

55
require (
6-
github.com/amnezia-vpn/amneziawg-go v0.2.11
7-
golang.org/x/sys v0.18.0
6+
github.com/amnezia-vpn/amnezia-libxray v0.0.1
7+
github.com/amnezia-vpn/amneziawg-go v0.2.10
8+
golang.org/x/sys v0.20.0
89
)
910

1011
require (
12+
github.com/OmarTariq612/goech v0.0.0-20240405204721-8e2e1dafd3a0 // indirect
13+
github.com/amnezia-vpn/amnezia-xray-core v1.8.11 // indirect
14+
github.com/andybalholm/brotli v1.1.0 // indirect
15+
github.com/cloudflare/circl v1.3.8 // indirect
16+
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
17+
github.com/francoispqt/gojay v1.2.13 // indirect
18+
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect
19+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
20+
github.com/google/btree v1.1.2 // indirect
21+
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
22+
github.com/gorilla/websocket v1.5.1 // indirect
23+
github.com/klauspost/compress v1.17.7 // indirect
24+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
25+
github.com/onsi/ginkgo/v2 v2.16.0 // indirect
26+
github.com/pelletier/go-toml v1.9.5 // indirect
27+
github.com/pires/go-proxyproto v0.7.0 // indirect
28+
github.com/quic-go/quic-go v0.44.0 // indirect
29+
github.com/refraction-networking/utls v1.6.6 // indirect
30+
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
31+
github.com/sagernet/sing v0.3.8 // indirect
32+
github.com/sagernet/sing-shadowsocks v0.2.6 // indirect
33+
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect
1134
github.com/tevino/abool/v2 v2.1.0 // indirect
12-
golang.org/x/crypto v0.21.0 // indirect
13-
golang.org/x/net v0.21.0 // indirect
35+
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
36+
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230316163032-ced5aaba43e3 // indirect
37+
github.com/vishvananda/netns v0.0.4 // indirect
38+
github.com/xtls/reality v0.0.0-20231112171332-de1173cf2b19 // indirect
39+
go.uber.org/mock v0.4.0 // indirect
40+
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
41+
golang.org/x/crypto v0.23.0 // indirect
42+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
43+
golang.org/x/mod v0.17.0 // indirect
44+
golang.org/x/net v0.25.0 // indirect
45+
golang.org/x/text v0.15.0 // indirect
46+
golang.org/x/time v0.5.0 // indirect
47+
golang.org/x/tools v0.21.0 // indirect
1448
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
49+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
50+
google.golang.org/grpc v1.64.0 // indirect
51+
google.golang.org/protobuf v1.34.1 // indirect
52+
gopkg.in/yaml.v2 v2.4.0 // indirect
53+
gopkg.in/yaml.v3 v3.0.1 // indirect
54+
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489 // indirect
55+
lukechampine.com/blake3 v1.3.0 // indirect
1556
)

0 commit comments

Comments
 (0)