github.com/moqsien/xraycore@v1.8.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/moqsien/xraycore/common" 10 "github.com/moqsien/xraycore/common/net" 11 "github.com/moqsien/xraycore/transport/internet" 12 "github.com/moqsien/xraycore/transport/internet/reality" 13 "github.com/moqsien/xraycore/transport/internet/stat" 14 "github.com/moqsien/xraycore/transport/internet/tls" 15 ) 16 17 func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) { 18 settings := streamSettings.ProtocolSettings.(*Config) 19 addr, err := settings.GetUnixAddr() 20 if err != nil { 21 return nil, err 22 } 23 24 conn, err := net.DialUnix("unix", nil, addr) 25 if err != nil { 26 return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning() 27 } 28 29 if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { 30 return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil 31 } else if config := reality.ConfigFromStreamSettings(streamSettings); config != nil { 32 return reality.UClient(conn, config, ctx, dest) 33 } 34 35 return conn, nil 36 } 37 38 func init() { 39 common.Must(internet.RegisterTransportDialer(protocolName, Dial)) 40 }