mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Transport: Remove DomainSocket (#3757)
https://github.com/XTLS/Xray-core/pull/3755#issuecomment-2325533003
This commit is contained in:
parent
9a953c070f
commit
c0a98f74fc
@ -12,7 +12,6 @@ type TransportConfig struct {
|
|||||||
KCPConfig *KCPConfig `json:"kcpSettings"`
|
KCPConfig *KCPConfig `json:"kcpSettings"`
|
||||||
WSConfig *WebSocketConfig `json:"wsSettings"`
|
WSConfig *WebSocketConfig `json:"wsSettings"`
|
||||||
HTTPConfig *HTTPConfig `json:"httpSettings"`
|
HTTPConfig *HTTPConfig `json:"httpSettings"`
|
||||||
DSConfig *DomainSocketConfig `json:"dsSettings"`
|
|
||||||
GRPCConfig *GRPCConfig `json:"grpcSettings"`
|
GRPCConfig *GRPCConfig `json:"grpcSettings"`
|
||||||
GUNConfig *GRPCConfig `json:"gunSettings"`
|
GUNConfig *GRPCConfig `json:"gunSettings"`
|
||||||
HTTPUPGRADEConfig *HttpUpgradeConfig `json:"httpupgradeSettings"`
|
HTTPUPGRADEConfig *HttpUpgradeConfig `json:"httpupgradeSettings"`
|
||||||
@ -67,17 +66,6 @@ func (c *TransportConfig) Build() (*global.Config, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.DSConfig != nil {
|
|
||||||
ds, err := c.DSConfig.Build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("Failed to build DomainSocket config.").Base(err)
|
|
||||||
}
|
|
||||||
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
|
|
||||||
ProtocolName: "domainsocket",
|
|
||||||
Settings: serial.ToTypedMessage(ds),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.GRPCConfig == nil {
|
if c.GRPCConfig == nil {
|
||||||
c.GRPCConfig = c.GUNConfig
|
c.GRPCConfig = c.GUNConfig
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
||||||
httpheader "github.com/xtls/xray-core/transport/internet/headers/http"
|
httpheader "github.com/xtls/xray-core/transport/internet/headers/http"
|
||||||
"github.com/xtls/xray-core/transport/internet/http"
|
"github.com/xtls/xray-core/transport/internet/http"
|
||||||
"github.com/xtls/xray-core/transport/internet/httpupgrade"
|
"github.com/xtls/xray-core/transport/internet/httpupgrade"
|
||||||
@ -313,21 +312,6 @@ func (c *HTTPConfig) Build() (proto.Message, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type DomainSocketConfig struct {
|
|
||||||
Path string `json:"path"`
|
|
||||||
Abstract bool `json:"abstract"`
|
|
||||||
Padding bool `json:"padding"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build implements Buildable.
|
|
||||||
func (c *DomainSocketConfig) Build() (proto.Message, error) {
|
|
||||||
return &domainsocket.Config{
|
|
||||||
Path: c.Path,
|
|
||||||
Abstract: c.Abstract,
|
|
||||||
Padding: c.Padding,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readFileOrString(f string, s []string) ([]byte, error) {
|
func readFileOrString(f string, s []string) ([]byte, error) {
|
||||||
if len(f) > 0 {
|
if len(f) > 0 {
|
||||||
return filesystem.ReadFile(f)
|
return filesystem.ReadFile(f)
|
||||||
@ -646,8 +630,6 @@ func (p TransportProtocol) Build() (string, error) {
|
|||||||
return "websocket", nil
|
return "websocket", nil
|
||||||
case "h2", "http":
|
case "h2", "http":
|
||||||
return "http", nil
|
return "http", nil
|
||||||
case "ds", "domainsocket":
|
|
||||||
return "domainsocket", nil
|
|
||||||
case "grpc", "gun":
|
case "grpc", "gun":
|
||||||
return "grpc", nil
|
return "grpc", nil
|
||||||
case "httpupgrade":
|
case "httpupgrade":
|
||||||
@ -783,7 +765,6 @@ type StreamConfig struct {
|
|||||||
KCPSettings *KCPConfig `json:"kcpSettings"`
|
KCPSettings *KCPConfig `json:"kcpSettings"`
|
||||||
WSSettings *WebSocketConfig `json:"wsSettings"`
|
WSSettings *WebSocketConfig `json:"wsSettings"`
|
||||||
HTTPSettings *HTTPConfig `json:"httpSettings"`
|
HTTPSettings *HTTPConfig `json:"httpSettings"`
|
||||||
DSSettings *DomainSocketConfig `json:"dsSettings"`
|
|
||||||
SocketSettings *SocketConfig `json:"sockopt"`
|
SocketSettings *SocketConfig `json:"sockopt"`
|
||||||
GRPCConfig *GRPCConfig `json:"grpcSettings"`
|
GRPCConfig *GRPCConfig `json:"grpcSettings"`
|
||||||
GUNConfig *GRPCConfig `json:"gunSettings"`
|
GUNConfig *GRPCConfig `json:"gunSettings"`
|
||||||
@ -818,8 +799,8 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
config.SecuritySettings = append(config.SecuritySettings, tm)
|
config.SecuritySettings = append(config.SecuritySettings, tm)
|
||||||
config.SecurityType = tm.Type
|
config.SecurityType = tm.Type
|
||||||
case "reality":
|
case "reality":
|
||||||
if config.ProtocolName != "tcp" && config.ProtocolName != "http" && config.ProtocolName != "grpc" && config.ProtocolName != "domainsocket" {
|
if config.ProtocolName != "tcp" && config.ProtocolName != "http" && config.ProtocolName != "grpc" {
|
||||||
return nil, errors.New("REALITY only supports TCP, H2, gRPC and DomainSocket for now.")
|
return nil, errors.New("REALITY only supports TCP, H2 and gRPC for now.")
|
||||||
}
|
}
|
||||||
if c.REALITYSettings == nil {
|
if c.REALITYSettings == nil {
|
||||||
return nil, errors.New(`REALITY: Empty "realitySettings".`)
|
return nil, errors.New(`REALITY: Empty "realitySettings".`)
|
||||||
@ -876,16 +857,6 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
Settings: serial.ToTypedMessage(ts),
|
Settings: serial.ToTypedMessage(ts),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if c.DSSettings != nil {
|
|
||||||
ds, err := c.DSSettings.Build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("Failed to build DomainSocket config.").Base(err)
|
|
||||||
}
|
|
||||||
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
|
|
||||||
ProtocolName: "domainsocket",
|
|
||||||
Settings: serial.ToTypedMessage(ds),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if c.GRPCConfig == nil {
|
if c.GRPCConfig == nil {
|
||||||
c.GRPCConfig = c.GUNConfig
|
c.GRPCConfig = c.GUNConfig
|
||||||
}
|
}
|
||||||
|
@ -553,9 +553,6 @@ func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
|
|||||||
if s.HTTPSettings == nil {
|
if s.HTTPSettings == nil {
|
||||||
s.HTTPSettings = t.HTTPConfig
|
s.HTTPSettings = t.HTTPConfig
|
||||||
}
|
}
|
||||||
if s.DSSettings == nil {
|
|
||||||
s.DSSettings = t.DSConfig
|
|
||||||
}
|
|
||||||
if s.HTTPUPGRADESettings == nil {
|
if s.HTTPUPGRADESettings == nil {
|
||||||
s.HTTPUPGRADESettings = t.HTTPUPGRADEConfig
|
s.HTTPUPGRADESettings = t.HTTPUPGRADEConfig
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ import (
|
|||||||
_ "github.com/xtls/xray-core/proxy/wireguard"
|
_ "github.com/xtls/xray-core/proxy/wireguard"
|
||||||
|
|
||||||
// Transports
|
// Transports
|
||||||
_ "github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
||||||
_ "github.com/xtls/xray-core/transport/internet/grpc"
|
_ "github.com/xtls/xray-core/transport/internet/grpc"
|
||||||
_ "github.com/xtls/xray-core/transport/internet/http"
|
_ "github.com/xtls/xray-core/transport/internet/http"
|
||||||
_ "github.com/xtls/xray-core/transport/internet/httpupgrade"
|
_ "github.com/xtls/xray-core/transport/internet/httpupgrade"
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package scenarios
|
package scenarios
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -20,7 +18,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
||||||
"github.com/xtls/xray-core/testing/servers/tcp"
|
"github.com/xtls/xray-core/testing/servers/tcp"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/headers/http"
|
"github.com/xtls/xray-core/transport/internet/headers/http"
|
||||||
tcptransport "github.com/xtls/xray-core/transport/internet/tcp"
|
tcptransport "github.com/xtls/xray-core/transport/internet/tcp"
|
||||||
)
|
)
|
||||||
@ -128,117 +125,3 @@ func TestHTTPConnectionHeader(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDomainSocket(t *testing.T) {
|
|
||||||
if runtime.GOOS == "windows" || runtime.GOOS == "android" {
|
|
||||||
t.Skip("Not supported on windows or android")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
tcpServer := tcp.Server{
|
|
||||||
MsgProcessor: xor,
|
|
||||||
}
|
|
||||||
dest, err := tcpServer.Start()
|
|
||||||
common.Must(err)
|
|
||||||
defer tcpServer.Close()
|
|
||||||
|
|
||||||
const dsPath = "/tmp/ds_scenario"
|
|
||||||
os.Remove(dsPath)
|
|
||||||
|
|
||||||
userID := protocol.NewID(uuid.New())
|
|
||||||
serverPort := tcp.PickPort()
|
|
||||||
serverConfig := &core.Config{
|
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
|
||||||
{
|
|
||||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
||||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(serverPort)}},
|
|
||||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
||||||
StreamSettings: &internet.StreamConfig{
|
|
||||||
Protocol: internet.TransportProtocol_DomainSocket,
|
|
||||||
TransportSettings: []*internet.TransportConfig{
|
|
||||||
{
|
|
||||||
Protocol: internet.TransportProtocol_DomainSocket,
|
|
||||||
Settings: serial.ToTypedMessage(&domainsocket.Config{
|
|
||||||
Path: dsPath,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
|
||||||
User: []*protocol.User{
|
|
||||||
{
|
|
||||||
Account: serial.ToTypedMessage(&vmess.Account{
|
|
||||||
Id: userID.String(),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
|
||||||
{
|
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
clientPort := tcp.PickPort()
|
|
||||||
clientConfig := &core.Config{
|
|
||||||
Inbound: []*core.InboundHandlerConfig{
|
|
||||||
{
|
|
||||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
|
||||||
PortList: &net.PortList{Range: []*net.PortRange{net.SinglePortRange(clientPort)}},
|
|
||||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
|
||||||
}),
|
|
||||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
|
||||||
Address: net.NewIPOrDomain(dest.Address),
|
|
||||||
Port: uint32(dest.Port),
|
|
||||||
NetworkList: &net.NetworkList{
|
|
||||||
Network: []net.Network{net.Network_TCP},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
|
||||||
{
|
|
||||||
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
|
||||||
Receiver: []*protocol.ServerEndpoint{
|
|
||||||
{
|
|
||||||
Address: net.NewIPOrDomain(net.LocalHostIP),
|
|
||||||
Port: uint32(serverPort),
|
|
||||||
User: []*protocol.User{
|
|
||||||
{
|
|
||||||
Account: serial.ToTypedMessage(&vmess.Account{
|
|
||||||
Id: userID.String(),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
SenderSettings: serial.ToTypedMessage(&proxyman.SenderConfig{
|
|
||||||
StreamSettings: &internet.StreamConfig{
|
|
||||||
Protocol: internet.TransportProtocol_DomainSocket,
|
|
||||||
TransportSettings: []*internet.TransportConfig{
|
|
||||||
{
|
|
||||||
Protocol: internet.TransportProtocol_DomainSocket,
|
|
||||||
Settings: serial.ToTypedMessage(&domainsocket.Config{
|
|
||||||
Path: dsPath,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
servers, err := InitializeServerConfigs(serverConfig, clientConfig)
|
|
||||||
common.Must(err)
|
|
||||||
defer CloseAllServers(servers)
|
|
||||||
|
|
||||||
if err := testTCPConn(clientPort, 1024, time.Second*2)(); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -42,8 +42,6 @@ func transportProtocolToString(protocol TransportProtocol) string {
|
|||||||
return "mkcp"
|
return "mkcp"
|
||||||
case TransportProtocol_WebSocket:
|
case TransportProtocol_WebSocket:
|
||||||
return "websocket"
|
return "websocket"
|
||||||
case TransportProtocol_DomainSocket:
|
|
||||||
return "domainsocket"
|
|
||||||
case TransportProtocol_HTTPUpgrade:
|
case TransportProtocol_HTTPUpgrade:
|
||||||
return "httpupgrade"
|
return "httpupgrade"
|
||||||
default:
|
default:
|
||||||
|
@ -24,14 +24,13 @@ const (
|
|||||||
type TransportProtocol int32
|
type TransportProtocol int32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TransportProtocol_TCP TransportProtocol = 0
|
TransportProtocol_TCP TransportProtocol = 0
|
||||||
TransportProtocol_UDP TransportProtocol = 1
|
TransportProtocol_UDP TransportProtocol = 1
|
||||||
TransportProtocol_MKCP TransportProtocol = 2
|
TransportProtocol_MKCP TransportProtocol = 2
|
||||||
TransportProtocol_WebSocket TransportProtocol = 3
|
TransportProtocol_WebSocket TransportProtocol = 3
|
||||||
TransportProtocol_HTTP TransportProtocol = 4
|
TransportProtocol_HTTP TransportProtocol = 4
|
||||||
TransportProtocol_DomainSocket TransportProtocol = 5
|
TransportProtocol_HTTPUpgrade TransportProtocol = 6
|
||||||
TransportProtocol_HTTPUpgrade TransportProtocol = 6
|
TransportProtocol_SplitHTTP TransportProtocol = 7
|
||||||
TransportProtocol_SplitHTTP TransportProtocol = 7
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for TransportProtocol.
|
// Enum value maps for TransportProtocol.
|
||||||
@ -42,19 +41,17 @@ var (
|
|||||||
2: "MKCP",
|
2: "MKCP",
|
||||||
3: "WebSocket",
|
3: "WebSocket",
|
||||||
4: "HTTP",
|
4: "HTTP",
|
||||||
5: "DomainSocket",
|
|
||||||
6: "HTTPUpgrade",
|
6: "HTTPUpgrade",
|
||||||
7: "SplitHTTP",
|
7: "SplitHTTP",
|
||||||
}
|
}
|
||||||
TransportProtocol_value = map[string]int32{
|
TransportProtocol_value = map[string]int32{
|
||||||
"TCP": 0,
|
"TCP": 0,
|
||||||
"UDP": 1,
|
"UDP": 1,
|
||||||
"MKCP": 2,
|
"MKCP": 2,
|
||||||
"WebSocket": 3,
|
"WebSocket": 3,
|
||||||
"HTTP": 4,
|
"HTTP": 4,
|
||||||
"DomainSocket": 5,
|
"HTTPUpgrade": 6,
|
||||||
"HTTPUpgrade": 6,
|
"SplitHTTP": 7,
|
||||||
"SplitHTTP": 7,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -821,32 +818,31 @@ var file_transport_internet_config_proto_rawDesc = []byte{
|
|||||||
0x6f, 0x63, 0x6b, 0x6f, 0x70, 0x74, 0x22, 0x2f, 0x0a, 0x0a, 0x54, 0x50, 0x72, 0x6f, 0x78, 0x79,
|
0x6f, 0x63, 0x6b, 0x6f, 0x70, 0x74, 0x22, 0x2f, 0x0a, 0x0a, 0x54, 0x50, 0x72, 0x6f, 0x78, 0x79,
|
||||||
0x4d, 0x6f, 0x64, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x66, 0x66, 0x10, 0x00, 0x12, 0x0a, 0x0a,
|
0x4d, 0x6f, 0x64, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x66, 0x66, 0x10, 0x00, 0x12, 0x0a, 0x0a,
|
||||||
0x06, 0x54, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x65, 0x64,
|
0x06, 0x54, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x65, 0x64,
|
||||||
0x69, 0x72, 0x65, 0x63, 0x74, 0x10, 0x02, 0x2a, 0x7a, 0x0a, 0x11, 0x54, 0x72, 0x61, 0x6e, 0x73,
|
0x69, 0x72, 0x65, 0x63, 0x74, 0x10, 0x02, 0x2a, 0x68, 0x0a, 0x11, 0x54, 0x72, 0x61, 0x6e, 0x73,
|
||||||
0x70, 0x6f, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x07, 0x0a, 0x03,
|
0x70, 0x6f, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x07, 0x0a, 0x03,
|
||||||
0x54, 0x43, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x55, 0x44, 0x50, 0x10, 0x01, 0x12, 0x08,
|
0x54, 0x43, 0x50, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x55, 0x44, 0x50, 0x10, 0x01, 0x12, 0x08,
|
||||||
0x0a, 0x04, 0x4d, 0x4b, 0x43, 0x50, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x57, 0x65, 0x62, 0x53,
|
0x0a, 0x04, 0x4d, 0x4b, 0x43, 0x50, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x57, 0x65, 0x62, 0x53,
|
||||||
0x6f, 0x63, 0x6b, 0x65, 0x74, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10,
|
0x6f, 0x63, 0x6b, 0x65, 0x74, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10,
|
||||||
0x04, 0x12, 0x10, 0x0a, 0x0c, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53, 0x6f, 0x63, 0x6b, 0x65,
|
0x04, 0x12, 0x0f, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65,
|
||||||
0x74, 0x10, 0x05, 0x12, 0x0f, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x55, 0x70, 0x67, 0x72, 0x61,
|
0x10, 0x06, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x70, 0x6c, 0x69, 0x74, 0x48, 0x54, 0x54, 0x50, 0x10,
|
||||||
0x64, 0x65, 0x10, 0x06, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x70, 0x6c, 0x69, 0x74, 0x48, 0x54, 0x54,
|
0x07, 0x2a, 0xa9, 0x01, 0x0a, 0x0e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53, 0x74, 0x72, 0x61,
|
||||||
0x50, 0x10, 0x07, 0x2a, 0xa9, 0x01, 0x0a, 0x0e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53, 0x74,
|
0x74, 0x65, 0x67, 0x79, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x53, 0x5f, 0x49, 0x53, 0x10, 0x00, 0x12,
|
||||||
0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x53, 0x5f, 0x49, 0x53, 0x10,
|
0x0a, 0x0a, 0x06, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x55,
|
||||||
0x00, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x10, 0x01, 0x12, 0x0b, 0x0a,
|
0x53, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x53, 0x45, 0x5f,
|
||||||
0x07, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x53,
|
0x49, 0x50, 0x36, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x34,
|
||||||
0x45, 0x5f, 0x49, 0x50, 0x36, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x55, 0x53, 0x45, 0x5f, 0x49,
|
0x36, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x36, 0x34, 0x10,
|
||||||
0x50, 0x34, 0x36, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x55, 0x53, 0x45, 0x5f, 0x49, 0x50, 0x36,
|
0x05, 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x10, 0x06, 0x12,
|
||||||
0x34, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x10,
|
0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x07, 0x12, 0x0d,
|
||||||
0x06, 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x10, 0x07,
|
0x0a, 0x09, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x36, 0x10, 0x08, 0x12, 0x0e, 0x0a,
|
||||||
0x12, 0x0d, 0x0a, 0x09, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x36, 0x10, 0x08, 0x12,
|
0x0a, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x36, 0x10, 0x09, 0x12, 0x0e, 0x0a,
|
||||||
0x0e, 0x0a, 0x0a, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x34, 0x36, 0x10, 0x09, 0x12,
|
0x0a, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x36, 0x34, 0x10, 0x0a, 0x42, 0x67, 0x0a,
|
||||||
0x0e, 0x0a, 0x0a, 0x46, 0x4f, 0x52, 0x43, 0x45, 0x5f, 0x49, 0x50, 0x36, 0x34, 0x10, 0x0a, 0x42,
|
0x1b, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
||||||
0x67, 0x0a, 0x1b, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e,
|
0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x2c,
|
||||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x50, 0x01,
|
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f,
|
||||||
0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c,
|
0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
||||||
0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e,
|
0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0xaa, 0x02, 0x17, 0x58,
|
||||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0xaa, 0x02,
|
0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e,
|
||||||
0x17, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e,
|
0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -14,7 +14,6 @@ enum TransportProtocol {
|
|||||||
MKCP = 2;
|
MKCP = 2;
|
||||||
WebSocket = 3;
|
WebSocket = 3;
|
||||||
HTTP = 4;
|
HTTP = 4;
|
||||||
DomainSocket = 5;
|
|
||||||
HTTPUpgrade = 6;
|
HTTPUpgrade = 6;
|
||||||
SplitHTTP = 7;
|
SplitHTTP = 7;
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package domainsocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
protocolName = "domainsocket"
|
|
||||||
sizeofSunPath = 108
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
|
||||||
path := c.Path
|
|
||||||
if path == "" {
|
|
||||||
return nil, errors.New("empty domain socket path")
|
|
||||||
}
|
|
||||||
if c.Abstract && path[0] != '@' {
|
|
||||||
path = "@" + path
|
|
||||||
}
|
|
||||||
if c.Abstract && c.Padding {
|
|
||||||
raw := []byte(path)
|
|
||||||
addr := make([]byte, sizeofSunPath)
|
|
||||||
copy(addr, raw)
|
|
||||||
path = string(addr)
|
|
||||||
}
|
|
||||||
return &net.UnixAddr{
|
|
||||||
Name: path,
|
|
||||||
Net: "unix",
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
|
|
||||||
return new(Config)
|
|
||||||
}))
|
|
||||||
}
|
|
@ -1,180 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
|
||||||
// versions:
|
|
||||||
// protoc-gen-go v1.34.2
|
|
||||||
// protoc v5.27.0
|
|
||||||
// source: transport/internet/domainsocket/config.proto
|
|
||||||
|
|
||||||
package domainsocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
reflect "reflect"
|
|
||||||
sync "sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Verify that this generated code is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
|
||||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
|
||||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
state protoimpl.MessageState
|
|
||||||
sizeCache protoimpl.SizeCache
|
|
||||||
unknownFields protoimpl.UnknownFields
|
|
||||||
|
|
||||||
// Path of the domain socket. This overrides the IP/Port parameter from
|
|
||||||
// upstream caller.
|
|
||||||
Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
|
|
||||||
// Abstract specifies whether to use abstract namespace or not.
|
|
||||||
// Traditionally Unix domain socket is file system based. Abstract domain
|
|
||||||
// socket can be used without acquiring file lock.
|
|
||||||
Abstract bool `protobuf:"varint,2,opt,name=abstract,proto3" json:"abstract,omitempty"`
|
|
||||||
// Some apps, eg. haproxy, use the full length of sockaddr_un.sun_path to
|
|
||||||
// connect(2) or bind(2) when using abstract UDS.
|
|
||||||
Padding bool `protobuf:"varint,3,opt,name=padding,proto3" json:"padding,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
|
||||||
*x = Config{}
|
|
||||||
if protoimpl.UnsafeEnabled {
|
|
||||||
mi := &file_transport_internet_domainsocket_config_proto_msgTypes[0]
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) String() string {
|
|
||||||
return protoimpl.X.MessageStringOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Config) ProtoMessage() {}
|
|
||||||
|
|
||||||
func (x *Config) ProtoReflect() protoreflect.Message {
|
|
||||||
mi := &file_transport_internet_domainsocket_config_proto_msgTypes[0]
|
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
|
||||||
if ms.LoadMessageInfo() == nil {
|
|
||||||
ms.StoreMessageInfo(mi)
|
|
||||||
}
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
return mi.MessageOf(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
|
|
||||||
func (*Config) Descriptor() ([]byte, []int) {
|
|
||||||
return file_transport_internet_domainsocket_config_proto_rawDescGZIP(), []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) GetPath() string {
|
|
||||||
if x != nil {
|
|
||||||
return x.Path
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) GetAbstract() bool {
|
|
||||||
if x != nil {
|
|
||||||
return x.Abstract
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *Config) GetPadding() bool {
|
|
||||||
if x != nil {
|
|
||||||
return x.Padding
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var File_transport_internet_domainsocket_config_proto protoreflect.FileDescriptor
|
|
||||||
|
|
||||||
var file_transport_internet_domainsocket_config_proto_rawDesc = []byte{
|
|
||||||
0x0a, 0x2c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65,
|
|
||||||
0x72, 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b, 0x65,
|
|
||||||
0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x24,
|
|
||||||
0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69,
|
|
||||||
0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f,
|
|
||||||
0x63, 0x6b, 0x65, 0x74, 0x22, 0x52, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12,
|
|
||||||
0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61,
|
|
||||||
0x74, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x62, 0x73, 0x74, 0x72, 0x61, 0x63, 0x74, 0x18, 0x02,
|
|
||||||
0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x62, 0x73, 0x74, 0x72, 0x61, 0x63, 0x74, 0x12, 0x18,
|
|
||||||
0x0a, 0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52,
|
|
||||||
0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x42, 0x8e, 0x01, 0x0a, 0x28, 0x63, 0x6f, 0x6d,
|
|
||||||
0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e,
|
|
||||||
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73,
|
|
||||||
0x6f, 0x63, 0x6b, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
|
|
||||||
0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f,
|
|
||||||
0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74,
|
|
||||||
0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b,
|
|
||||||
0x65, 0x74, 0xaa, 0x02, 0x24, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
|
||||||
0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x44, 0x6f, 0x6d,
|
|
||||||
0x61, 0x69, 0x6e, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
|
||||||
0x33,
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
file_transport_internet_domainsocket_config_proto_rawDescOnce sync.Once
|
|
||||||
file_transport_internet_domainsocket_config_proto_rawDescData = file_transport_internet_domainsocket_config_proto_rawDesc
|
|
||||||
)
|
|
||||||
|
|
||||||
func file_transport_internet_domainsocket_config_proto_rawDescGZIP() []byte {
|
|
||||||
file_transport_internet_domainsocket_config_proto_rawDescOnce.Do(func() {
|
|
||||||
file_transport_internet_domainsocket_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_domainsocket_config_proto_rawDescData)
|
|
||||||
})
|
|
||||||
return file_transport_internet_domainsocket_config_proto_rawDescData
|
|
||||||
}
|
|
||||||
|
|
||||||
var file_transport_internet_domainsocket_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
|
||||||
var file_transport_internet_domainsocket_config_proto_goTypes = []any{
|
|
||||||
(*Config)(nil), // 0: xray.transport.internet.domainsocket.Config
|
|
||||||
}
|
|
||||||
var file_transport_internet_domainsocket_config_proto_depIdxs = []int32{
|
|
||||||
0, // [0:0] is the sub-list for method output_type
|
|
||||||
0, // [0:0] is the sub-list for method input_type
|
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
|
||||||
0, // [0:0] is the sub-list for field type_name
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() { file_transport_internet_domainsocket_config_proto_init() }
|
|
||||||
func file_transport_internet_domainsocket_config_proto_init() {
|
|
||||||
if File_transport_internet_domainsocket_config_proto != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !protoimpl.UnsafeEnabled {
|
|
||||||
file_transport_internet_domainsocket_config_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
|
||||||
switch v := v.(*Config); i {
|
|
||||||
case 0:
|
|
||||||
return &v.state
|
|
||||||
case 1:
|
|
||||||
return &v.sizeCache
|
|
||||||
case 2:
|
|
||||||
return &v.unknownFields
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type x struct{}
|
|
||||||
out := protoimpl.TypeBuilder{
|
|
||||||
File: protoimpl.DescBuilder{
|
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
|
||||||
RawDescriptor: file_transport_internet_domainsocket_config_proto_rawDesc,
|
|
||||||
NumEnums: 0,
|
|
||||||
NumMessages: 1,
|
|
||||||
NumExtensions: 0,
|
|
||||||
NumServices: 0,
|
|
||||||
},
|
|
||||||
GoTypes: file_transport_internet_domainsocket_config_proto_goTypes,
|
|
||||||
DependencyIndexes: file_transport_internet_domainsocket_config_proto_depIdxs,
|
|
||||||
MessageInfos: file_transport_internet_domainsocket_config_proto_msgTypes,
|
|
||||||
}.Build()
|
|
||||||
File_transport_internet_domainsocket_config_proto = out.File
|
|
||||||
file_transport_internet_domainsocket_config_proto_rawDesc = nil
|
|
||||||
file_transport_internet_domainsocket_config_proto_goTypes = nil
|
|
||||||
file_transport_internet_domainsocket_config_proto_depIdxs = nil
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package xray.transport.internet.domainsocket;
|
|
||||||
option csharp_namespace = "Xray.Transport.Internet.DomainSocket";
|
|
||||||
option go_package = "github.com/xtls/xray-core/transport/internet/domainsocket";
|
|
||||||
option java_package = "com.xray.transport.internet.domainsocket";
|
|
||||||
option java_multiple_files = true;
|
|
||||||
|
|
||||||
message Config {
|
|
||||||
// Path of the domain socket. This overrides the IP/Port parameter from
|
|
||||||
// upstream caller.
|
|
||||||
string path = 1;
|
|
||||||
// Abstract specifies whether to use abstract namespace or not.
|
|
||||||
// Traditionally Unix domain socket is file system based. Abstract domain
|
|
||||||
// socket can be used without acquiring file lock.
|
|
||||||
bool abstract = 2;
|
|
||||||
// Some apps, eg. haproxy, use the full length of sockaddr_un.sun_path to
|
|
||||||
// connect(2) or bind(2) when using abstract UDS.
|
|
||||||
bool padding = 3;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
//go:build !windows && !wasm
|
|
||||||
// +build !windows,!wasm
|
|
||||||
|
|
||||||
package domainsocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/reality"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/tls"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
|
||||||
settings := streamSettings.ProtocolSettings.(*Config)
|
|
||||||
addr, err := settings.GetUnixAddr()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := net.DialUnix("unix", nil, addr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("failed to dial unix: ", settings.Path).Base(err).AtWarning()
|
|
||||||
}
|
|
||||||
|
|
||||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
||||||
return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil
|
|
||||||
} else if config := reality.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
||||||
return reality.UClient(conn, config, ctx, dest)
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package domainsocket
|
|
||||||
|
|
||||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
|
@ -1,141 +0,0 @@
|
|||||||
//go:build !windows && !wasm
|
|
||||||
// +build !windows,!wasm
|
|
||||||
|
|
||||||
package domainsocket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
gotls "crypto/tls"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
goreality "github.com/xtls/reality"
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/reality"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/tls"
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Listener struct {
|
|
||||||
addr *net.UnixAddr
|
|
||||||
ln net.Listener
|
|
||||||
tlsConfig *gotls.Config
|
|
||||||
realityConfig *goreality.Config
|
|
||||||
config *Config
|
|
||||||
addConn internet.ConnHandler
|
|
||||||
locker *fileLocker
|
|
||||||
}
|
|
||||||
|
|
||||||
func Listen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, handler internet.ConnHandler) (internet.Listener, error) {
|
|
||||||
settings := streamSettings.ProtocolSettings.(*Config)
|
|
||||||
addr, err := settings.GetUnixAddr()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
unixListener, err := net.ListenUnix("unix", addr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("failed to listen domain socket").Base(err).AtWarning()
|
|
||||||
}
|
|
||||||
|
|
||||||
ln := &Listener{
|
|
||||||
addr: addr,
|
|
||||||
ln: unixListener,
|
|
||||||
config: settings,
|
|
||||||
addConn: handler,
|
|
||||||
}
|
|
||||||
|
|
||||||
if !settings.Abstract {
|
|
||||||
ln.locker = &fileLocker{
|
|
||||||
path: settings.Path + ".lock",
|
|
||||||
}
|
|
||||||
if err := ln.locker.Acquire(); err != nil {
|
|
||||||
unixListener.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
||||||
ln.tlsConfig = config.GetTLSConfig()
|
|
||||||
}
|
|
||||||
if config := reality.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
||||||
ln.realityConfig = config.GetREALITYConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
go ln.run()
|
|
||||||
|
|
||||||
return ln, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ln *Listener) Addr() net.Addr {
|
|
||||||
return ln.addr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ln *Listener) Close() error {
|
|
||||||
if ln.locker != nil {
|
|
||||||
ln.locker.Release()
|
|
||||||
}
|
|
||||||
return ln.ln.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ln *Listener) run() {
|
|
||||||
for {
|
|
||||||
conn, err := ln.ln.Accept()
|
|
||||||
if err != nil {
|
|
||||||
if strings.Contains(err.Error(), "closed") {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
errors.LogWarningInner(context.Background(), err, "failed to accepted raw connections")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
if ln.tlsConfig != nil {
|
|
||||||
conn = tls.Server(conn, ln.tlsConfig)
|
|
||||||
} else if ln.realityConfig != nil {
|
|
||||||
if conn, err = reality.Server(conn, ln.realityConfig); err != nil {
|
|
||||||
errors.LogInfo(context.Background(), err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ln.addConn(stat.Connection(conn))
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type fileLocker struct {
|
|
||||||
path string
|
|
||||||
file *os.File
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fl *fileLocker) Acquire() error {
|
|
||||||
f, err := os.Create(fl.path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := unix.Flock(int(f.Fd()), unix.LOCK_EX); err != nil {
|
|
||||||
f.Close()
|
|
||||||
return errors.New("failed to lock file: ", fl.path).Base(err)
|
|
||||||
}
|
|
||||||
fl.file = f
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fl *fileLocker) Release() {
|
|
||||||
if err := unix.Flock(int(fl.file.Fd()), unix.LOCK_UN); err != nil {
|
|
||||||
errors.LogInfoInner(context.Background(), err, "failed to unlock file: ", fl.path)
|
|
||||||
}
|
|
||||||
if err := fl.file.Close(); err != nil {
|
|
||||||
errors.LogInfoInner(context.Background(), err, "failed to close file: ", fl.path)
|
|
||||||
}
|
|
||||||
if err := os.Remove(fl.path); err != nil {
|
|
||||||
errors.LogInfoInner(context.Background(), err, "failed to remove file: ", fl.path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
common.Must(internet.RegisterTransportListener(protocolName, Listen))
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
//go:build !windows && !android
|
|
||||||
// +build !windows,!android
|
|
||||||
|
|
||||||
package domainsocket_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
|
||||||
. "github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestListen(t *testing.T) {
|
|
||||||
ctx := context.Background()
|
|
||||||
streamSettings := &internet.MemoryStreamConfig{
|
|
||||||
ProtocolName: "domainsocket",
|
|
||||||
ProtocolSettings: &Config{
|
|
||||||
Path: "/tmp/ts3",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn stat.Connection) {
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
b := buf.New()
|
|
||||||
defer b.Release()
|
|
||||||
common.Must2(b.ReadFrom(conn))
|
|
||||||
b.WriteString("Response")
|
|
||||||
|
|
||||||
common.Must2(conn.Write(b.Bytes()))
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
defer listener.Close()
|
|
||||||
|
|
||||||
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
|
||||||
common.Must(err)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
common.Must2(conn.Write([]byte("Request")))
|
|
||||||
|
|
||||||
b := buf.New()
|
|
||||||
defer b.Release()
|
|
||||||
common.Must2(b.ReadFrom(conn))
|
|
||||||
|
|
||||||
if b.String() != "RequestResponse" {
|
|
||||||
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestListenAbstract(t *testing.T) {
|
|
||||||
if runtime.GOOS != "linux" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
streamSettings := &internet.MemoryStreamConfig{
|
|
||||||
ProtocolName: "domainsocket",
|
|
||||||
ProtocolSettings: &Config{
|
|
||||||
Path: "/tmp/ts3",
|
|
||||||
Abstract: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn stat.Connection) {
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
b := buf.New()
|
|
||||||
defer b.Release()
|
|
||||||
common.Must2(b.ReadFrom(conn))
|
|
||||||
b.WriteString("Response")
|
|
||||||
|
|
||||||
common.Must2(conn.Write(b.Bytes()))
|
|
||||||
})
|
|
||||||
common.Must(err)
|
|
||||||
defer listener.Close()
|
|
||||||
|
|
||||||
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
|
||||||
common.Must(err)
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
common.Must2(conn.Write([]byte("Request")))
|
|
||||||
|
|
||||||
b := buf.New()
|
|
||||||
defer b.Release()
|
|
||||||
common.Must2(b.ReadFrom(conn))
|
|
||||||
|
|
||||||
if b.String() != "RequestResponse" {
|
|
||||||
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user