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