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.
Xray-core/transport/internet/domainsocket/dial.go

41 lines
1.2 KiB

//go:build !windows && !wasm
// +build !windows,!wasm
4 years ago
package domainsocket
import (
"context"
4 years ago
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/reality"
"github.com/xtls/xray-core/transport/internet/stat"
4 years ago
"github.com/xtls/xray-core/transport/internet/tls"
4 years ago
)
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
4 years ago
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 := reality.ConfigFromStreamSettings(streamSettings); config != nil {
return reality.UClient(conn, config, ctx, dest)
4 years ago
}
return conn, nil
}
func init() {
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
}