github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/domainsocket/dial.go (about)

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