The latest developement of XTLS has moved to Xray-core v1.7.0 and https://github.com/XTLS/Xray-core/commit/6f61021f7a7337b2997c442495cb8654d145cf8f
THE FUTURE
License: MIT License
THE FUTURE
接续问题 #14
请问我后来在 xray_wrapper.go 新增增加转发 xray log 至 native 的功能,但是在 系统监控程式.app 看到的 log 是 "private" 并无转发到 native 中,所以提出以下 xray_wrapper.go 新增的内容,能请问各位前辈,我的程式码是否有没注意到的问题吗?
目前遇到两个问题
/// XrayLogger
type XrayLogger interface {
OnAccessLog(message string)
}
type myLogger struct{}
func (m *myLogger) OnAccessLog(message string) {
fmt.Println("Access Log:", message)
}
var globalLogger XrayLogger
// XraySetupLogger 接收一个 XrayLogger 接口实现
func XraySetupLogger(logger XrayLogger) {
globalLogger = logger
if logger != nil {
logger.OnAccessLog("Access log message")
}
}
/// Give me Log
type consoleLogWriter struct {
logger *log.Logger
}
func (w *consoleLogWriter) Close() error {
return nil
}
func (w *consoleLogWriter) Write(s string) error {
w.logger.Println(s)
globalLogger.OnAccessLog(s)
var stringA = fmt.Sprintf("(String(reflecting: %v), privacy: .public)", s)
globalLogger.OnAccessLog(stringA)
return nil
}
type defaultLogWriter struct{}
func (defaultLogWriter) Write(b []byte) (int, error) {
log.Println("(String(reflecting: %v), privacy: .public)", string(b))
var stringA = fmt.Sprintf("(String(reflecting: %v), privacy: .public)", string(b))
globalLogger.OnAccessLog(stringA)
return len(b), nil
}
func CreateDefaultLogWriter() v2commlog.WriterCreator {
return func() v2commlog.Writer {
return &consoleLogWriter{
logger: log.New(defaultLogWriter{}, "", 0),
}
}
}
func init() {
v2applog.RegisterHandlerCreator(v2applog.LogType_Console, func(lt v2applog.LogType, options v2applog.HandlerCreatorOptions) (v2commlog.Handler, error) {
return v2commlog.NewLogger(CreateDefaultLogWriter()), nil
})
}
以下是Swift的實現接口部分
extension XRayCoreManager: LibXrayXrayLoggerProtocol {
func onAccessLog(_ message: String?) {
os_log("[DEBUGV] onAccessLog: %{public}@", log: OSLog.default, type: .info, message ?? "456")
}
}
root@****:~/libXray# python3 build/main.py android
['build/main.py', 'android']
go: creating new go.mod: module github.com/xtls/libxray
go: to add module requirements and sums:
go mod tidy
go: finding module for package github.com/xtls/xray-core/common/cmdarg
go: finding module for package github.com/xtls/xray-core/app/log
go: finding module for package github.com/xtls/xray-core/app/router
go: finding module for package github.com/xtls/xray-core/transport/internet
go: finding module for package gopkg.in/yaml.v3
go: finding module for package github.com/xtls/xray-core/common
go: finding module for package github.com/xtls/xray-core/app/stats/command
go: finding module for package github.com/xtls/xray-core/common/log
go: finding module for package github.com/xtls/xray-core/common/uuid
go: finding module for package github.com/xtls/xray-core/core
go: finding module for package google.golang.org/grpc
go: finding module for package github.com/xtls/xray-core/main/distro/all
go: finding module for package google.golang.org/grpc/credentials/insecure
go: finding module for package google.golang.org/protobuf/encoding/protojson
go: finding module for package google.golang.org/protobuf/proto
go: found github.com/xtls/xray-core/transport/internet in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/app/log in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/common in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/common/log in github.com/xtls/xray-core v1.8.21
go: found gopkg.in/yaml.v3 in gopkg.in/yaml.v3 v3.0.1
go: found github.com/xtls/xray-core/app/router in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/app/stats/command in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/common/cmdarg in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/common/uuid in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/core in github.com/xtls/xray-core v1.8.21
go: found github.com/xtls/xray-core/main/distro/all in github.com/xtls/xray-core v1.8.21
go: found google.golang.org/grpc in google.golang.org/grpc v1.65.0
go: found google.golang.org/grpc/credentials/insecure in google.golang.org/grpc v1.65.0
go: found google.golang.org/protobuf/encoding/protojson in google.golang.org/protobuf v1.34.2
go: found google.golang.org/protobuf/proto in google.golang.org/protobuf v1.34.2
go: added golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6
go: upgraded golang.org/x/mod v0.18.0 => v0.19.0
go: upgraded golang.org/x/tools v0.22.0 => v0.23.0
gomobile: go build -buildmode=c-shared -o=/tmp/gomobile-work-2368720822/android/src/main/jniLibs/x86/libgojni.so ./gobind failed: exit status 1
# github.com/xtls/libxray/log
/root/libXray/log/android.go:46:2: undefined: common
/root/libXray/log/android.go:46:14: undefined: xlog
Traceback (most recent call last):
File "/root/libXray/build/main.py", line 30, in <module>
builder.build()
File "/root/libXray/build/app/android.py", line 23, in build
raise Exception("build failed")
Exception: build failed
This library is great. But to run it on Android, it should be optimized.
For example, when we want to use commands like share.go, the strings must be written in the file each time, and then specify the path of the file to this command for output.
This causes more pressure. Because to use any command, we have to write it in the file and give the file path to the program.
For example, consider this command:
val decode = "
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw..."
val array = decode.split("\n").toTypedArray()
for (strings in array) {
// first write each strings to a file
writeFile(path, strings)
// then give path of file to lib
LibXray.convertShareTextToXrayJson(path, outputPath)
// then read outputPath and ping them
LibXray.Ping(datDir, outputPath, timeout, url, proxy)
}
each step should written in disk and then read it from there.
But if it is as follows, all the steps are in string and it makes it more efficient and reduces the pressure on the disk;
val decode = "
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw..."
val array = decode.split("\n").toTypedArray()
for (strings in array) {
// the final output in string
val share = LibXray.convertShareTextToXrayJson(path, strings)
// read output in string format
LibXray.Ping(datDir, share, timeout, url, proxy)
}
please look at this sub, it has about +100 configs and by this way all of them should be write in disk every time. it will cool if this lib give us all of outputs in the string format.
my knowledge is not enough in go, but i just checked AndroidLibXrayLite and And I saw this line. i dont know how strings.NewReader works in go. But if anyone can please help to improve this library.
Today I started implementing a demo on Mac with this lib.
I can't build it though.
/Users/houmie/Library/Developer/Xcode/DerivedData/xraydemo-akmagyiewjmaxhgqegcdimbvucrm/Build/Products/Debug/tunnel-mac.appex: code object is not signed at all
In subcomponent: /Users/houmie/Library/Developer/Xcode/DerivedData/xraydemo-akmagyiewjmaxhgqegcdimbvucrm/Build/Products/Debug/tunnel-mac.appex/Contents/Frameworks/Libxray.framework
Command CodeSign failed with a nonzero exit code
I have already set it to Embed Without Signing.
But it doesn't work.
Any advice please?
使用空结构体指针作为接收对象,提供面向对象的 API。
thanks for this great work.
does this library always using the least version of Xray (XTLS Core) when we building it?
After compiling this for apple:
bash build.sh apple
and adding LibXray.xcframework
to my project, I can no longer build it.
I get this error:
/Users/houmie/Projects/libXray/LibXray.xcframework/ios-arm64/LibXray.framework bitcode_strip /Users/houmie/Projects/libXray/LibXray.xcframework/ios-arm64/LibXray.framework/Versions/A/LibXray: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip exited with 1
The only way to circumvent it is to
STRIP_BITCODE_FROM_COPIED_FILES=NO
Embed & Sign
to Embed Without Signing
.Is this intended like this?
As my understanding go.sum
is like npm package-lock.json
which guarantees the dependencies versions be exactly same as author machine
Why it listed in .gitignore
file?
When i run go mod download
to install dependencies go command updates libs so I have to commit the changes (go.mod
) which I don't want to do it!
I saw other go repos that contains this file
Please include it if there is no specific reason for that, Thanks
Hello friend,
It was working fine until today. Maybe it's because of the new iOS 17?
I have XCode Version 15.0 (15A240d), Mac M1 Ventura 13.6 (22G120) and iOS 17.0, go version go1.21.1 darwin/arm64
When trying to build it on Mac:
➜ libXray git:(main) bash build.sh apple
go: downloading github.com/xtls/xray-core v1.8.4
go: downloading google.golang.org/protobuf v1.31.0
go: downloading go4.org/netipx v0.0.0-20230824141953-6213f710f925
go: downloading github.com/sagernet/sing v0.2.9
go: downloading google.golang.org/grpc v1.57.0
go: downloading github.com/quic-go/quic-go v0.38.1
go: downloading golang.org/x/net v0.15.0
go: downloading github.com/miekg/dns v1.1.55
go: downloading golang.org/x/crypto v0.13.0
go: downloading github.com/refraction-networking/utls v1.4.3
go: downloading gvisor.dev/gvisor v0.0.0-20230822212503-5bf4e5f98744
go: downloading github.com/xtls/reality v0.0.0-20230828171259-e426190d57f6
go: downloading golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
go: downloading github.com/onsi/ginkgo/v2 v2.12.0
go: downloading github.com/onsi/gomega v1.27.10
go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d
go: downloading github.com/sagernet/sing-shadowsocks v0.2.4
go: downloading github.com/gaukas/godicttls v0.0.4
go: downloading github.com/klauspost/compress v1.16.7
go: downloading golang.org/x/text v0.13.0
go: downloading github.com/quic-go/qtls-go1-20 v0.3.3
go: downloading github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f
go: added golang.org/x/mobile v0.0.0-20230906132913-2077a3224571
will build libxray for apple
gomobile: xcodebuild -create-xcframework -framework /var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/ios/iphoneos/LibXray.framework -framework /var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/iossimulator/iphonesimulator/LibXray.framework -framework /var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/iossimulator/iphonesimulator/LibXray.framework -framework /var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/macos/macosx/LibXray.framework -framework /var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/macos/macosx/LibXray.framework -output LibXray.xcframework failed: exit status 70
error: cannot compute path of binary 'Path(str: "/private/var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/ios/iphoneos/LibXray.framework/Versions/A/LibXray")' relative to that of '/var/folders/9m/lwx24q8929g7kpcg7vb5vssh0000gn/T/gomobile-work-122789388/ios/iphoneos/LibXray.framework'
Any advice, please?
Thanks
你好,
感谢你的精彩项目。
我已经为iOS编译了这个项目,并添加到我的项目中。我是否需要在我的PacketTunnelProvider中使用这个框架?例如,我是否可以在startTunnel()等函数中直接运行LibxrayRunXray()?
请问有关于如何在iOS中使用这个框架的文档吗?
谢谢你,
I attempted to use an IP address that employs Xray to establish a SOCKS5 proxy, but it had no effect.
public class XrayVpnService extends VpnService {
private void setup() {
***
Builder builder = new Builder();
builder.addDnsServer("26.26.26.2");
***
}
}
Here's an example of the DNS config.json I utilized:
"dns" {
"hosts": {
"dns.nextdns.io": ["192.121.87.101","38.175.115.137"]
},
"servers": ["https://dns.nextdns.io/yourid"],
"queryStrategy": "UseIPv4",
"disableCache": true,
"disableFallback": true,
"disableFallbackIfMatch": true,
"tag": "dns"
}
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [ {
"port": "53,18303,853",
"outboundTag": "dns",
"type": "field"
}, {
"inboundTag": ["dns"],
"outboundTag": "proxy",
"type": "field"
}, {
"type": "field",
"ip": ["1.1.1.1", "10.0.2.3", "0.0.0.0"],
"outboundTag": "blackhole"
}
]
}
Hello brother,
Thanks for the great work on this project.
I understand there are breaking changes with version 3.0.0. But it is not clear to me.
Before I could do this on iOS:
LibXrayRunXray(TGConstant.assetDirectory.path, configurationFilePath, 1024 * 1024 * 10)
Now it only accepts a base64 text, I don't understand that. How do I pass in assetDirectory Path
and configuration file path
to LibXrayRunXray?
Do I need to convert them both to base64? Could you give an example in Go or Swift, so I understand it better?
Thank you so much
Hello!
You have an excellent library, and I've been using it for a long time. I noticed that in version 3, you added a builder through 'cgo'. I tried modifying the script to build on tvOS through it, but I constantly encounter errors. Since you have added the ability to build through this tool, could you add the capability in the script to build the library for tvOS?
Best regards,
Vitaliy
感谢作者开源,已可以使用libxray打包出来的 xcframework 可以正常运作
唯独只有无法检视log的运作,因为想仿造当时 Mango 专案在运作时可以观看log
但碍于已联系不到作者,只能自行摸索开发现阶段的 go 程式码
尝试好几天都还没有办法把 log 显示出来,所以上来请教
Hello,
What is the best way to get the usage (traffic)?
import UIKit
import NetworkExtension
import LibXray
class ViewController: UIViewController {
var tunnelProviderManager: NETunnelProviderManager?
var isTimerUsageRunning = false
var timerUsage = Timer()
override func viewDidLoad() {
super.viewDidLoad()
if self.isTimerUsageRunning == false {
self.isTimerUsageRunning = true
self.timerUsage = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [self] _ in
LibXrayQueryStats("127.0.0.1:8080", TGConstant.homeDirectory.absoluteString + "test.json")
})
}
}
I try to get the stats written to test.json every second. Is this the correct approach?
https://github.com/yiguous/libxray/blob/0ad0717b70b088ff628b917dade43dfbe0a60a9a/build.sh#L11
例如
gomobile bind -o ./XrayKit.xcframework -target=ios,iossimulator,macos -iosversion=12.0 -ldflags="-s -w" -v ./
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.