github.com/xraypb/xray-core@v1.6.6/app/proxyman/outbound/uot.go (about)

     1  package outbound
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/sagernet/sing/common/uot"
     8  	"github.com/xraypb/xray-core/common/net"
     9  	"github.com/xraypb/xray-core/transport/internet"
    10  	"github.com/xraypb/xray-core/transport/internet/stat"
    11  )
    12  
    13  func (h *Handler) getUoTConnection(ctx context.Context, dest net.Destination) (stat.Connection, error) {
    14  	if !dest.Address.Family().IsDomain() || dest.Address.Domain() != uot.UOTMagicAddress {
    15  		return nil, os.ErrInvalid
    16  	}
    17  	packetConn, err := internet.ListenSystemPacket(ctx, &net.UDPAddr{IP: net.AnyIP.IP(), Port: 0}, h.streamSettings.SocketSettings)
    18  	if err != nil {
    19  		return nil, newError("unable to listen socket").Base(err)
    20  	}
    21  	conn := uot.NewServerConn(packetConn)
    22  	return h.getStatCouterConnection(conn), nil
    23  }