github.com/imannamdari/v2ray-core/v5@v5.0.5/transport/internet/domainsocket/dial.go (about) 1 //go:build !windows && !wasm 2 // +build !windows,!wasm 3 4 package domainsocket 5 6 import ( 7 "context" 8 9 "github.com/imannamdari/v2ray-core/v5/common" 10 "github.com/imannamdari/v2ray-core/v5/common/net" 11 "github.com/imannamdari/v2ray-core/v5/transport/internet" 12 "github.com/imannamdari/v2ray-core/v5/transport/internet/tls" 13 ) 14 15 func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { 16 settings := streamSettings.ProtocolSettings.(*Config) 17 addr, err := settings.GetUnixAddr() 18 if err != nil { 19 return nil, err 20 } 21 22 conn, err := net.DialUnix("unix", nil, addr) 23 if err != nil { 24 return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning() 25 } 26 27 if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { 28 return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil 29 } 30 31 return conn, nil 32 } 33 34 func init() { 35 common.Must(internet.RegisterTransportDialer(protocolName, Dial)) 36 }