1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/transport/internet/domainsocket/dial.go
2021-02-17 04:31:50 +08:00

38 lines
973 B
Go

// +build !windows
// +build !wasm
// +build !confonly
package domainsocket
import (
"context"
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/transport/internet"
"github.com/v2fly/v2ray-core/v4/transport/internet/tls"
)
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
}
return conn, nil
}
func init() {
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}