Compare commits

..
8 Commits
Author SHA1 Message Date
Meo597 fa4aeb1a56 alias udp:// 2026-11-15 21:10:30 +08:00
Meo597 ddfac74131 add udp+local 2026-11-15 19:32:45 +08:00
𐲓𐳛𐳪𐳂𐳐 𐲀𐳢𐳦𐳫𐳢 𐲥𐳔𐳛𐳪𐳌𐳑𐳖𐳇andGitHub c456141815 Build: Build list optimization; build tags clean-up (#5824)
https://github.com/XTLS/Xray-core/pull/5824#issuecomment-6796919801
2026-11-11 13:42:32 +00:00
LjhAUMEMandGitHub f082058590 Hysteria transport: Proper Brutal behavior; Bump quic-go (#7356)
Fixes https://github.com/XTLS/Xray-core/issues/7353
2026-11-11 08:45:54 +00:00
e184d774a2 Metrics: Close HTTP connections when stopping Xray Instance (#7361)
https://github.com/XTLS/Xray-core/pull/7361#pullrequestreview-5840920982

---------

Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
2026-11-11 08:23:01 +00:00
LjhAUMEMandGitHub 14df0738f3 XDNS finalmask: Implement worker for TCP resolver (#7354)
Fixes https://github.com/XTLS/Xray-core/issues/7349
2026-11-11 08:12:22 +00:00
36cc9ff510 VLESS Multiplex (mux.cool): Raise maxConcurrency to 128 only for XDRIVE (#7375)
Closes https://github.com/XTLS/Xray-core/issues/7358#issuecomment-6785007489 and https://github.com/XTLS/Xray-core/pull/7365#issuecomment-6785026850

---------

Co-authored-by: Ivan Zorin <creator@localzet.com>
2026-11-11 07:37:36 +00:00
c43ee98ec7 VLESS Multiplex (mux.cool): Replace MutexWriter with buf.BufferedWriter (#7359)
Fixes https://github.com/XTLS/Xray-core/pull/7355#issuecomment-6738888441

---------

Co-authored-by: Medium1992 <Medium1992@users.noreply.github.com>
2026-11-10 22:13:21 +00:00
46 changed files with 411 additions and 252 deletions
+1 -2
View File
@@ -1,5 +1,6 @@
{
"android-arm64": { "friendlyName": "android-arm64-v8a" },
"android-amd64": { "friendlyName": "android-amd64" },
"darwin-amd64": { "friendlyName": "macos-64" },
"darwin-arm64": { "friendlyName": "macos-arm64-v8a" },
"freebsd-386": { "friendlyName": "freebsd-32" },
@@ -14,9 +15,7 @@
"linux-arm7": { "friendlyName": "linux-arm32-v7a" },
"linux-mips64le": { "friendlyName": "linux-mips64le" },
"linux-mips64": { "friendlyName": "linux-mips64" },
"linux-mipslesoftfloat": { "friendlyName": "linux-mips32le-softfloat" },
"linux-mipsle": { "friendlyName": "linux-mips32le" },
"linux-mipssoftfloat": { "friendlyName": "linux-mips32-softfloat" },
"linux-mips": { "friendlyName": "linux-mips32" },
"linux-ppc64le": { "friendlyName": "linux-ppc64le" },
"linux-ppc64": { "friendlyName": "linux-ppc64" },
+8 -13
View File
@@ -1,17 +1,14 @@
name: Build and Release for Windows 7
# Pre-compiling support removal since 1.29
on:
workflow_dispatch:
release:
types: [published]
push:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-assets:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- name: Restore Geodat Cache
uses: actions/cache/restore@v6
@@ -115,8 +112,6 @@ jobs:
COMMID=$(git describe --always --dirty)
echo 'Building Xray for Windows 7...'
go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
# The line below is for without running conhost.exe version. Commented for not being used. Provided for reference.
# go build -o build_assets/wxray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-H windowsgui -X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
- name: Restore Geodat Cache
uses: actions/cache/restore@v6
@@ -152,6 +147,13 @@ jobs:
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
- name: Upload files to Artifacts
uses: actions/upload-artifact@v7
with:
name: Xray-${{ env.ASSET_NAME }}
path: |
./build_assets/*
- name: Create ZIP archive
if: github.event_name == 'release'
shell: bash
@@ -175,10 +177,3 @@ jobs:
file: ./Xray-${{ env.ASSET_NAME }}.zip*
tag: ${{ github.ref }}
file_glob: true
- name: Upload files to Artifacts
uses: actions/upload-artifact@v7
with:
name: Xray-${{ env.ASSET_NAME }}
path: |
./build_assets/*
+178 -85
View File
@@ -79,86 +79,23 @@ jobs:
contents: write
strategy:
matrix:
# Include amd64 on all platforms.
goos: [windows, freebsd, openbsd, linux, darwin]
goarch: [amd64, 386]
# Include amd64 and arm64 on all platforms.
goos: [windows, freebsd, openbsd, linux, darwin, android]
goarch: [amd64, arm64]
patch-assetname: [""]
exclude:
# Exclude i386 on darwin
- goarch: 386
goos: darwin
include:
# BEGIN MacOS ARM64
- goos: darwin
goarch: arm64
# END MacOS ARM64
# BEGIN Linux ARM 5 6 7
- goos: linux
goarch: arm
goarm: 7
- goos: linux
goarch: arm
goarm: 6
- goos: linux
goarch: arm
goarm: 5
# END Linux ARM 5 6 7
# BEGIN Android ARM 8
- goos: android
goarch: arm64
# END Android ARM 8
# BEGIN Android AMD64
- goos: android
goarch: amd64
patch-assetname: android-amd64
# END Android AMD64
# Windows ARM
- goos: windows
goarch: arm64
# BEGIN Other architectures
# BEGIN riscv64 & ARM64 & LOONG64
- goos: linux
goarch: arm64
- goos: linux
goarch: riscv64
- goos: linux
goarch: loong64
# END riscv64 & ARM64 & LOONG64
# BEGIN MIPS
- goos: linux
goarch: mips64
- goos: linux
goarch: mips64le
- goos: linux
goarch: mipsle
- goos: linux
goarch: mips
# END MIPS
# BEGIN PPC
# BEGIN Linux specified
- goos: linux
goarch: ppc64
- goos: linux
goarch: ppc64le
# END PPC
# BEGIN FreeBSD ARM
- goos: freebsd
goarch: arm64
- goos: freebsd
goarch: arm
goarm: 7
# END FreeBSD ARM
# BEGIN S390X
- goos: linux
goarch: s390x
# END S390X
# END Other architectures
# BEGIN OPENBSD ARM
- goos: openbsd
goarch: arm64
- goos: openbsd
goarch: arm
goarm: 7
# END OPENBSD ARM
- goos: linux
goarch: riscv64
- goos: linux
goarch: loong64
# END Linux specified
fail-fast: false
runs-on: ubuntu-latest
@@ -166,7 +103,6 @@ jobs:
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: 0
steps:
- name: Checkout codebase
@@ -188,8 +124,8 @@ jobs:
- name: Show workflow information
run: |
_NAME=${{ matrix.patch-assetname }}
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH\"].friendlyName" -r < .github/build/friendly-filenames.json)
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
- name: Set up Go
@@ -203,6 +139,18 @@ jobs:
- name: Build Xray
run: |
case "${GOARCH}:${GOOS}" in
# Special processing for x86-64 and ARM64
amd64:windows|amd64:darwin)
GOAMD64="v2"
;;
arm64:windows)
GOARM64="v8.2"
;;
arm64:darwin)
GOARM64="v8.4"
;;
esac
mkdir -p build_assets
COMMID=$(git describe --always --dirty)
if [[ ${GOOS} == 'windows' ]]; then
@@ -215,13 +163,7 @@ jobs:
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid= -checklinkname=0 -extldflags=-Wl,--pack-dyn-relocs=android" -v ./main
else
echo 'Building Xray...'
if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
else
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
fi
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
fi
- name: Restore Geodat Cache
@@ -248,9 +190,6 @@ jobs:
if [[ ${GOARCH} == 'amd64' ]]; then
mv resources/wintun/bin/amd64/wintun.dll build_assets/
fi
if [[ ${GOARCH} == '386' ]]; then
mv resources/wintun/bin/x86/wintun.dll build_assets/
fi
if [[ ${GOARCH} == 'arm64' ]]; then
mv resources/wintun/bin/arm64/wintun.dll build_assets/
fi
@@ -262,6 +201,13 @@ jobs:
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
- name: Upload files to Artifacts
uses: actions/upload-artifact@v7
with:
name: Xray-${{ env.ASSET_NAME }}
path: |
./build_assets/*
- name: Create ZIP archive
if: github.event_name == 'release'
shell: bash
@@ -286,9 +232,156 @@ jobs:
tag: ${{ github.ref }}
file_glob: true
build-release-only:
needs: check-assets
permissions:
contents: write
strategy:
matrix:
# First batch (since Go 1.29) of removal:
# x86: windows, linux, freebsd, openbsd
# arm: linux(v5), linux(v6)
# other: linux(mips), linux(mips64), linux(mips64le)
# Second batch (needs discussion) of removal
# arm(v7): freebsd, openbsd, linux
# other: linux(mipsle)
goos: [windows, freebsd, openbsd, linux]
goarch: [arm, 386]
goarm: [7]
exclude:
- goos: windows
goarch: arm
include:
# Second batch of removal [In the future]
- goos: linux
goarch: mipsle
# END of second batch
# First batch of removal [Go 1.29]
- goos: linux
goarch: arm
goarm: 5
- goos: linux
goarch: arm
goarm: 6
- goos: linux
goarch: mips
- goos: linux
goarch: mips64
- goos: linux
goarch: mips64le
# END of first batch
fail-fast: false
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: 0
steps:
- name: Checkout codebase
uses: actions/checkout@v7
- name: Show workflow information
run: |
_NAME=${{ matrix.patch-assetname }}
if [[ ${GOARCH} == 'arm' ]]; then
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM\"].friendlyName" -r < .github/build/friendly-filenames.json)
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, RELEASE_NAME: $_NAME"
else
echo "GOARM=''" >> $GITHUB_ENV
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH\"].friendlyName" -r < .github/build/friendly-filenames.json)
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
fi
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
check-latest: true
- name: Get project dependencies
run: go mod download
- name: Build Xray
run: |
mkdir -p build_assets
COMMID=$(git describe --always --dirty)
if [[ ${GOOS} == 'windows' ]]; then
echo 'Building Xray for Windows...'
go build -o build_assets/xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
else
echo 'Building Xray...'
if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
go build -o build_assets/xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
echo 'Building soft-float Xray for MIPS/MIPSLE 32-bit...'
GOMIPS=softfloat go build -o build_assets/xray_softfloat -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
else
go build -o build_assets/xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=${COMMID} -s -w -buildid=" -v ./main
fi
fi
- name: Restore Geodat Cache
uses: actions/cache/restore@v6
with:
path: resources
key: xray-geodat-
- name: Restore Wintun Cache
if: matrix.goos == 'windows'
uses: actions/cache/restore@v6
with:
path: resources
key: xray-wintun-
- name: Add additional assets into package
run: |
mv -f resources/geo* build_assets/
if [[ ${GOOS} == 'windows' ]]; then
cp .github/build/windows/* build_assets/
fi
if [[ ${GOOS} == 'windows' ]]; then
echo 'Adding Wintun into packages'
if [[ ${GOARCH} == '386' ]]; then
mv resources/wintun/bin/x86/wintun.dll build_assets/
fi
mv resources/wintun/LICENSE.txt build_assets/LICENSE-Wintun
fi
- name: Copy README.md & LICENSE
run: |
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
- name: Upload files to Artifacts
uses: actions/upload-artifact@v7
with:
name: Xray-${{ env.ASSET_NAME }}
path: |
./build_assets/*
- name: Create ZIP archive
if: github.event_name == 'release'
shell: bash
run: |
pushd build_assets || exit 1
touch -mt $(date +%Y01010000) *
zip -9vr ../Xray-${{ env.ASSET_NAME }}.zip .
popd || exit 1
FILE=./Xray-${{ env.ASSET_NAME }}.zip
DGST=$FILE.dgst
for METHOD in {"md5","sha1","sha256","sha512"}
do
openssl dgst -$METHOD $FILE | sed 's/([^)]*)//g' >>$DGST
done
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
if: github.event_name == 'release'
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./Xray-${{ env.ASSET_NAME }}.zip*
tag: ${{ github.ref }}
file_glob: true
+19 -2
View File
@@ -231,6 +231,20 @@ Make sure that you are using the same Go version, and remember to set the git co
CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
```
For Windows (x86-64 and AArch64, not win7):
```bash
GOOS=windows GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=0 go build -o xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=windows GOARCH=arm64 GOARM64=v8.2 CGO_ENABLED=0 go build -o xray.exe -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
```
For macOS:
```bash
GOOS=darwin GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=darwin GOARCH=arm64 GOARM64=v8.4 CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
```
For Android:
```bash
@@ -238,10 +252,13 @@ GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=/path/to/aarch64-linux-android24-clan
GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC=/path/to/x86_64-linux-android24-clang go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid= -checklinkname=0 -extldflags=-Wl,--pack-dyn-relocs=android" -v ./main
```
If you are compiling a 32-bit MIPS/MIPSLE target, use this command instead:
For Linux (MIPS32 and MIPS32LE):
```bash
CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="-l=4" -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=linux GOARCH=mips GOMIPS=hardfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=linux GOARCH=mipsle GOMIPS=hardfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
GOOS=linux GOARCH=mipsle GOMIPS=softfloat CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags="-X github.com/xtls/xray-core/core.build=REPLACE -s -w -buildid=" -v ./main
```
## Stargazers over time
+4
View File
@@ -68,6 +68,10 @@ func NewServer(ctx context.Context, dest net.Destination, dispatcher routing.Dis
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
return NewTCPLocalNameServer(u, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "udp"): // UDP DNS Remote mode
return NewUDPNameServer(u, dispatcher, false, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.Scheme, "udp+local"): // UDP DNS Local mode
return NewUDPNameServer(u, dispatcher, true, disableCache, serveStale, serveExpiredTTL, clientIP)
case strings.EqualFold(u.String(), "fakedns"):
var fd dns.FakeDNSEngine
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
+45
View File
@@ -2,12 +2,15 @@ package dns
import (
"context"
"io"
"net/url"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol/dns"
@@ -15,6 +18,8 @@ import (
"github.com/xtls/xray-core/common/task"
dns_feature "github.com/xtls/xray-core/features/dns"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/udp"
"golang.org/x/net/dns/dnsmessage"
)
@@ -59,6 +64,46 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
return s
}
// NewUDPNameServer creates a UDP DNS client from a URL.
func NewUDPNameServer(url *url.URL, dispatcher routing.Dispatcher, local bool, disableCache bool, serveStale bool, serveExpiredTTL uint32, clientIP net.IP) (*ClassicNameServer, error) {
if url.Hostname() == "" {
return nil, errors.New("missing UDP nameserver host")
}
port := net.Port(53)
if url.Port() != "" {
var err error
if port, err = net.PortFromString(url.Port()); err != nil {
return nil, err
}
}
if local {
dispatcher = &localUDPDispatcher{dispatcher}
}
s := NewClassicNameServer(net.UDPDestination(net.ParseAddress(url.Hostname()), port), dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
if local {
s.cacheController.name = "UDPL//" + s.address.NetAddr()
}
return s, nil
}
type localUDPDispatcher struct {
routing.Dispatcher
}
func (*localUDPDispatcher) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) {
conn, err := internet.DialSystem(ctx, dest, nil)
if err != nil {
return nil, err
}
return &transport.Link{
Reader: &struct {
buf.Reader
io.Closer
}{buf.NewPacketReader(conn), conn},
Writer: buf.NewWriter(conn),
}, nil
}
// Name implements Server.
func (s *ClassicNameServer) Name() string {
return s.cacheController.name
+13 -5
View File
@@ -29,6 +29,7 @@ type MetricsHandler struct {
listen string
tcpListener xnet.Listener
listener *OutboundListener
server *http.Server
}
// NewMetricsHandler creates a new MetricsHandler based on the given config.
@@ -50,7 +51,8 @@ func (p *MetricsHandler) Type() interface{} {
}
func (p *MetricsHandler) Start() error {
handler := p.httpHandler()
server := &http.Server{Handler: p.httpHandler()}
p.server = server
// direct listen a port if listen is set
if p.listen != "" {
@@ -61,7 +63,7 @@ func (p *MetricsHandler) Start() error {
p.tcpListener = TCPlistener
errors.LogInfo(context.Background(), "Metrics server listening on ", p.listen)
go p.serve(TCPlistener, handler)
go p.serve(TCPlistener, server)
}
if p.tag == "" {
@@ -77,7 +79,7 @@ func (p *MetricsHandler) Start() error {
}
p.listener = listener
go p.serve(listener, handler)
go p.serve(listener, server)
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
errors.LogInfo(context.Background(), "failed to remove existing handler")
@@ -106,6 +108,12 @@ func (p *MetricsHandler) Close() error {
errs = append(errs, p.listener.Close())
p.listener = nil
}
if p.server != nil {
if err := p.server.Close(); !isClosedListenerError(err) {
errs = append(errs, err)
}
p.server = nil
}
if p.ohm != nil && p.tag != "" {
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
errors.LogInfo(context.Background(), "failed to remove metrics handler")
@@ -114,8 +122,8 @@ func (p *MetricsHandler) Close() error {
return errors.Combine(errs...)
}
func (p *MetricsHandler) serve(listener xnet.Listener, handler http.Handler) {
if err := http.Serve(listener, handler); err != nil && !isClosedListenerError(err) {
func (p *MetricsHandler) serve(listener xnet.Listener, server *http.Server) {
if err := server.Serve(listener); err != nil && !isClosedListenerError(err) {
errors.LogErrorInner(context.Background(), err, "failed to start metrics server")
}
}
+4 -1
View File
@@ -122,7 +122,10 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
if config.Concurrency < 0 {
h.mux = &mux.ClientManager{Enabled: false}
}
if config.Concurrency >= 0 && config.Concurrency <= 128 {
if config.Concurrency == 0 {
config.Concurrency = 8 // same as before
}
if config.Concurrency > 0 && config.Concurrency < 128 && h.streamSettings != nil && h.streamSettings.ProtocolName == "xdrive" {
config.Concurrency = 128
}
if config.Concurrency > 0 {
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build !windows && !wasm && !illumos && !openbsd
// +build !windows,!wasm,!illumos,!openbsd
//go:build !windows && !openbsd
package buf
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build !wasm && !openbsd
// +build !wasm,!openbsd
//go:build !openbsd
package buf
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build wasm || openbsd
// +build wasm openbsd
//go:build openbsd
package buf
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build !wasm && !openbsd
// +build !wasm,!openbsd
//go:build !openbsd
package buf_test
-37
View File
@@ -1,37 +0,0 @@
//go:build illumos
// +build illumos
package buf
import "golang.org/x/sys/unix"
type unixReader struct {
iovs [][]byte
}
func (r *unixReader) Init(bs []*Buffer) {
iovs := r.iovs
if iovs == nil {
iovs = make([][]byte, 0, len(bs))
}
for _, b := range bs {
iovs = append(iovs, b.v)
}
r.iovs = iovs
}
func (r *unixReader) Read(fd uintptr) int32 {
n, e := unix.Readv(int(fd), r.iovs)
if e != nil {
return -1
}
return int32(n)
}
func (r *unixReader) Clear() {
r.iovs = r.iovs[:0]
}
func newMultiReader() multiReader {
return &unixReader{}
}
@@ -1,5 +1,4 @@
//go:build generate
// +build generate
package main
-1
View File
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package platform
-1
View File
@@ -1,5 +1,4 @@
//go:build windows
// +build windows
package platform
+1 -1
View File
@@ -3,7 +3,7 @@ module github.com/xtls/xray-core
go 1.27
require (
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c
github.com/bufbuild/protocompile v0.14.1
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
github.com/golang/mock v1.7.0-rc.1
+2 -2
View File
@@ -1,5 +1,5 @@
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e h1:5mgtR5gwIgBKMiGI1QdXldZZ+SNor06Nbu1wCBulQBg=
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c h1:cxK8qTA0YCsj68A7zLYDCfPgMTOyt3ePkHh+oXEmYU0=
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c/go.mod h1:J7UZVOMF2M1LiE3iiUZWPuy8YCPAcLJOwVURrfJCvc0=
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+4 -4
View File
@@ -697,10 +697,10 @@ func (c *HttpUpgradeConfig) Build() (proto.Message, error) {
const (
Byte = 1
Kilobyte = 1024 * Byte
Megabyte = 1024 * Kilobyte
Gigabyte = 1024 * Megabyte
Terabyte = 1024 * Gigabyte
Kilobyte = 1000 * Byte
Megabyte = 1000 * Kilobyte
Gigabyte = 1000 * Megabyte
Terabyte = 1000 * Gigabyte
)
type Bandwidth string
-1
View File
@@ -1,5 +1,4 @@
//go:build coveragemain
// +build coveragemain
package main
-1
View File
@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package dokodemo
-1
View File
@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
package dokodemo
-1
View File
@@ -1,5 +1,4 @@
//go:build !linux && !openbsd
// +build !linux,!openbsd
package dokodemo
-1
View File
@@ -1,5 +1,4 @@
//go:build coverage
// +build coverage
package scenarios
-1
View File
@@ -1,5 +1,4 @@
//go:build !coverage
// +build !coverage
package scenarios
-1
View File
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package internet
@@ -1,5 +1,4 @@
//go:build !amd64
// +build !amd64
package original
+9 -2
View File
@@ -108,8 +108,15 @@ func NewDomain(domain string, lenLimit int, labelLimit int, types []uint16, edns
return nil, err
}
ascii = strings.Trim(ascii, ".")
name, err := dnsmessage.NewName(domain + ".")
if ascii == "" {
return nil, errors.New("empty domain")
}
for _, label := range strings.Split(ascii, ".") {
if len(label) == 0 || len(label) > 63 {
return nil, errors.New("invalid domain")
}
}
name, err := dnsmessage.NewName(ascii + ".")
if err != nil {
return nil, err
}
+104 -57
View File
@@ -1,11 +1,11 @@
package xdns
import (
"encoding/binary"
"errors"
"context"
"io"
"sync"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/transport/internet/finalmask"
)
@@ -14,11 +14,9 @@ type TCPResolver struct {
dest net.Destination
dialer *finalmask.Dialer
conn net.Conn
tcpAddr *net.TCPAddr
udpAddr *net.UDPAddr
readCh chan []byte
sendCh chan []byte
closeCh chan struct{}
wg sync.WaitGroup
mu sync.Mutex
@@ -33,12 +31,10 @@ func NewTCPResolver(config *ResolverProto, dialer *finalmask.Dialer) (Resolver,
dest: dest,
dialer: dialer,
readCh: make(chan []byte),
sendCh: make(chan []byte),
closeCh: make(chan struct{}),
}
if err := r.dial(); err != nil {
r.Close()
return nil, err
}
go r.run(config.Worker)
return r, nil
}
@@ -51,60 +47,113 @@ func (r *TCPResolver) closed() bool {
}
}
func (r *TCPResolver) dial() error {
if r.closed() {
return errors.New("closed")
func (r *TCPResolver) setaddr(addr net.Addr) {
r.mu.Lock()
defer r.mu.Unlock()
switch v := addr.(type) {
case *net.TCPAddr:
r.udpAddr = &net.UDPAddr{IP: v.IP, Port: v.Port}
case *net.UDPAddr:
r.udpAddr = v
default:
panic(v)
}
if r.conn != nil {
return nil
}
func (r *TCPResolver) read(reader io.Reader, p []byte) (l int, err error) {
if _, err := io.ReadFull(reader, p[:2]); err != nil {
return 0, err
}
conn, err := r.dialer.DialTCP(r.dest)
l = int(p[0])<<8 | int(p[1])
if l == 0 || l > 4096 {
return 0, errors.New("err resp len ", l)
}
if _, err = io.ReadFull(reader, p[:l]); err != nil {
return 0, err
}
return l, nil
}
func (r *TCPResolver) do(conn *net.Conn, buf *[4096 + 2]byte, p []byte) error {
var err error
if *conn == nil {
*conn, err = r.dialer.DialTCP(r.dest)
if err != nil {
*conn = nil
return err
}
r.setaddr((*conn).RemoteAddr())
}
c := *conn
l := len(p)
buf[0] = byte(l >> 8)
buf[1] = byte(l)
copy(buf[2:], p)
_, err = c.Write(buf[:2+len(p)])
if err != nil {
c.Close()
*conn = nil
return err
}
r.conn = conn
r.tcpAddr = conn.RemoteAddr().(*net.TCPAddr)
r.udpAddr = &net.UDPAddr{IP: r.tcpAddr.IP, Port: r.tcpAddr.Port}
r.wg.Add(1)
go r.recv(conn)
b := pool4K.Get().([]byte)
l, err = r.read(c, b)
if err != nil {
c.Close()
*conn = nil
pool4K.Put(b[:cap(b)])
return err
}
select {
case <-r.closeCh:
pool4K.Put(b[:cap(b)])
case r.readCh <- b[:l]:
}
return nil
}
func (r *TCPResolver) recv(conn net.Conn) {
func (r *TCPResolver) worker() {
defer r.wg.Done()
var buf [4096]byte
var conn net.Conn
defer func() {
if conn != nil {
_ = conn.Close()
}
}()
var buf [4096 + 2]byte
var p []byte
for {
_, err := io.ReadFull(conn, buf[:2])
if err != nil {
break
}
n := binary.BigEndian.Uint16(buf[:2])
if n == 0 || n > 4096 {
io.CopyN(io.Discard, conn, int64(n))
continue
}
_, err = io.ReadFull(conn, buf[:n])
if err != nil {
break
}
p := pool4K.Get().([]byte)
copy(p, buf[:n])
select {
case <-r.closeCh:
pool4K.Put(p[:cap(p)])
case r.readCh <- p[:n]:
return
default:
select {
case <-r.closeCh:
return
case p = <-r.sendCh:
}
}
if err := r.do(&conn, &buf, p); err != nil {
errors.LogErrorInner(context.Background(), err, "do err")
}
}
}
r.mu.Lock()
defer r.mu.Unlock()
_ = conn.Close()
r.conn = nil
func (r *TCPResolver) run(worker int32) {
for range worker {
r.wg.Add(1)
go r.worker()
}
r.wg.Wait()
close(r.readCh)
// close(r.sendCh)
}
func (r *TCPResolver) Addr() *net.UDPAddr {
r.mu.Lock()
defer r.mu.Unlock()
return r.udpAddr
}
@@ -119,27 +168,25 @@ func (r *TCPResolver) Read(p []byte) (n int, err error) {
}
func (r *TCPResolver) Send(p []byte) {
r.mu.Lock()
defer r.mu.Unlock()
if r.dial() != nil {
select {
case <-r.closeCh:
return
default:
b := make([]byte, len(p))
copy(b, p)
select {
case <-r.closeCh:
return
case r.sendCh <- b:
}
}
_ = binary.Write(r.conn, binary.BigEndian, len(p))
_, _ = r.conn.Write(p)
}
func (r *TCPResolver) Close() {
r.mu.Lock()
defer r.mu.Unlock()
if r.closed() {
r.mu.Unlock()
return
}
close(r.closeCh)
conn := r.conn
r.mu.Unlock()
if conn != nil {
_ = conn.Close()
}
r.wg.Wait()
close(r.readCh)
}
+7 -3
View File
@@ -197,7 +197,8 @@ func (c *client) dial(ctx context.Context) error {
}
// udp, _ := strconv.ParseBool(resp.Header.Get(ResponseHeaderUDPEnabled))
down, _ := strconv.ParseUint(resp.Header.Get(CommonHeaderCCRX), 10, 64)
remote_rx, _ := strconv.ParseUint(resp.Header.Get(CommonHeaderCCRX), 10, 64)
tx := quicParams.BrutalUp
errors.LogDebug(context.Background(), "ECHAccepted ", conn.ConnectionState().TLS.ECHAccepted)
switch quicParams.Congestion {
@@ -205,10 +206,13 @@ func (c *client) dial(ctx context.Context) error {
case "bbr":
congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
case "", "brutal":
if quicParams.BrutalUp == 0 || down == 0 {
if tx == 0 {
congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
} else {
congestion.UseBrutal(conn, min(quicParams.BrutalUp, down), quicParams.BrutalDisableLossCompensation)
if remote_rx > 0 {
tx = min(tx, remote_rx)
}
congestion.UseBrutal(conn, tx, quicParams.BrutalDisableLossCompensation)
}
case "force-brutal":
congestion.UseBrutal(conn, quicParams.BrutalUp, quicParams.BrutalDisableLossCompensation)
+7 -3
View File
@@ -55,7 +55,8 @@ func (h *httpHandler) AuthHTTP(w http.ResponseWriter, r *http.Request) bool {
}
auth := r.Header.Get(RequestHeaderAuth)
down, _ := strconv.ParseUint(r.Header.Get(CommonHeaderCCRX), 10, 64)
remote_rx, _ := strconv.ParseUint(r.Header.Get(CommonHeaderCCRX), 10, 64)
tx := h.quicParams.BrutalUp
var user *protocol.MemoryUser
var ok bool
@@ -76,10 +77,13 @@ func (h *httpHandler) AuthHTTP(w http.ResponseWriter, r *http.Request) bool {
case "bbr":
congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
case "", "brutal":
if quicParams.BrutalUp == 0 || down == 0 {
if remote_rx == 0 {
congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
} else {
congestion.UseBrutal(conn, min(quicParams.BrutalUp, down), quicParams.BrutalDisableLossCompensation)
if tx > 0 {
remote_rx = min(remote_rx, tx)
}
congestion.UseBrutal(conn, remote_rx, quicParams.BrutalDisableLossCompensation)
}
case "force-brutal":
congestion.UseBrutal(conn, quicParams.BrutalUp, quicParams.BrutalDisableLossCompensation)
-1
View File
@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
package internet
+1 -2
View File
@@ -1,5 +1,4 @@
//go:build js || netbsd || solaris
// +build js netbsd solaris
//go:build !windows && !darwin && !linux && !freebsd && !openbsd
package internet
-1
View File
@@ -1,5 +1,4 @@
//go:build darwin
// +build darwin
package tcp
@@ -1,5 +1,4 @@
//go:build freebsd
// +build freebsd
package tcp
-1
View File
@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package tcp
@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package tcp_test
-1
View File
@@ -1,5 +1,4 @@
//go:build !linux && !freebsd && !darwin
// +build !linux,!freebsd,!darwin
package tcp
-1
View File
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows
package tls
-1
View File
@@ -1,5 +1,4 @@
//go:build windows
// +build windows
package tls
-1
View File
@@ -1,5 +1,4 @@
//go:build darwin
// +build darwin
package udp
-1
View File
@@ -1,5 +1,4 @@
//go:build freebsd
// +build freebsd
package udp
-1
View File
@@ -1,5 +1,4 @@
//go:build linux
// +build linux
package udp
-1
View File
@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
package udp
@@ -1,5 +1,4 @@
//go:build openbsd
// +build openbsd
package udp
-1
View File
@@ -1,5 +1,4 @@
//go:build !linux && !freebsd && !darwin && !openbsd
// +build !linux,!freebsd,!darwin,!openbsd
package udp