2021-09-20 16:00:55 +03:00
|
|
|
//go:build !windows && !wasm
|
|
|
|
// +build !windows,!wasm
|
2020-11-25 14:01:53 +03:00
|
|
|
|
|
|
|
package domainsocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/common"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
2023-02-15 19:07:12 +03:00
|
|
|
"github.com/xtls/xray-core/transport/internet/reality"
|
2021-12-15 03:28:47 +03:00
|
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
2020-12-04 04:36:16 +03:00
|
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
2021-09-20 15:11:21 +03:00
|
|
|
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
2020-11-25 14:01:53 +03:00
|
|
|
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, newError("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
|
2023-02-15 19:07:12 +03:00
|
|
|
} else if config := reality.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
|
|
return reality.UClient(conn, config, ctx, dest)
|
2020-11-25 14:01:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return conn, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
|
|
|
|
}
|