mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 20:59:19 +02:00
fix(conf): add Windows support for Unix Domain Socket in the fallback settings
This commit is contained in:
parent
1dba70004f
commit
006cf491e5
|
@ -2,8 +2,10 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
@ -147,22 +149,19 @@ func (c *TrojanServerConfig) Build() (proto.Message, error) {
|
||||||
if fb.Type == "" && fb.Dest != "" {
|
if fb.Type == "" && fb.Dest != "" {
|
||||||
if fb.Dest == "serve-ws-none" {
|
if fb.Dest == "serve-ws-none" {
|
||||||
fb.Type = "serve"
|
fb.Type = "serve"
|
||||||
|
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
|
||||||
|
fb.Type = "unix"
|
||||||
|
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)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch fb.Dest[0] {
|
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
||||||
case '@', '/':
|
fb.Dest = "127.0.0.1:" + fb.Dest
|
||||||
fb.Type = "unix"
|
}
|
||||||
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
if _, _, err := net.SplitHostPort(fb.Dest); err == nil {
|
||||||
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
fb.Type = "tcp"
|
||||||
copy(fullAddr, fb.Dest[1:])
|
|
||||||
fb.Dest = string(fullAddr)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
|
||||||
fb.Dest = "127.0.0.1:" + fb.Dest
|
|
||||||
}
|
|
||||||
if _, _, err := net.SplitHostPort(fb.Dest); err == nil {
|
|
||||||
fb.Type = "tcp"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
@ -103,22 +105,19 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
||||||
if fb.Type == "" && fb.Dest != "" {
|
if fb.Type == "" && fb.Dest != "" {
|
||||||
if fb.Dest == "serve-ws-none" {
|
if fb.Dest == "serve-ws-none" {
|
||||||
fb.Type = "serve"
|
fb.Type = "serve"
|
||||||
|
} else if filepath.IsAbs(fb.Dest) || fb.Dest[0] == '@' {
|
||||||
|
fb.Type = "unix"
|
||||||
|
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)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch fb.Dest[0] {
|
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
||||||
case '@', '/':
|
fb.Dest = "127.0.0.1:" + fb.Dest
|
||||||
fb.Type = "unix"
|
}
|
||||||
if fb.Dest[0] == '@' && len(fb.Dest) > 1 && fb.Dest[1] == '@' && (runtime.GOOS == "linux" || runtime.GOOS == "android") {
|
if _, _, err := net.SplitHostPort(fb.Dest); err == nil {
|
||||||
fullAddr := make([]byte, len(syscall.RawSockaddrUnix{}.Path)) // may need padding to work with haproxy
|
fb.Type = "tcp"
|
||||||
copy(fullAddr, fb.Dest[1:])
|
|
||||||
fb.Dest = string(fullAddr)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if _, err := strconv.Atoi(fb.Dest); err == nil {
|
|
||||||
fb.Dest = "127.0.0.1:" + fb.Dest
|
|
||||||
}
|
|
||||||
if _, _, err := net.SplitHostPort(fb.Dest); err == nil {
|
|
||||||
fb.Type = "tcp"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue