Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build/template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import "C"

func main() {}

//export CGoSetTunFd
func CGoSetTunFd(fd C.int) {
SetTunFd(int32(fd))
}

//export CGoInitDns
func CGoInitDns(base64Text *C.char) *C.char {
text := C.GoString(base64Text)
Expand Down
7 changes: 7 additions & 0 deletions xray/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xray
import (
"os"
"runtime/debug"
"strconv"

"github.com/xtls/libxray/memory"
"github.com/xtls/xray-core/common/cmdarg"
Expand Down Expand Up @@ -45,6 +46,12 @@ func StartXrayFromJSON(configJSON string) (*core.Instance, error) {
return server, nil
}

// SetTunFd sets the TUN file descriptor.
// Call this BEFORE RunXray/RunXrayFromJSON.
func SetTunFd(fd int32) {
os.Setenv("XRAY_TUN_FD", strconv.Itoa(int(fd)))
}

func InitEnv(datDir string, mphCachePath string) {
os.Setenv(platform.AssetLocation, datDir)
os.Setenv(platform.CertLocation, datDir)
Expand Down
6 changes: 6 additions & 0 deletions xray_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"github.com/xtls/libxray/xray"
)

// SetTunFd sets the TUN file descriptor.
// Call this BEFORE RunXray/RunXrayFromJSON.
func SetTunFd(fd int32) {
xray.SetTunFd(fd)
}

type CountGeoDataRequest struct {
DatDir string `json:"datDir,omitempty"`
Name string `json:"name,omitempty"`
Expand Down