github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/transport/internet/udp/dialer.go (about)

     1  package udp
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/xtls/xray-core/common"
     7  	"github.com/xtls/xray-core/common/net"
     8  	"github.com/xtls/xray-core/transport/internet"
     9  	"github.com/xtls/xray-core/transport/internet/stat"
    10  )
    11  
    12  func init() {
    13  	common.Must(internet.RegisterTransportDialer(protocolName,
    14  		func(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
    15  			var sockopt *internet.SocketConfig
    16  			if streamSettings != nil {
    17  				sockopt = streamSettings.SocketSettings
    18  			}
    19  			conn, err := internet.DialSystem(ctx, dest, sockopt)
    20  			if err != nil {
    21  				return nil, err
    22  			}
    23  			// TODO: handle dialer options
    24  			return stat.Connection(conn), nil
    25  		}))
    26  }