github.com/moqsien/xraycore@v1.8.5/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/moqsien/xraycore/common/net" 9 "github.com/moqsien/xraycore/transport/internet" 10 "github.com/moqsien/xraycore/transport/internet/stat" 11 ) 12 13 func (h *Handler) getUoTConnection(ctx context.Context, dest net.Destination) (stat.Connection, error) { 14 if dest.Address == nil { 15 return nil, newError("nil destination address") 16 } 17 if !dest.Address.Family().IsDomain() { 18 return nil, os.ErrInvalid 19 } 20 var uotVersion int 21 if dest.Address.Domain() == uot.MagicAddress { 22 uotVersion = uot.Version 23 } else if dest.Address.Domain() == uot.LegacyMagicAddress { 24 uotVersion = uot.LegacyVersion 25 } else { 26 return nil, os.ErrInvalid 27 } 28 packetConn, err := internet.ListenSystemPacket(ctx, &net.UDPAddr{IP: net.AnyIP.IP(), Port: 0}, h.streamSettings.SocketSettings) 29 if err != nil { 30 return nil, newError("unable to listen socket").Base(err) 31 } 32 conn := uot.NewServerConn(packetConn, uotVersion) 33 return h.getStatCouterConnection(conn), nil 34 }