mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
// +build !windows
|
|
// +build !wasm
|
|
// +build !confonly
|
|
|
|
package domainsocket
|
|
|
|
import (
|
|
"context"
|
|
|
|
"v2ray.com/core/common"
|
|
"v2ray.com/core/common/net"
|
|
"v2ray.com/core/transport/internet"
|
|
"v2ray.com/core/transport/internet/tls"
|
|
"v2ray.com/core/transport/internet/xtls"
|
|
)
|
|
|
|
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.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))
|
|
}
|