mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 05:03:20 +00:00
079d0bd8a9
* Refactor log * Add new log methods * Fix logger test * Change all logging code * Clean up pathObj * Rebase to latest main * Remove invoking method name after the dot
36 lines
1 KiB
Go
36 lines
1 KiB
Go
package outbound
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/sagernet/sing/common/uot"
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
|
)
|
|
|
|
func (h *Handler) getUoTConnection(ctx context.Context, dest net.Destination) (stat.Connection, error) {
|
|
if dest.Address == nil {
|
|
return nil, errors.New("nil destination address")
|
|
}
|
|
if !dest.Address.Family().IsDomain() {
|
|
return nil, os.ErrInvalid
|
|
}
|
|
var uotVersion int
|
|
if dest.Address.Domain() == uot.MagicAddress {
|
|
uotVersion = uot.Version
|
|
} else if dest.Address.Domain() == uot.LegacyMagicAddress {
|
|
uotVersion = uot.LegacyVersion
|
|
} else {
|
|
return nil, os.ErrInvalid
|
|
}
|
|
packetConn, err := internet.ListenSystemPacket(ctx, &net.UDPAddr{IP: net.AnyIP.IP(), Port: 0}, h.streamSettings.SocketSettings)
|
|
if err != nil {
|
|
return nil, errors.New("unable to listen socket").Base(err)
|
|
}
|
|
conn := uot.NewServerConn(packetConn, uotVersion)
|
|
return h.getStatCouterConnection(conn), nil
|
|
}
|