fix(conf): add Windows support for Unix Domain Socket in the fallback settings

This commit is contained in:
Allo 2023-12-27 12:19:52 +08:00 committed by yuhan6665
parent 1dba70004f
commit 006cf491e5
2 changed files with 28 additions and 30 deletions

View file

@ -2,8 +2,10 @@ package conf
import (
"encoding/json"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"github.com/xtls/xray-core/common/net"
@ -147,16 +149,14 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
if fb.Type == "" && fb.Dest != "" {
if fb.Dest == "serve-ws-none" {
fb.Type = "serve"
} else {
switch fb.Dest[0] {
case '@', '/':
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
fb.Type = "unix"
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
if strings.HasPrefix(fb.Dest, "@@") && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
copy(fullAddr, fb.Dest[1:])
fb.Dest = string(fullAddr)
}
default:
} else {
if _, err := strconv.Atoi(fb.Dest); err == nil {
fb.Dest = "127.0.0.1:" + fb.Dest
}
@ -165,7 +165,6 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
}
}
}
}
if fb.Type == "" {
return nil, newError(`Trojan fallbacks: please fill in a valid value for every "dest"`)
}

View file

@ -2,8 +2,10 @@ package conf
import (
"encoding/json"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
"github.com/xtls/xray-core/common/net"
@ -103,16 +105,14 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
if fb.Type == "" && fb.Dest != "" {
if fb.Dest == "serve-ws-none" {
fb.Type = "serve"
} else {
switch fb.Dest[0] {
case '@', '/':
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
fb.Type = "unix"
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
if strings.HasPrefix(fb.Dest, "@@") && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
copy(fullAddr, fb.Dest[1:])
fb.Dest = string(fullAddr)
}
default:
} else {
if _, err := strconv.Atoi(fb.Dest); err == nil {
fb.Dest = "127.0.0.1:" + fb.Dest
}
@ -121,7 +121,6 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
}
}
}
}
if fb.Type == "" {
return nil, newError(`VLESS fallbacks: please fill in a valid value for every "dest"`)
}