1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| //go:build !windows && !wasm
| // +build !windows,!wasm
|
| package domainsocket
|
| import (
| "context"
|
| "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"
| )
|
| func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) {
| 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
| }
|
| return conn, nil
| }
|
| func init() {
| common.Must(internet.RegisterTransportDialer(protocolName, Dial))
| }
|
|