1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/transport/internet/domainsocket/dial.go

37 lines
972 B
Go
Raw Normal View History

2021-10-28 06:34:19 -04:00
//go:build !windows && !wasm
// +build !windows,!wasm
2018-04-12 11:44:23 -04:00
2017-11-03 08:02:05 -04:00
package domainsocket
2017-11-22 08:53:22 -05:00
import (
"context"
2018-04-09 11:09:24 -04:00
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/transport/internet"
"github.com/v2fly/v2ray-core/v5/transport/internet/tls"
2017-11-22 08:53:22 -05:00
)
2017-11-03 08:02:05 -04:00
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
settings := streamSettings.ProtocolSettings.(*Config)
2018-04-09 11:09:24 -04:00
addr, err := settings.GetUnixAddr()
2017-11-22 08:53:22 -05:00
if err != nil {
return nil, err
}
2018-04-09 11:09:24 -04:00
conn, err := net.DialUnix("unix", nil, addr)
2017-11-22 08:53:22 -05:00
if err != nil {
2018-04-09 11:09:24 -04:00
return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning()
}
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
2018-04-09 11:09:24 -04:00
return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil
2017-11-22 08:53:22 -05:00
}
2018-04-09 11:09:24 -04:00
return conn, nil
}
func init() {
2018-08-06 07:48:35 -04:00
common.Must(internet.RegisterTransportDialer(protocolName, Dial))
2017-11-03 08:02:05 -04:00
}