mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-17 20:43:02 +00:00
e93da4bd02
* Increase some tls test timeout * Fix TestUserValidator * Change all tests to VMessAEAD Old VMess MD5 tests will be rejected and fail in 2022 * Chore: auto format code
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
//go:build !windows && !wasm
|
|
// +build !windows,!wasm
|
|
|
|
package domainsocket
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
|
"github.com/xtls/xray-core/transport/internet/tls"
|
|
"github.com/xtls/xray-core/transport/internet/xtls"
|
|
)
|
|
|
|
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, 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
|
|
} else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil {
|
|
return xtls.Client(conn, config.GetXTLSConfig(xtls.WithDestination(dest))), nil
|
|
}
|
|
|
|
return conn, nil
|
|
}
|
|
|
|
func init() {
|
|
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
|
|
}
|