mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-21 00:59:12 +00:00
Compare commits
1
Commits
lua
..
ActivityTimer
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ec957cc72 |
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"android-arm64": { "friendlyName": "android-arm64-v8a" },
|
"android-arm64": { "friendlyName": "android-arm64-v8a" },
|
||||||
"android-amd64": { "friendlyName": "android-amd64" },
|
|
||||||
"darwin-amd64": { "friendlyName": "macos-64" },
|
"darwin-amd64": { "friendlyName": "macos-64" },
|
||||||
"darwin-arm64": { "friendlyName": "macos-arm64-v8a" },
|
"darwin-arm64": { "friendlyName": "macos-arm64-v8a" },
|
||||||
"freebsd-386": { "friendlyName": "freebsd-32" },
|
"freebsd-386": { "friendlyName": "freebsd-32" },
|
||||||
@@ -15,7 +14,9 @@
|
|||||||
"linux-arm7": { "friendlyName": "linux-arm32-v7a" },
|
"linux-arm7": { "friendlyName": "linux-arm32-v7a" },
|
||||||
"linux-mips64le": { "friendlyName": "linux-mips64le" },
|
"linux-mips64le": { "friendlyName": "linux-mips64le" },
|
||||||
"linux-mips64": { "friendlyName": "linux-mips64" },
|
"linux-mips64": { "friendlyName": "linux-mips64" },
|
||||||
|
"linux-mipslesoftfloat": { "friendlyName": "linux-mips32le-softfloat" },
|
||||||
"linux-mipsle": { "friendlyName": "linux-mips32le" },
|
"linux-mipsle": { "friendlyName": "linux-mips32le" },
|
||||||
|
"linux-mipssoftfloat": { "friendlyName": "linux-mips32-softfloat" },
|
||||||
"linux-mips": { "friendlyName": "linux-mips32" },
|
"linux-mips": { "friendlyName": "linux-mips32" },
|
||||||
"linux-ppc64le": { "friendlyName": "linux-ppc64le" },
|
"linux-ppc64le": { "friendlyName": "linux-ppc64le" },
|
||||||
"linux-ppc64": { "friendlyName": "linux-ppc64" },
|
"linux-ppc64": { "friendlyName": "linux-ppc64" },
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ ARG TARGETARCH
|
|||||||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
||||||
|
|
||||||
# Download geodat into a staging directory
|
# Download geodat into a staging directory
|
||||||
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat
|
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat
|
||||||
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat
|
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat
|
||||||
|
|
||||||
RUN mkdir -p /tmp/empty
|
RUN mkdir -p /tmp/empty
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json
|
|||||||
{
|
{
|
||||||
"log": {
|
"log": {
|
||||||
"error": "/var/log/xray/error.log",
|
"error": "/var/log/xray/error.log",
|
||||||
"logLevel": "warning",
|
"loglevel": "warning",
|
||||||
"access": "none",
|
"access": "none",
|
||||||
"dnsLog": false
|
"dnsLog": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ ARG TARGETARCH
|
|||||||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -gcflags="all=-l=4" -ldflags "-s -w -buildid=" ./main
|
||||||
|
|
||||||
# Download geodat into a staging directory
|
# Download geodat into a staging directory
|
||||||
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geoip-full.dat /tmp/geodat/geoip.dat
|
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geoip/geoip-full.dat /tmp/geodat/geoip.dat
|
||||||
ADD https://github.com/XTLS/Xray-rules-dat/releases/latest/download/geosite-expand.dat /tmp/geodat/geosite.dat
|
ADD https://raw.githubusercontent.com/XTLS/Xray-rules-dat/release/geosite/geosite-expand.dat /tmp/geodat/geosite.dat
|
||||||
|
|
||||||
RUN mkdir -p /tmp/empty
|
RUN mkdir -p /tmp/empty
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ RUN cat <<EOF >/tmp/usr/local/etc/xray/00_log.json
|
|||||||
{
|
{
|
||||||
"log": {
|
"log": {
|
||||||
"error": "/var/log/xray/error.log",
|
"error": "/var/log/xray/error.log",
|
||||||
"logLevel": "warning",
|
"loglevel": "warning",
|
||||||
"access": "none",
|
"access": "none",
|
||||||
"dnsLog": false
|
"dnsLog": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@v4
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v4.8.0
|
uses: docker/login-action@v4.6.0
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
name: Build and Release for Windows 7
|
name: Build and Release for Windows 7
|
||||||
# Pre-compiling support removal since 1.29
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-assets:
|
check-assets:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- name: Restore Geodat Cache
|
- name: Restore Geodat Cache
|
||||||
uses: actions/cache/restore@v6
|
uses: actions/cache/restore@v6
|
||||||
@@ -112,6 +115,8 @@ jobs:
|
|||||||
COMMID=$(git describe --always --dirty)
|
COMMID=$(git describe --always --dirty)
|
||||||
echo 'Building Xray for Windows 7...'
|
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
|
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
|
- name: Restore Geodat Cache
|
||||||
uses: actions/cache/restore@v6
|
uses: actions/cache/restore@v6
|
||||||
@@ -147,13 +152,6 @@ jobs:
|
|||||||
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
||||||
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
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
|
- name: Create ZIP archive
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -177,3 +175,10 @@ jobs:
|
|||||||
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
||||||
tag: ${{ github.ref }}
|
tag: ${{ github.ref }}
|
||||||
file_glob: true
|
file_glob: true
|
||||||
|
|
||||||
|
- name: Upload files to Artifacts
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: Xray-${{ env.ASSET_NAME }}
|
||||||
|
path: |
|
||||||
|
./build_assets/*
|
||||||
|
|||||||
+90
-183
@@ -79,23 +79,86 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# Include amd64 and arm64 on all platforms.
|
# Include amd64 on all platforms.
|
||||||
goos: [windows, freebsd, openbsd, linux, darwin, android]
|
goos: [windows, freebsd, openbsd, linux, darwin]
|
||||||
goarch: [amd64, arm64]
|
goarch: [amd64, 386]
|
||||||
patch-assetname: [""]
|
patch-assetname: [""]
|
||||||
|
exclude:
|
||||||
|
# Exclude i386 on darwin
|
||||||
|
- goarch: 386
|
||||||
|
goos: darwin
|
||||||
include:
|
include:
|
||||||
# BEGIN Linux specified
|
# BEGIN MacOS ARM64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
# END MacOS ARM64
|
||||||
|
# BEGIN Linux ARM 5 6 7
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: ppc64
|
goarch: arm
|
||||||
|
goarm: 7
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: ppc64le
|
goarch: arm
|
||||||
|
goarm: 6
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: s390x
|
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
|
- goos: linux
|
||||||
goarch: riscv64
|
goarch: riscv64
|
||||||
- goos: linux
|
- goos: linux
|
||||||
goarch: loong64
|
goarch: loong64
|
||||||
# END Linux specified
|
# 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
|
||||||
|
- 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
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -103,6 +166,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
GOARCH: ${{ matrix.goarch }}
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
GOARM: ${{ matrix.goarm }}
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout codebase
|
- name: Checkout codebase
|
||||||
@@ -124,8 +188,8 @@ jobs:
|
|||||||
- name: Show workflow information
|
- name: Show workflow information
|
||||||
run: |
|
run: |
|
||||||
_NAME=${{ matrix.patch-assetname }}
|
_NAME=${{ matrix.patch-assetname }}
|
||||||
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
[ -n "$_NAME" ] || _NAME=$(jq ".[\"$GOOS-$GOARCH$GOARM$GOMIPS\"].friendlyName" -r < .github/build/friendly-filenames.json)
|
||||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
|
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, GOMIPS: $GOMIPS, RELEASE_NAME: $_NAME"
|
||||||
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
@@ -139,18 +203,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Xray
|
- name: Build Xray
|
||||||
run: |
|
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
|
mkdir -p build_assets
|
||||||
COMMID=$(git describe --always --dirty)
|
COMMID=$(git describe --always --dirty)
|
||||||
if [[ ${GOOS} == 'windows' ]]; then
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
@@ -160,164 +212,13 @@ jobs:
|
|||||||
# 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
|
# 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
|
||||||
elif [[ ${GOOS} == 'android' ]]; then
|
elif [[ ${GOOS} == 'android' ]]; then
|
||||||
echo 'Building Xray for Android...'
|
echo 'Building Xray for Android...'
|
||||||
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
|
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" -v ./main
|
||||||
else
|
|
||||||
echo 'Building Xray...'
|
|
||||||
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
|
|
||||||
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} == 'amd64' ]]; then
|
|
||||||
mv resources/wintun/bin/amd64/wintun.dll build_assets/
|
|
||||||
fi
|
|
||||||
if [[ ${GOARCH} == 'arm64' ]]; then
|
|
||||||
mv resources/wintun/bin/arm64/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
|
|
||||||
|
|
||||||
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
|
else
|
||||||
echo 'Building Xray...'
|
echo 'Building Xray...'
|
||||||
if [[ ${GOARCH} == 'mips' || ${GOARCH} == 'mipsle' ]]; then
|
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
|
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...'
|
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
|
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
|
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
|
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
|
||||||
@@ -344,9 +245,15 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
if [[ ${GOOS} == 'windows' ]]; then
|
if [[ ${GOOS} == 'windows' ]]; then
|
||||||
echo 'Adding Wintun into packages'
|
echo 'Adding Wintun into packages'
|
||||||
|
if [[ ${GOARCH} == 'amd64' ]]; then
|
||||||
|
mv resources/wintun/bin/amd64/wintun.dll build_assets/
|
||||||
|
fi
|
||||||
if [[ ${GOARCH} == '386' ]]; then
|
if [[ ${GOARCH} == '386' ]]; then
|
||||||
mv resources/wintun/bin/x86/wintun.dll build_assets/
|
mv resources/wintun/bin/x86/wintun.dll build_assets/
|
||||||
fi
|
fi
|
||||||
|
if [[ ${GOARCH} == 'arm64' ]]; then
|
||||||
|
mv resources/wintun/bin/arm64/wintun.dll build_assets/
|
||||||
|
fi
|
||||||
mv resources/wintun/LICENSE.txt build_assets/LICENSE-Wintun
|
mv resources/wintun/LICENSE.txt build_assets/LICENSE-Wintun
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -355,13 +262,6 @@ jobs:
|
|||||||
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
cp ${GITHUB_WORKSPACE}/README.md ./build_assets/README.md
|
||||||
cp ${GITHUB_WORKSPACE}/LICENSE ./build_assets/LICENSE
|
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
|
- name: Create ZIP archive
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -385,3 +285,10 @@ jobs:
|
|||||||
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
file: ./Xray-${{ env.ASSET_NAME }}.zip*
|
||||||
tag: ${{ github.ref }}
|
tag: ${{ github.ref }}
|
||||||
file_glob: true
|
file_glob: true
|
||||||
|
|
||||||
|
- name: Upload files to Artifacts
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
with:
|
||||||
|
name: Xray-${{ env.ASSET_NAME }}
|
||||||
|
path: |
|
||||||
|
./build_assets/*
|
||||||
|
|||||||
@@ -35,7 +35,24 @@ jobs:
|
|||||||
if: steps.check-assets.outputs.missing == 'true'
|
if: steps.check-assets.outputs.missing == 'true'
|
||||||
run: sleep 90
|
run: sleep 90
|
||||||
|
|
||||||
check-format-and-proto:
|
check-proto:
|
||||||
|
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: Checkout codebase
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
- name: Check Proto Version Header
|
||||||
|
run: |
|
||||||
|
head -n 4 core/config.pb.go > ref.txt
|
||||||
|
find . -name "*.pb.go" ! -name "*_grpc.pb.go" -print0 | while IFS= read -r -d '' file; do
|
||||||
|
if ! cmp -s ref.txt <(head -n 4 "$file"); then
|
||||||
|
echo "Error: Header mismatch in $file"
|
||||||
|
head -n 4 "$file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
check-format:
|
||||||
runs-on: ubuntu-latest
|
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
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
permissions:
|
permissions:
|
||||||
@@ -51,8 +68,6 @@ jobs:
|
|||||||
cache: false
|
cache: false
|
||||||
- name: Check Format
|
- name: Check Format
|
||||||
run: go run ./infra/vformat/main.go -mode check -pwd ./
|
run: go run ./infra/vformat/main.go -mode check -pwd ./
|
||||||
- name: Check Protobuf
|
|
||||||
run: go run ./infra/vprotogen/main.go -mode check -pwd ./
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
needs: check-assets
|
needs: check-assets
|
||||||
|
|||||||
@@ -231,34 +231,17 @@ 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
|
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:
|
For Android:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=/path/to/aarch64-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
|
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=/path/to/aarch64-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" -v ./main
|
||||||
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
|
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" -v ./main
|
||||||
```
|
```
|
||||||
|
|
||||||
For Linux (MIPS32 and MIPS32LE):
|
If you are compiling a 32-bit MIPS/MIPSLE target, use this command instead:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
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
|
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=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
|
## Stargazers over time
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/commander/config.proto
|
// source: app/commander/config.proto
|
||||||
|
|
||||||
package commander
|
package commander
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/dispatcher/config.proto
|
// source: app/dispatcher/config.proto
|
||||||
|
|
||||||
package dispatcher
|
package dispatcher
|
||||||
|
|||||||
@@ -124,17 +124,14 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {
|
|||||||
if rec == nil {
|
if rec == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
a, aaaa := rec.A, rec.AAAA
|
if rec.A != nil && rec.A.Expire.Before(now) {
|
||||||
if a != nil && a.Expire.Before(now) {
|
rec.A = nil
|
||||||
a = nil
|
|
||||||
}
|
}
|
||||||
if aaaa != nil && aaaa.Expire.Before(now) {
|
if rec.AAAA != nil && rec.AAAA.Expire.Before(now) {
|
||||||
aaaa = nil
|
rec.AAAA = nil
|
||||||
}
|
}
|
||||||
if a == nil && aaaa == nil {
|
if rec.A == nil && rec.AAAA == nil {
|
||||||
delete(c.ips, domain)
|
delete(c.ips, domain)
|
||||||
} else if a != rec.A || aaaa != rec.AAAA {
|
|
||||||
c.ips[domain] = &record{A: a, AAAA: aaaa}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/dns/config.proto
|
// source: app/dns/config.proto
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|||||||
+8
-8
@@ -148,7 +148,7 @@ func TestUDPServerSubnet(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -210,7 +210,7 @@ func TestUDPServer(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -350,7 +350,7 @@ func TestPrioritizedDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -421,7 +421,7 @@ func TestUDPServerIPv6(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -490,7 +490,7 @@ func TestStaticHostDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -577,7 +577,7 @@ func TestIPMatch(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -696,7 +696,7 @@ func TestLocalDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -953,7 +953,7 @@ func TestMultiMatchPrioritizedDomain(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/dns/fakedns/fakedns.proto
|
// source: app/dns/fakedns/fakedns.proto
|
||||||
|
|
||||||
package fakedns
|
package fakedns
|
||||||
|
|||||||
@@ -68,10 +68,6 @@ func NewServer(ctx context.Context, dest net.Destination, dispatcher routing.Dis
|
|||||||
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
|
return NewTCPNameServer(u, dispatcher, disableCache, serveStale, serveExpiredTTL, clientIP)
|
||||||
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
|
case strings.EqualFold(u.Scheme, "tcp+local"): // DNS-over-TCP Local mode
|
||||||
return NewTCPLocalNameServer(u, disableCache, serveStale, serveExpiredTTL, clientIP)
|
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"):
|
case strings.EqualFold(u.String(), "fakedns"):
|
||||||
var fd dns.FakeDNSEngine
|
var fd dns.FakeDNSEngine
|
||||||
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
err = core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"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/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol/dns"
|
"github.com/xtls/xray-core/common/protocol/dns"
|
||||||
@@ -18,8 +15,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
dns_feature "github.com/xtls/xray-core/features/dns"
|
dns_feature "github.com/xtls/xray-core/features/dns"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"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"
|
"github.com/xtls/xray-core/transport/internet/udp"
|
||||||
"golang.org/x/net/dns/dnsmessage"
|
"golang.org/x/net/dns/dnsmessage"
|
||||||
)
|
)
|
||||||
@@ -64,46 +59,6 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher
|
|||||||
return s
|
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.
|
// Name implements Server.
|
||||||
func (s *ClassicNameServer) Name() string {
|
func (s *ClassicNameServer) Name() string {
|
||||||
return s.cacheController.name
|
return s.cacheController.name
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/geodata/config.proto
|
// source: app/geodata/config.proto
|
||||||
|
|
||||||
package geodata
|
package geodata
|
||||||
|
|||||||
+60
-57
@@ -1,8 +1,6 @@
|
|||||||
package geodata
|
package geodata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"compress/gzip"
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
go_errors "errors"
|
go_errors "errors"
|
||||||
@@ -23,10 +21,7 @@ import (
|
|||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const idleTimeout = 30 * time.Second
|
||||||
idleTimeout = 30 * time.Second
|
|
||||||
maxDownloadSize int64 = 256 * 1024 * 1024
|
|
||||||
)
|
|
||||||
|
|
||||||
// DO NOT EDIT. Ignored by geodata, rejected by Lua.
|
// DO NOT EDIT. Ignored by geodata, rejected by Lua.
|
||||||
const luaGuardHeader = "\x12\x01\x00"
|
const luaGuardHeader = "\x12\x01\x00"
|
||||||
@@ -38,6 +33,7 @@ type stage struct {
|
|||||||
|
|
||||||
type downloader struct {
|
type downloader struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
httpClient *http.Client
|
||||||
httpsClient *http.Client
|
httpsClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +61,12 @@ func (c *idleConn) Write(b []byte) (int, error) {
|
|||||||
func newDownloader(ctx context.Context, dispatcher routing.Dispatcher, outbound string) *downloader {
|
func newDownloader(ctx context.Context, dispatcher routing.Dispatcher, outbound string) *downloader {
|
||||||
return &downloader{
|
return &downloader{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
httpsClient: newClient(ctx, dispatcher, outbound),
|
httpClient: newClient(ctx, dispatcher, outbound, false),
|
||||||
|
httpsClient: newClient(ctx, dispatcher, outbound, true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound string) *http.Client {
|
func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound string, isHTTPS bool) *http.Client {
|
||||||
dial := func(ctx context.Context, network, address string) (net.Conn, error) {
|
dial := func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
err := task.Run(ctx, func() error {
|
err := task.Run(ctx, func() error {
|
||||||
@@ -94,33 +91,53 @@ func newClient(baseCtx context.Context, dispatcher routing.Dispatcher, outbound
|
|||||||
Conn: conn,
|
Conn: conn,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return &http.Client{
|
if isHTTPS {
|
||||||
Transport: &http2.Transport{
|
return &http.Client{
|
||||||
DialTLSContext: func(ctx context.Context, network string, address string, cfg *tls.Config) (net.Conn, error) {
|
Transport: &http2.Transport{
|
||||||
conn, err := dial(ctx, network, address)
|
DialTLSContext: func(ctx context.Context, network string, address string, cfg *tls.Config) (net.Conn, error) {
|
||||||
if err != nil {
|
conn, err := dial(ctx, network, address)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
host, _, _ := net.SplitHostPort(address)
|
}
|
||||||
tlsConn := utls.UClient(conn, &utls.Config{ServerName: host}, utls.HelloChrome_Auto)
|
host, _, _ := net.SplitHostPort(address)
|
||||||
handshakeCtx, cancel := context.WithTimeout(ctx, idleTimeout)
|
tlsConn := utls.UClient(conn, &utls.Config{ServerName: host}, utls.HelloChrome_Auto)
|
||||||
defer cancel()
|
handshakeCtx, cancel := context.WithTimeout(ctx, idleTimeout)
|
||||||
if err := tlsConn.HandshakeContext(handshakeCtx); err != nil {
|
defer cancel()
|
||||||
conn.Close()
|
if err := tlsConn.HandshakeContext(handshakeCtx); err != nil {
|
||||||
return nil, err
|
conn.Close()
|
||||||
}
|
return nil, err
|
||||||
return tlsConn, nil
|
}
|
||||||
|
return tlsConn, nil
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
if req.URL.Scheme != "https" {
|
||||||
if req.URL.Scheme != "https" {
|
return errors.New("redirected to non-https URL: ", req.URL.String())
|
||||||
return errors.New("redirected to non-https URL: ", req.URL.String())
|
}
|
||||||
}
|
if len(via) >= 10 {
|
||||||
if len(via) >= 20 {
|
return errors.New("stopped after 10 redirects")
|
||||||
return errors.New("stopped after 20 redirects")
|
}
|
||||||
}
|
return nil
|
||||||
return nil
|
},
|
||||||
},
|
}
|
||||||
|
} else {
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: nil,
|
||||||
|
DisableKeepAlives: true,
|
||||||
|
DialContext: dial,
|
||||||
|
ResponseHeaderTimeout: idleTimeout,
|
||||||
|
},
|
||||||
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||||
|
if req.URL.Scheme != "https" {
|
||||||
|
return errors.New("redirected to non-https URL: ", req.URL.String())
|
||||||
|
}
|
||||||
|
if len(via) >= 10 {
|
||||||
|
return errors.New("stopped after 10 redirects")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,41 +203,27 @@ func (d *downloader) fetch(rawURL string, writer io.Writer) error {
|
|||||||
}
|
}
|
||||||
utils.TryDefaultHeadersWith(req.Header, "nav")
|
utils.TryDefaultHeadersWith(req.Header, "nav")
|
||||||
|
|
||||||
resp, err := d.httpsClient.Do(req)
|
var client *http.Client
|
||||||
|
if req.URL.Scheme == "https" {
|
||||||
|
client = d.httpsClient
|
||||||
|
} else {
|
||||||
|
client = d.httpClient
|
||||||
|
}
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
|
||||||
|
io.Copy(io.Discard, resp.Body)
|
||||||
return errors.New("unexpected status code: ", resp.StatusCode)
|
return errors.New("unexpected status code: ", resp.StatusCode)
|
||||||
}
|
}
|
||||||
if resp.ContentLength > maxDownloadSize {
|
|
||||||
return errors.New("geodata download exceeds 256 MiB")
|
|
||||||
}
|
|
||||||
|
|
||||||
br := bufio.NewReader(resp.Body)
|
n, err := io.Copy(writer, resp.Body)
|
||||||
header, err := br.Peek(2)
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var body io.Reader = br
|
|
||||||
if len(header) == 2 && header[0] == 0x1f && header[1] == 0x8b {
|
|
||||||
zr, err := gzip.NewReader(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer zr.Close()
|
|
||||||
body = zr
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := io.Copy(writer, io.LimitReader(body, maxDownloadSize+1))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if n > maxDownloadSize {
|
|
||||||
return errors.New("geodata download exceeds 256 MiB")
|
|
||||||
}
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return errors.New("empty response body")
|
return errors.New("empty response body")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,10 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
commongeodata "github.com/xtls/xray-core/common/geodata"
|
commongeodata "github.com/xtls/xray-core/common/geodata"
|
||||||
xlua "github.com/xtls/xray-core/common/lua"
|
xlua "github.com/xtls/xray-core/common/lua"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
|
||||||
"github.com/xtls/xray-core/core"
|
|
||||||
"github.com/yuin/gopher-lua/parse"
|
"github.com/yuin/gopher-lua/parse"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
@@ -34,11 +31,11 @@ func TestDownloadOneLuaGuard(t *testing.T) {
|
|||||||
if err := os.WriteFile(filepath.Join(dir, "asset.lua"), nil, 0o600); err != nil {
|
if err := os.WriteFile(filepath.Join(dir, "asset.lua"), nil, 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, _ = w.Write([]byte(tc.body))
|
_, _ = w.Write([]byte(tc.body))
|
||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
d := &downloader{ctx: context.Background(), httpsClient: server.Client()}
|
d := &downloader{ctx: context.Background(), httpClient: server.Client()}
|
||||||
staged, err := d.downloadOne(&Asset{Url: server.URL, File: "asset.lua"})
|
staged, err := d.downloadOne(&Asset{Url: server.URL, File: "asset.lua"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -74,53 +71,3 @@ func TestDownloadOneLuaGuard(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProtobufConfigValidation(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
t.Setenv("xray.location.asset", dir)
|
|
||||||
for _, name := range []string{"asset.dat", "asset.DAT"} {
|
|
||||||
if err := os.WriteFile(filepath.Join(dir, name), nil, 0o600); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := os.Mkdir(filepath.Join(dir, "directory.dat"), 0o700); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
server, err := core.New(&core.Config{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() { _ = server.Close() })
|
|
||||||
for _, tc := range []struct {
|
|
||||||
name string
|
|
||||||
config *Config
|
|
||||||
wantError string
|
|
||||||
}{
|
|
||||||
{"minutely cron", &Config{Cron: "* * * * *"}, ""},
|
|
||||||
{"minimum interval", &Config{Cron: "@every 1m"}, ""},
|
|
||||||
{"short interval", &Config{Cron: "@every 59s"}, "interval must be at least 1 minute"},
|
|
||||||
{"fractional interval", &Config{Cron: "@every 59.999s"}, "interval must be at least 1 minute"},
|
|
||||||
{"invalid cron", &Config{Cron: "invalid"}, "invalid geodata cron"},
|
|
||||||
{"dat extension", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "asset.dat"}}}, ""},
|
|
||||||
{"uppercase extension", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "asset.DAT"}}}, ""},
|
|
||||||
{"invalid extension", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "asset.lua"}}}, "extension must be .dat"},
|
|
||||||
{"missing extension", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "asset"}}}, "extension must be .dat"},
|
|
||||||
{"missing file", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "missing.dat"}}}, "invalid geodata asset file"},
|
|
||||||
{"directory", &Config{Cron: "@daily", Assets: []*Asset{{Url: "https://example.com/asset.dat", File: "directory.dat"}}}, "asset is not a regular file"},
|
|
||||||
} {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
config, err := serial.ToTypedMessage(tc.config).GetInstance()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
_, err = core.CreateObject(server, config)
|
|
||||||
if tc.wantError == "" {
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
} else if err == nil || !strings.Contains(err.Error(), tc.wantError) {
|
|
||||||
t.Fatalf("CreateObject() error = %v; want %q", err, tc.wantError)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+3
-23
@@ -2,16 +2,12 @@ package geodata
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
commongeodata "github.com/xtls/xray-core/common/geodata"
|
commongeodata "github.com/xtls/xray-core/common/geodata"
|
||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
)
|
)
|
||||||
@@ -29,24 +25,6 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
|
|||||||
if config.Cron == "" {
|
if config.Cron == "" {
|
||||||
return &Instance{}, nil
|
return &Instance{}, nil
|
||||||
}
|
}
|
||||||
if len(config.Assets) > 100 {
|
|
||||||
return nil, errors.New("geodata supports at most 100 assets")
|
|
||||||
}
|
|
||||||
for _, asset := range config.Assets {
|
|
||||||
if !strings.EqualFold(filepath.Ext(asset.GetFile()), ".dat") {
|
|
||||||
return nil, errors.New("geodata asset file extension must be .dat")
|
|
||||||
}
|
|
||||||
if _, err := filesystem.ResolveAsset(asset.GetFile()); err != nil {
|
|
||||||
return nil, errors.New("invalid geodata asset file: ", asset.GetFile()).Base(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
schedule, err := cron.ParseStandard(config.Cron)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("invalid geodata cron").Base(err)
|
|
||||||
}
|
|
||||||
if interval, ok := schedule.(cron.ConstantDelaySchedule); ok && interval.Delay < time.Minute {
|
|
||||||
return nil, errors.New("geodata cron interval must be at least 1 minute")
|
|
||||||
}
|
|
||||||
|
|
||||||
g := &Instance{
|
g := &Instance{
|
||||||
assets: config.Assets,
|
assets: config.Assets,
|
||||||
@@ -66,7 +44,9 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
|
|||||||
cron.WithChain(cron.SkipIfStillRunning(cron.DiscardLogger)),
|
cron.WithChain(cron.SkipIfStillRunning(cron.DiscardLogger)),
|
||||||
cron.WithLogger(cron.DiscardLogger),
|
cron.WithLogger(cron.DiscardLogger),
|
||||||
)
|
)
|
||||||
g.tasker.Schedule(schedule, cron.FuncJob(g.execute))
|
if _, err := g.tasker.AddFunc(config.Cron, g.execute); err != nil {
|
||||||
|
return nil, errors.New("invalid geodata cron").Base(err)
|
||||||
|
}
|
||||||
errors.LogInfo(ctx, "scheduled geodata reload with cron: ", config.Cron)
|
errors.LogInfo(ctx, "scheduled geodata reload with cron: ", config.Cron)
|
||||||
|
|
||||||
return g, nil
|
return g, nil
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/log/command/config.proto
|
// source: app/log/command/config.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.2
|
// - protoc-gen-go-grpc v1.6.0
|
||||||
// - protoc (unknown)
|
// - protoc v6.33.5
|
||||||
// source: app/log/command/config.proto
|
// source: app/log/command/config.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/log/config.proto
|
// source: app/log/config.proto
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/metrics/config.proto
|
// source: app/metrics/config.proto
|
||||||
|
|
||||||
package metrics
|
package metrics
|
||||||
|
|||||||
+5
-13
@@ -29,7 +29,6 @@ type MetricsHandler struct {
|
|||||||
listen string
|
listen string
|
||||||
tcpListener xnet.Listener
|
tcpListener xnet.Listener
|
||||||
listener *OutboundListener
|
listener *OutboundListener
|
||||||
server *http.Server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMetricsHandler creates a new MetricsHandler based on the given config.
|
// NewMetricsHandler creates a new MetricsHandler based on the given config.
|
||||||
@@ -51,8 +50,7 @@ func (p *MetricsHandler) Type() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *MetricsHandler) Start() error {
|
func (p *MetricsHandler) Start() error {
|
||||||
server := &http.Server{Handler: p.httpHandler()}
|
handler := p.httpHandler()
|
||||||
p.server = server
|
|
||||||
|
|
||||||
// direct listen a port if listen is set
|
// direct listen a port if listen is set
|
||||||
if p.listen != "" {
|
if p.listen != "" {
|
||||||
@@ -63,7 +61,7 @@ func (p *MetricsHandler) Start() error {
|
|||||||
p.tcpListener = TCPlistener
|
p.tcpListener = TCPlistener
|
||||||
errors.LogInfo(context.Background(), "Metrics server listening on ", p.listen)
|
errors.LogInfo(context.Background(), "Metrics server listening on ", p.listen)
|
||||||
|
|
||||||
go p.serve(TCPlistener, server)
|
go p.serve(TCPlistener, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.tag == "" {
|
if p.tag == "" {
|
||||||
@@ -79,7 +77,7 @@ func (p *MetricsHandler) Start() error {
|
|||||||
}
|
}
|
||||||
p.listener = listener
|
p.listener = listener
|
||||||
|
|
||||||
go p.serve(listener, server)
|
go p.serve(listener, handler)
|
||||||
|
|
||||||
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
||||||
errors.LogInfo(context.Background(), "failed to remove existing handler")
|
errors.LogInfo(context.Background(), "failed to remove existing handler")
|
||||||
@@ -108,12 +106,6 @@ func (p *MetricsHandler) Close() error {
|
|||||||
errs = append(errs, p.listener.Close())
|
errs = append(errs, p.listener.Close())
|
||||||
p.listener = nil
|
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 p.ohm != nil && p.tag != "" {
|
||||||
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
if err := p.ohm.RemoveHandler(context.Background(), p.tag); err != nil {
|
||||||
errors.LogInfo(context.Background(), "failed to remove metrics handler")
|
errors.LogInfo(context.Background(), "failed to remove metrics handler")
|
||||||
@@ -122,8 +114,8 @@ func (p *MetricsHandler) Close() error {
|
|||||||
return errors.Combine(errs...)
|
return errors.Combine(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MetricsHandler) serve(listener xnet.Listener, server *http.Server) {
|
func (p *MetricsHandler) serve(listener xnet.Listener, handler http.Handler) {
|
||||||
if err := server.Serve(listener); err != nil && !isClosedListenerError(err) {
|
if err := http.Serve(listener, handler); err != nil && !isClosedListenerError(err) {
|
||||||
errors.LogErrorInner(context.Background(), err, "failed to start metrics server")
|
errors.LogErrorInner(context.Background(), err, "failed to start metrics server")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/observatory/burst/config.proto
|
// source: app/observatory/burst/config.proto
|
||||||
|
|
||||||
package burst
|
package burst
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/observatory/command/command.proto
|
// source: app/observatory/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.2
|
// - protoc-gen-go-grpc v1.6.0
|
||||||
// - protoc (unknown)
|
// - protoc v6.33.5
|
||||||
// source: app/observatory/command/command.proto
|
// source: app/observatory/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/observatory/config.proto
|
// source: app/observatory/config.proto
|
||||||
|
|
||||||
package observatory
|
package observatory
|
||||||
@@ -152,23 +152,23 @@ func (x *HealthPingMeasurementResult) GetMin() int64 {
|
|||||||
type OutboundStatus struct {
|
type OutboundStatus struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
// @Document Whether this outbound is usable
|
// @Document Whether this outbound is usable
|
||||||
//@Restriction ReadOnlyForUser
|
// @Restriction ReadOnlyForUser
|
||||||
Alive bool `protobuf:"varint,1,opt,name=alive,proto3" json:"alive,omitempty"`
|
Alive bool `protobuf:"varint,1,opt,name=alive,proto3" json:"alive,omitempty"`
|
||||||
// @Document The time for probe request to finish.
|
// @Document The time for probe request to finish.
|
||||||
//@Type time.ms
|
// @Type time.ms
|
||||||
//@Restriction ReadOnlyForUser
|
// @Restriction ReadOnlyForUser
|
||||||
Delay int64 `protobuf:"varint,2,opt,name=delay,proto3" json:"delay,omitempty"`
|
Delay int64 `protobuf:"varint,2,opt,name=delay,proto3" json:"delay,omitempty"`
|
||||||
// @Document The last error caused this outbound failed to relay probe request
|
// @Document The last error caused this outbound failed to relay probe request
|
||||||
//@Restriction NotMachineReadable
|
// @Restriction NotMachineReadable
|
||||||
LastErrorReason string `protobuf:"bytes,3,opt,name=last_error_reason,json=lastErrorReason,proto3" json:"last_error_reason,omitempty"`
|
LastErrorReason string `protobuf:"bytes,3,opt,name=last_error_reason,json=lastErrorReason,proto3" json:"last_error_reason,omitempty"`
|
||||||
// @Document The outbound tag for this Server
|
// @Document The outbound tag for this Server
|
||||||
//@Type id.outboundTag
|
// @Type id.outboundTag
|
||||||
OutboundTag string `protobuf:"bytes,4,opt,name=outbound_tag,json=outboundTag,proto3" json:"outbound_tag,omitempty"`
|
OutboundTag string `protobuf:"bytes,4,opt,name=outbound_tag,json=outboundTag,proto3" json:"outbound_tag,omitempty"`
|
||||||
// @Document The time this outbound is known to be alive
|
// @Document The time this outbound is known to be alive
|
||||||
//@Type id.outboundTag
|
// @Type id.outboundTag
|
||||||
LastSeenTime int64 `protobuf:"varint,5,opt,name=last_seen_time,json=lastSeenTime,proto3" json:"last_seen_time,omitempty"`
|
LastSeenTime int64 `protobuf:"varint,5,opt,name=last_seen_time,json=lastSeenTime,proto3" json:"last_seen_time,omitempty"`
|
||||||
// @Document The time this outbound is tried
|
// @Document The time this outbound is tried
|
||||||
//@Type id.outboundTag
|
// @Type id.outboundTag
|
||||||
LastTryTime int64 `protobuf:"varint,6,opt,name=last_try_time,json=lastTryTime,proto3" json:"last_try_time,omitempty"`
|
LastTryTime int64 `protobuf:"varint,6,opt,name=last_try_time,json=lastTryTime,proto3" json:"last_try_time,omitempty"`
|
||||||
HealthPing *HealthPingMeasurementResult `protobuf:"bytes,7,opt,name=health_ping,json=healthPing,proto3" json:"health_ping,omitempty"`
|
HealthPing *HealthPingMeasurementResult `protobuf:"bytes,7,opt,name=health_ping,json=healthPing,proto3" json:"health_ping,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
@@ -257,14 +257,14 @@ func (x *OutboundStatus) GetHealthPing() *HealthPingMeasurementResult {
|
|||||||
type ProbeResult struct {
|
type ProbeResult struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
// @Document Whether this outbound is usable
|
// @Document Whether this outbound is usable
|
||||||
//@Restriction ReadOnlyForUser
|
// @Restriction ReadOnlyForUser
|
||||||
Alive bool `protobuf:"varint,1,opt,name=alive,proto3" json:"alive,omitempty"`
|
Alive bool `protobuf:"varint,1,opt,name=alive,proto3" json:"alive,omitempty"`
|
||||||
// @Document The time for probe request to finish.
|
// @Document The time for probe request to finish.
|
||||||
//@Type time.ms
|
// @Type time.ms
|
||||||
//@Restriction ReadOnlyForUser
|
// @Restriction ReadOnlyForUser
|
||||||
Delay int64 `protobuf:"varint,2,opt,name=delay,proto3" json:"delay,omitempty"`
|
Delay int64 `protobuf:"varint,2,opt,name=delay,proto3" json:"delay,omitempty"`
|
||||||
// @Document The error caused this outbound failed to relay probe request
|
// @Document The error caused this outbound failed to relay probe request
|
||||||
//@Restriction NotMachineReadable
|
// @Restriction NotMachineReadable
|
||||||
LastErrorReason string `protobuf:"bytes,3,opt,name=last_error_reason,json=lastErrorReason,proto3" json:"last_error_reason,omitempty"`
|
LastErrorReason string `protobuf:"bytes,3,opt,name=last_error_reason,json=lastErrorReason,proto3" json:"last_error_reason,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@@ -324,7 +324,7 @@ func (x *ProbeResult) GetLastErrorReason() string {
|
|||||||
type Intensity struct {
|
type Intensity struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
// @Document The time interval for a probe request in ms.
|
// @Document The time interval for a probe request in ms.
|
||||||
//@Type time.ms
|
// @Type time.ms
|
||||||
ProbeInterval uint32 `protobuf:"varint,1,opt,name=probe_interval,json=probeInterval,proto3" json:"probe_interval,omitempty"`
|
ProbeInterval uint32 `protobuf:"varint,1,opt,name=probe_interval,json=probeInterval,proto3" json:"probe_interval,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/policy/config.proto
|
// source: app/policy/config.proto
|
||||||
|
|
||||||
package policy
|
package policy
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/proxyman/command/command.proto
|
// source: app/proxyman/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.2
|
// - protoc-gen-go-grpc v1.6.0
|
||||||
// - protoc (unknown)
|
// - protoc v6.33.5
|
||||||
// source: app/proxyman/command/command.proto
|
// source: app/proxyman/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/proxyman/config.proto
|
// source: app/proxyman/config.proto
|
||||||
|
|
||||||
package proxyman
|
package proxyman
|
||||||
|
|||||||
@@ -51,17 +51,7 @@ func (m *Manager) AddHandler(ctx context.Context, handler inbound.Handler) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.running {
|
if m.running {
|
||||||
if err := handler.Start(); err != nil {
|
return handler.Start()
|
||||||
if len(tag) > 0 {
|
|
||||||
delete(m.taggedHandlers, tag)
|
|
||||||
} else {
|
|
||||||
m.untaggedHandlers = m.untaggedHandlers[:len(m.untaggedHandlers)-1]
|
|
||||||
}
|
|
||||||
if err := handler.Close(); err != nil {
|
|
||||||
errors.LogWarningInner(ctx, err, "failed to close handler ", tag)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -273,7 +273,8 @@ type udpWorker struct {
|
|||||||
checker *task.Periodic
|
checker *task.Periodic
|
||||||
activeConn map[connID]*udpConn
|
activeConn map[connID]*udpConn
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
cone bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
|
func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
|
||||||
@@ -315,6 +316,9 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest
|
|||||||
src: source,
|
src: source,
|
||||||
}
|
}
|
||||||
if originalDest.IsValid() {
|
if originalDest.IsValid() {
|
||||||
|
if !w.cone {
|
||||||
|
id.dest = originalDest
|
||||||
|
}
|
||||||
b.UDP = &originalDest
|
b.UDP = &originalDest
|
||||||
}
|
}
|
||||||
conn, existing := w.getConnection(id)
|
conn, existing := w.getConnection(id)
|
||||||
@@ -414,6 +418,8 @@ func (w *udpWorker) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.cone = w.ctx.Value("cone").(bool)
|
||||||
|
|
||||||
w.checker = &task.Periodic{
|
w.checker = &task.Periodic{
|
||||||
Interval: time.Minute,
|
Interval: time.Minute,
|
||||||
Execute: w.clean,
|
Execute: w.clean,
|
||||||
|
|||||||
@@ -125,9 +125,6 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
if config.Concurrency == 0 {
|
if config.Concurrency == 0 {
|
||||||
config.Concurrency = 8 // same as before
|
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 {
|
if config.Concurrency > 0 {
|
||||||
h.mux = &mux.ClientManager{
|
h.mux = &mux.ClientManager{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
@@ -137,7 +134,7 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
Dialer: h,
|
Dialer: h,
|
||||||
Strategy: mux.ClientStrategy{
|
Strategy: mux.ClientStrategy{
|
||||||
MaxConcurrency: uint32(config.Concurrency),
|
MaxConcurrency: uint32(config.Concurrency),
|
||||||
MaxConnection: 1024,
|
MaxConnection: 128,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -158,7 +155,7 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
|
|||||||
Dialer: h,
|
Dialer: h,
|
||||||
Strategy: mux.ClientStrategy{
|
Strategy: mux.ClientStrategy{
|
||||||
MaxConcurrency: uint32(config.XudpConcurrency),
|
MaxConcurrency: uint32(config.XudpConcurrency),
|
||||||
MaxConnection: 1024,
|
MaxConnection: 128,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestOutboundWithoutStatCounter(t *testing.T) {
|
|||||||
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
||||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||||
Tag: "tag",
|
Tag: "tag",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
})
|
})
|
||||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||||
_, ok := conn.(*stat.CounterConnection)
|
_, ok := conn.(*stat.CounterConnection)
|
||||||
@@ -78,7 +78,7 @@ func TestOutboundWithStatCounter(t *testing.T) {
|
|||||||
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{{}})
|
||||||
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
h, _ := NewHandler(ctx, &core.OutboundHandlerConfig{
|
||||||
Tag: "tag",
|
Tag: "tag",
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
})
|
})
|
||||||
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
conn, _ := h.(*Handler).Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146))
|
||||||
_, ok := conn.(*stat.CounterConnection)
|
_, ok := conn.(*stat.CounterConnection)
|
||||||
@@ -117,7 +117,7 @@ func TestTagsCache(t *testing.T) {
|
|||||||
tag := fmt.Sprintf("%s%d", tags_prefix, idx)
|
tag := fmt.Sprintf("%s%d", tags_prefix, idx)
|
||||||
cfg := &core.OutboundHandlerConfig{
|
cfg := &core.OutboundHandlerConfig{
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}}}),
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}}}),
|
||||||
}
|
}
|
||||||
if h, err := NewHandler(ctx, cfg); err == nil {
|
if h, err := NewHandler(ctx, cfg); err == nil {
|
||||||
if err := ohm.AddHandler(ctx, h); err == nil {
|
if err := ohm.AddHandler(ctx, h); err == nil {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/reverse/config.proto
|
// source: app/reverse/config.proto
|
||||||
|
|
||||||
package reverse
|
package reverse
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/router/command/command.proto
|
// source: app/router/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -34,19 +34,18 @@ message RoutingContext {
|
|||||||
// opened by xray-core.
|
// opened by xray-core.
|
||||||
// * FieldSelectors selects a subset of fields in routing statistics to return.
|
// * FieldSelectors selects a subset of fields in routing statistics to return.
|
||||||
// Valid selectors:
|
// Valid selectors:
|
||||||
// - inbound: Selects connection's inbound tag.
|
// - inbound: Selects connection's inbound tag.
|
||||||
// - network: Selects connection's network.
|
// - network: Selects connection's network.
|
||||||
// - ip: Equivalent as "ip_source" and "ip_target", selects both source and
|
// - ip: Equivalent as "ip_source" and "ip_target", selects both source and
|
||||||
// target IP.
|
// target IP.
|
||||||
// - port: Equivalent as "port_source" and "port_target", selects both source
|
// - port: Equivalent as "port_source" and "port_target", selects both source
|
||||||
// and target port.
|
// and target port.
|
||||||
// - domain: Selects target domain.
|
// - domain: Selects target domain.
|
||||||
// - protocol: Select connection's protocol.
|
// - protocol: Select connection's protocol.
|
||||||
// - user: Select connection's inbound user email.
|
// - user: Select connection's inbound user email.
|
||||||
// - attributes: Select connection's additional attributes.
|
// - attributes: Select connection's additional attributes.
|
||||||
// - outbound: Equivalent as "outbound" and "outbound_group", select both
|
// - outbound: Equivalent as "outbound" and "outbound_group", select both
|
||||||
// outbound tag and outbound group tags.
|
// outbound tag and outbound group tags.
|
||||||
//
|
|
||||||
// * If FieldSelectors is left empty, all fields will be returned.
|
// * If FieldSelectors is left empty, all fields will be returned.
|
||||||
message SubscribeRoutingStatsRequest {
|
message SubscribeRoutingStatsRequest {
|
||||||
repeated string FieldSelectors = 1;
|
repeated string FieldSelectors = 1;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.2
|
// - protoc-gen-go-grpc v1.6.0
|
||||||
// - protoc (unknown)
|
// - protoc v6.33.5
|
||||||
// source: app/router/command/command.proto
|
// source: app/router/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/router/config.proto
|
// source: app/router/config.proto
|
||||||
|
|
||||||
package router
|
package router
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
routing_session "github.com/xtls/xray-core/features/routing/session"
|
routing_session "github.com/xtls/xray-core/features/routing/session"
|
||||||
|
"github.com/xtls/xray-core/proxy/blackhole"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -396,9 +397,9 @@ end`)
|
|||||||
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
serial.ToTypedMessage(&proxyman.OutboundConfig{}),
|
||||||
},
|
},
|
||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{Tag: "default", ProxySettings: serial.ToTypedMessage(&freedom.Config{Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Block, Delay: &freedom.Range{}}}})},
|
{Tag: "default", ProxySettings: serial.ToTypedMessage(&blackhole.Config{})},
|
||||||
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
{Tag: "direct", ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
})},
|
})},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/stats/command/command.proto
|
// source: app/stats/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// - protoc-gen-go-grpc v1.6.2
|
// - protoc-gen-go-grpc v1.6.0
|
||||||
// - protoc (unknown)
|
// - protoc v6.33.5
|
||||||
// source: app/stats/command/command.proto
|
// source: app/stats/command/command.proto
|
||||||
|
|
||||||
package command
|
package command
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/stats/config.proto
|
// source: app/stats/config.proto
|
||||||
|
|
||||||
package stats
|
package stats
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: app/version/config.proto
|
// source: app/version/config.proto
|
||||||
|
|
||||||
package version
|
package version
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ func (r *TimeoutWrapperReader) ReadMultiBufferTimeout(duration time.Duration) (M
|
|||||||
}
|
}
|
||||||
return r.mb, r.err
|
return r.mb, r.err
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return nil, ErrReadTimeout
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build !windows && !openbsd
|
//go:build !windows && !wasm && !illumos && !openbsd
|
||||||
|
// +build !windows,!wasm,!illumos,!openbsd
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build !openbsd
|
//go:build !wasm && !openbsd
|
||||||
|
// +build !wasm,!openbsd
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build openbsd
|
//go:build wasm || openbsd
|
||||||
|
// +build wasm openbsd
|
||||||
|
|
||||||
package buf
|
package buf
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build !openbsd
|
//go:build !wasm && !openbsd
|
||||||
|
// +build !wasm,!openbsd
|
||||||
|
|
||||||
package buf_test
|
package buf_test
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
//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{}
|
||||||
|
}
|
||||||
@@ -236,10 +236,6 @@ func (w *BufferedWriter) Close() error {
|
|||||||
return common.Close(w.writer)
|
return common.Close(w.writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *BufferedWriter) Interrupt() {
|
|
||||||
common.Interrupt(w.writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SequentialWriter is a Writer that writes MultiBuffer sequentially into the underlying io.Writer.
|
// SequentialWriter is a Writer that writes MultiBuffer sequentially into the underlying io.Writer.
|
||||||
type SequentialWriter struct {
|
type SequentialWriter struct {
|
||||||
io.Writer
|
io.Writer
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build generate
|
//go:build generate
|
||||||
|
// +build generate
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|||||||
+17
-59
@@ -8,65 +8,23 @@ import (
|
|||||||
|
|
||||||
var privateIPMatcher = sync.OnceValue(func() IPMatcher {
|
var privateIPMatcher = sync.OnceValue(func() IPMatcher {
|
||||||
return common.Must2(IPReg.BuildIPMatcher(common.Must2(ParseIPRules([]string{
|
return common.Must2(IPReg.BuildIPMatcher(common.Must2(ParseIPRules([]string{
|
||||||
// https://www.iana.org/assignments/iana-ipv4-special-registry
|
"0.0.0.0/8",
|
||||||
"0.0.0.0/8", // "This network"
|
"10.0.0.0/8",
|
||||||
"0.0.0.0/32", // "This host on this network"
|
"100.64.0.0/10",
|
||||||
"10.0.0.0/8", // Private-Use
|
"127.0.0.0/8",
|
||||||
"100.64.0.0/10", // Shared Address Space
|
"169.254.0.0/16",
|
||||||
"127.0.0.0/8", // Loopback
|
"172.16.0.0/12",
|
||||||
"169.254.0.0/16", // Link Local
|
"192.0.0.0/24",
|
||||||
"172.16.0.0/12", // Private-Use
|
"192.0.2.0/24",
|
||||||
// "192.0.0.0/24", // IETF Protocol Assignments
|
"192.88.99.0/24",
|
||||||
"192.0.0.0/29", // IPv4 Service Continuity Prefix
|
"192.168.0.0/16",
|
||||||
"192.0.0.8/32", // IPv4 dummy address
|
"198.18.0.0/15",
|
||||||
"192.0.0.9/32", // Port Control Protocol Anycast
|
"198.51.100.0/24",
|
||||||
"192.0.0.10/32", // Traversal Using Relays around NAT Anycast
|
"203.0.113.0/24",
|
||||||
"192.0.0.170/32", // NAT64/DNS64 Discovery
|
"224.0.0.0/3",
|
||||||
"192.0.0.171/32", // NAT64/DNS64 Discovery
|
"::/127",
|
||||||
"192.0.2.0/24", // Documentation (TEST-NET-1)
|
"fc00::/7",
|
||||||
// "192.31.196.0/24", // AS112-v4
|
"fe80::/10",
|
||||||
"192.52.193.0/24", // AMT
|
|
||||||
// "192.88.99.0/24", // Deprecated (6to4 Relay Anycast)
|
|
||||||
"192.88.99.2/32", // 6a44-relay anycast address
|
|
||||||
"192.168.0.0/16", // Private-Use
|
|
||||||
// "192.175.48.0/24", // Direct Delegation AS112 Service
|
|
||||||
"198.18.0.0/15", // Benchmarking
|
|
||||||
"198.51.100.0/24", // Documentation (TEST-NET-2)
|
|
||||||
"203.0.113.0/24", // Documentation (TEST-NET-3)
|
|
||||||
"240.0.0.0/4", // Reserved
|
|
||||||
"255.255.255.255/32", // Limited Broadcast
|
|
||||||
|
|
||||||
// https://www.iana.org/assignments/multicast-addresses
|
|
||||||
"224.0.0.0/4",
|
|
||||||
|
|
||||||
// https://www.iana.org/assignments/iana-ipv6-special-registry
|
|
||||||
"::1/128", // Loopback Address
|
|
||||||
"::/128", // Unspecified Address
|
|
||||||
// "::ffff:0:0/96", // IPv4-mapped Address
|
|
||||||
"64:ff9b::/96", // IPv4-IPv6 Translat.
|
|
||||||
"64:ff9b:1::/48", // IPv4-IPv6 Translat.
|
|
||||||
"100::/64", // Discard-Only Address Block
|
|
||||||
"100:0:0:1::/64", // Dummy IPv6 Prefix
|
|
||||||
// "2001::/23", // IETF Protocol Assignments
|
|
||||||
"2001::/32", // TEREDO
|
|
||||||
"2001:1::1/128", // Port Control Protocol Anycast
|
|
||||||
"2001:1::2/128", // Traversal Using Relays around NAT Anycast
|
|
||||||
"2001:1::3/128", // DNS-SD Service Registration Protocol Anycast
|
|
||||||
"2001:2::/48", // Benchmarking
|
|
||||||
"2001:3::/32", // AMT
|
|
||||||
// "2001:4:112::/48", // AS112-v6
|
|
||||||
// "2001:10::/28", // Deprecated (previously ORCHID)
|
|
||||||
"2001:20::/28", // ORCHIDv2
|
|
||||||
"2001:30::/28", // Drone Remote ID Protocol Entity Tags (DETs) Prefix
|
|
||||||
"2001:db8::/32", // Documentation
|
|
||||||
"2002::/16", // 6to4
|
|
||||||
// "2620:4f:8000::/48", // Direct Delegation AS112 Service
|
|
||||||
"3fff::/20", // Documentation
|
|
||||||
"5f00::/16", // Segment Routing (SRv6) SIDs
|
|
||||||
"fc00::/7", // Unique-Local
|
|
||||||
"fe80::/10", // Link-Local Unicast
|
|
||||||
|
|
||||||
// https://www.iana.org/assignments/ipv6-multicast-addresses
|
|
||||||
"ff00::/8",
|
"ff00::/8",
|
||||||
}))))
|
}))))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/geodata/geodat.proto
|
// source: common/geodata/geodat.proto
|
||||||
|
|
||||||
package geodata
|
package geodata
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func RegisterLua(L *lua.LState) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
xlua.PushWithDirectMethods(L, matcher, map[string]xlua.DirectMethod{
|
xlua.PushWithDirectMethods(L, matcher, map[string]xlua.DirectMethod{
|
||||||
"Match": newLuaDomainMatch(xlua.NewReadOnlySlicePusher[uint32](L)),
|
"Match": newLuaDomainMatch(xlua.NewSlicePusher[uint32](L)),
|
||||||
"MatchAny": luaDomainMatchAny,
|
"MatchAny": luaDomainMatchAny,
|
||||||
})
|
})
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -104,9 +104,7 @@ for _, value in ipairs({matcher, domain}) do
|
|||||||
assert(not pcall(function() return value ^ {} end))
|
assert(not pcall(function() return value ^ {} end))
|
||||||
end
|
end
|
||||||
assert(domain:matchAny("example.com"))
|
assert(domain:matchAny("example.com"))
|
||||||
local indices = domain:Match("example.com")
|
assert(#domain:Match("example.com") == 1)
|
||||||
assert(#indices == 1)
|
|
||||||
assert(not pcall(function() indices[1] = 7 end))
|
|
||||||
assert(domain:match("example.com")[1] == 0)
|
assert(domain:match("example.com")[1] == 0)
|
||||||
assert(not pcall(function() matcher:AnyMatch() end))
|
assert(not pcall(function() matcher:AnyMatch() end))
|
||||||
assert(not pcall(function() matcher:AnyMatch(matched, true) end))
|
assert(not pcall(function() matcher:AnyMatch(matched, true) end))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/log/log.proto
|
// source: common/log/log.proto
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|||||||
+3
-3
@@ -8,10 +8,10 @@ import (
|
|||||||
luar "layeh.com/gopher-luar"
|
luar "layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newSlicePusher captures luar's slice metatable during state initialization.
|
// NewSlicePusher captures luar's slice metatable during state initialization.
|
||||||
// The returned function wraps slices without reflection or metatable lookup,
|
// The returned function wraps slices without reflection or metatable lookup,
|
||||||
// and pushes nil for nil slices. Use it with this state or its coroutines.
|
// and pushes nil for nil slices. Use it with this state or its coroutines.
|
||||||
func newSlicePusher[T any](L *glua.LState) func(*glua.LState, []T) {
|
func NewSlicePusher[T any](L *glua.LState) func(*glua.LState, []T) {
|
||||||
metatable := luar.MT(L, []T(nil)).LTable
|
metatable := luar.MT(L, []T(nil)).LTable
|
||||||
return func(L *glua.LState, values []T) {
|
return func(L *glua.LState, values []T) {
|
||||||
if values == nil {
|
if values == nil {
|
||||||
@@ -38,7 +38,7 @@ func NewReadOnlySlicePusher[T any](L *glua.LState) func(*glua.LState, []T) {
|
|||||||
})
|
})
|
||||||
setSliceReadOnly[[]T](L, readOnly)
|
setSliceReadOnly[[]T](L, readOnly)
|
||||||
}
|
}
|
||||||
return newSlicePusher[T](L)
|
return NewSlicePusher[T](L)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSliceReadOnly[S ~[]E, E any](L *glua.LState, readOnly *glua.LFunction) {
|
func setSliceReadOnly[S ~[]E, E any](L *glua.LState, readOnly *glua.LFunction) {
|
||||||
|
|||||||
+43
-21
@@ -9,20 +9,53 @@ import (
|
|||||||
luar "layeh.com/gopher-luar"
|
luar "layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadOnlySlicePusher(t *testing.T) {
|
func TestSlicePusher(t *testing.T) {
|
||||||
L := glua.NewState()
|
L := glua.NewState()
|
||||||
defer L.Close()
|
defer L.Close()
|
||||||
push := NewReadOnlySlicePusher[int](L)
|
push := NewSlicePusher[int](L)
|
||||||
values := []int{3, 5}
|
values := []int{3, 5}
|
||||||
L.SetGlobal("getValues", L.NewFunction(func(L *glua.LState) int {
|
L.SetGlobal("getValues", L.NewFunction(func(L *glua.LState) int {
|
||||||
push(L, values)
|
push(L, values)
|
||||||
return 1
|
return 1
|
||||||
}))
|
}))
|
||||||
if err := L.DoString(`
|
if err := L.DoString(`
|
||||||
local co = coroutine.create(function() return getValues() end)
|
local values = getValues()
|
||||||
|
assert(#values == 2 and values[1] == 3 and values[2] == 5)
|
||||||
|
values[2] = 7
|
||||||
|
local co = coroutine.create(function()
|
||||||
|
local values = getValues()
|
||||||
|
assert(#values == 2 and values[1] == 3 and values[2] == 7)
|
||||||
|
return true
|
||||||
|
end)
|
||||||
local ok, result = coroutine.resume(co)
|
local ok, result = coroutine.resume(co)
|
||||||
assert(ok, result)
|
assert(ok and result == true)
|
||||||
values = result
|
`); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if values[1] != 7 {
|
||||||
|
t.Fatal("slice storage was copied")
|
||||||
|
}
|
||||||
|
push(L, nil)
|
||||||
|
if L.Get(-1) != glua.LNil {
|
||||||
|
t.Fatal("nil slice must push Lua nil")
|
||||||
|
}
|
||||||
|
L.Pop(1)
|
||||||
|
push(L, []int{})
|
||||||
|
L.SetGlobal("empty", L.Get(-1))
|
||||||
|
L.Pop(1)
|
||||||
|
if err := L.DoString(`assert(type(empty) == "userdata" and #empty == 0)`); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadOnlySlicePusher(t *testing.T) {
|
||||||
|
L := glua.NewState()
|
||||||
|
defer L.Close()
|
||||||
|
values := []int{3, 5}
|
||||||
|
NewReadOnlySlicePusher[int](L)(L, values)
|
||||||
|
L.SetGlobal("values", L.Get(-1))
|
||||||
|
L.Pop(1)
|
||||||
|
if err := L.DoString(`
|
||||||
assert(#values == 2 and values[1] == 3 and values[2] == 5)
|
assert(#values == 2 and values[1] == 3 and values[2] == 5)
|
||||||
assert(not pcall(function() values[1] = 7 end))
|
assert(not pcall(function() values[1] = 7 end))
|
||||||
assert(not pcall(function() return values + 7 end))
|
assert(not pcall(function() return values + 7 end))
|
||||||
@@ -36,17 +69,6 @@ assert(sum == 8)
|
|||||||
if &got[0] != &values[0] || values[0] != 3 || values[1] != 5 {
|
if &got[0] != &values[0] || values[0] != 3 || values[1] != 5 {
|
||||||
t.Fatal("read-only binding copied or modified the slice")
|
t.Fatal("read-only binding copied or modified the slice")
|
||||||
}
|
}
|
||||||
push(L, nil)
|
|
||||||
if L.Get(-1) != glua.LNil {
|
|
||||||
t.Fatal("nil slice must push Lua nil")
|
|
||||||
}
|
|
||||||
L.Pop(1)
|
|
||||||
push(L, []int{})
|
|
||||||
L.SetGlobal("empty", L.Get(-1))
|
|
||||||
L.Pop(1)
|
|
||||||
if err := L.DoString(`assert(type(empty) == "userdata" and #empty == 0)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadOnlyIPSlicePusher(t *testing.T) {
|
func TestReadOnlyIPSlicePusher(t *testing.T) {
|
||||||
@@ -208,23 +230,23 @@ assert(not pcall(function() return nested + nested end))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadOnlySlicePusherMetatablePerState(t *testing.T) {
|
func TestSlicePusherMetatablePerState(t *testing.T) {
|
||||||
first := glua.NewState()
|
first := glua.NewState()
|
||||||
defer first.Close()
|
defer first.Close()
|
||||||
second := glua.NewState()
|
second := glua.NewState()
|
||||||
defer second.Close()
|
defer second.Close()
|
||||||
NewReadOnlySlicePusher[int](first)(first, []int{1})
|
NewSlicePusher[int](first)(first, []int{1})
|
||||||
NewReadOnlySlicePusher[int](second)(second, []int{1})
|
NewSlicePusher[int](second)(second, []int{1})
|
||||||
if first.Get(-1).(*glua.LUserData).Metatable == second.Get(-1).(*glua.LUserData).Metatable {
|
if first.Get(-1).(*glua.LUserData).Metatable == second.Get(-1).(*glua.LUserData).Metatable {
|
||||||
t.Fatal("independent states share a slice metatable")
|
t.Fatal("independent states share a slice metatable")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkReadOnlySlicePusher(b *testing.B) {
|
func BenchmarkSlicePusher(b *testing.B) {
|
||||||
L := glua.NewState()
|
L := glua.NewState()
|
||||||
defer L.Close()
|
defer L.Close()
|
||||||
ips := []net.IP{net.ParseIP("127.0.0.1")}
|
ips := []net.IP{net.ParseIP("127.0.0.1")}
|
||||||
pushIPs := NewReadOnlySlicePusher[net.IP](L)
|
pushIPs := NewSlicePusher[net.IP](L)
|
||||||
for _, benchmark := range []struct {
|
for _, benchmark := range []struct {
|
||||||
name string
|
name string
|
||||||
push func(*glua.LState, []net.IP)
|
push func(*glua.LState, []net.IP)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/xtls/xray-core/common/base64"
|
"github.com/xtls/xray-core/common/base64"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
"github.com/xtls/xray-core/common/platform"
|
||||||
glua "github.com/yuin/gopher-lua"
|
glua "github.com/yuin/gopher-lua"
|
||||||
"github.com/yuin/gopher-lua/parse"
|
"github.com/yuin/gopher-lua/parse"
|
||||||
)
|
)
|
||||||
@@ -36,7 +36,7 @@ func Compile(script string) (*Program, error) {
|
|||||||
// TODO: Restore inline script support and re-enable the related tests.
|
// TODO: Restore inline script support and re-enable the related tests.
|
||||||
return nil, errors.New("currently unavailable")
|
return nil, errors.New("currently unavailable")
|
||||||
code, err = base64.Decode(script)
|
code, err = base64.Decode(script)
|
||||||
} else if name, err = filesystem.ResolveLuaFile(script); err == nil {
|
} else if name, err = platform.ResolveLuaFile(script); err == nil {
|
||||||
code, err = os.ReadFile(name)
|
code, err = os.ReadFile(name)
|
||||||
// TODO: Restore privileged signature authorization and re-enable the related tests and CLI entries.
|
// TODO: Restore privileged signature authorization and re-enable the related tests and CLI entries.
|
||||||
// if err == nil {
|
// if err == nil {
|
||||||
|
|||||||
+15
-10
@@ -187,20 +187,19 @@ func TestCompileInlineDiagnostics(t *testing.T) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func TestCompileFileExtension(t *testing.T) {
|
func TestCompileFileExtension(t *testing.T) {
|
||||||
for _, name := range []string{"script", "script.dat", "script.lua.txt"} {
|
for _, name := range []string{"script", "script.dat", "script.lua.txt", "script.LUA"} {
|
||||||
if program, err := Compile(name); program != nil || err == nil || !strings.Contains(err.Error(), "Lua file extension must be .lua") {
|
|
||||||
t.Fatalf("Compile(%q) = %v, %v; want nil program and .lua extension error", name, program, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, name := range []string{"script.lua", "script.LUA", "script.Lua", "script.lUa"} {
|
|
||||||
path := filepath.Join(t.TempDir(), name)
|
path := filepath.Join(t.TempDir(), name)
|
||||||
if err := os.WriteFile(path, []byte("value = 42"), 0o600); err != nil {
|
if err := os.WriteFile(path, []byte("value = 42"), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if program, err := Compile(path); program == nil || err != nil {
|
if program, err := Compile(path); program != nil || err == nil || !strings.Contains(err.Error(), "Lua file extension must be .lua") {
|
||||||
t.Fatalf("Compile(%q) = %v, %v; want successful compilation", path, program, err)
|
t.Fatalf("Compile(%q) = %v, %v; want nil program and .lua extension error", path, program, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
path := writeTestScript(t, "value = 42") + string(filepath.Separator) + "."
|
||||||
|
if program, err := Compile(path); program == nil || err != nil {
|
||||||
|
t.Fatalf("Compile(%q) = %v, %v; want acceptance of the resolved .lua path", path, program, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompileRejectsReadFailure(t *testing.T) {
|
func TestCompileRejectsReadFailure(t *testing.T) {
|
||||||
@@ -235,6 +234,10 @@ func writeTestScript(t *testing.T, code string) string {
|
|||||||
if err := os.WriteFile(path, []byte(code), 0o600); err != nil {
|
if err := os.WriteFile(path, []byte(code), 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
path, err := filepath.EvalSymlinks(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -671,7 +674,7 @@ string.__tostring = nil
|
|||||||
L.SetGlobal("testNativeError", L.Get(-1))
|
L.SetGlobal("testNativeError", L.Get(-1))
|
||||||
L.Pop(1)
|
L.Pop(1)
|
||||||
L.SetGlobal("testGoStruct", luar.New(L, &struct{ Value string }{"readable field"}))
|
L.SetGlobal("testGoStruct", luar.New(L, &struct{ Value string }{"readable field"}))
|
||||||
NewReadOnlySlicePusher[net.IP](L)(L, []net.IP{net.ParseIP("192.0.2.1")})
|
NewSlicePusher[net.IP](L)(L, []net.IP{net.ParseIP("192.0.2.1")})
|
||||||
L.SetGlobal("testIPs", L.Get(-1))
|
L.SetGlobal("testIPs", L.Get(-1))
|
||||||
L.Pop(1)
|
L.Pop(1)
|
||||||
userdata := L.NewUserData()
|
userdata := L.NewUserData()
|
||||||
@@ -865,7 +868,9 @@ assert(not ok and a == "{<address> <address>}")
|
|||||||
PushUserData(L, struct{ Pointer *int }{&target})
|
PushUserData(L, struct{ Pointer *int }{&target})
|
||||||
L.SetGlobal("testObject", L.Get(-1))
|
L.SetGlobal("testObject", L.Get(-1))
|
||||||
L.Pop(1)
|
L.Pop(1)
|
||||||
L.SetGlobal("testValues", luar.New(L, []int{1}))
|
NewSlicePusher[int](L)(L, []int{1})
|
||||||
|
L.SetGlobal("testValues", L.Get(-1))
|
||||||
|
L.Pop(1)
|
||||||
L.SetGlobal("testPanic", L.NewFunction(func(L *glua.LState) int {
|
L.SetGlobal("testPanic", L.NewFunction(func(L *glua.LState) int {
|
||||||
panic(struct{ First, Second *int }{&target, &target})
|
panic(struct{ First, Second *int }{&target, &target})
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -188,9 +188,6 @@ var (
|
|||||||
|
|
||||||
// NewClientWorker creates a new mux.Client.
|
// NewClientWorker creates a new mux.Client.
|
||||||
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
||||||
writer := buf.NewBufferedWriter(stream.Writer)
|
|
||||||
writer.SetBuffered(false)
|
|
||||||
stream.Writer = writer
|
|
||||||
c := &ClientWorker{
|
c := &ClientWorker{
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
link: stream,
|
link: stream,
|
||||||
|
|||||||
@@ -93,11 +93,9 @@ type ServerWorker struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
func NewServerWorker(ctx context.Context, d routing.Dispatcher, link *transport.Link) (*ServerWorker, error) {
|
||||||
writer := buf.NewBufferedWriter(link.Writer)
|
|
||||||
writer.SetBuffered(false)
|
|
||||||
worker := &ServerWorker{
|
worker := &ServerWorker{
|
||||||
dispatcher: d,
|
dispatcher: d,
|
||||||
link: &transport.Link{Reader: link.Reader, Writer: writer},
|
link: link,
|
||||||
sessionManager: NewSessionManager(),
|
sessionManager: NewSessionManager(),
|
||||||
done: done.New(),
|
done: done.New(),
|
||||||
timer: time.NewTicker(60 * time.Second),
|
timer: time.NewTicker(60 * time.Second),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/net/address.proto
|
// source: common/net/address.proto
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/net/destination.proto
|
// source: common/net/destination.proto
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ package net
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/binary"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
switch network {
|
switch network {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
if net.ParseIP(srcIP).To4() != nil {
|
if net.ParseIP(srcIP).To4() != nil {
|
||||||
procFiles = []string{"/proc/net/tcp", "/proc/net/tcp6"}
|
procFiles = []string{"/proc/net/tcp"}
|
||||||
} else {
|
} else {
|
||||||
procFiles = []string{"/proc/net/tcp6"}
|
procFiles = []string{"/proc/net/tcp6"}
|
||||||
}
|
}
|
||||||
@@ -46,10 +45,9 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
panic("Unsupported network type for process lookup.")
|
panic("Unsupported network type for process lookup.")
|
||||||
}
|
}
|
||||||
|
|
||||||
targetHexAddrs := []string{formatProcNetAddress(net.ParseIP(srcIP).To16(), Port(srcPort))}
|
targetHexAddr, err := formatLittleEndianString(net.ParseIP(srcIP), Port(srcPort))
|
||||||
if ipv4 := net.ParseIP(srcIP).To4(); ipv4 != nil {
|
if err != nil {
|
||||||
// the one above is then the IPv4-mapped IPv6 address that an IPv6 socket has it as, in the IPv6 file
|
return 0, "", "", errors.New("failed to format address: ", err)
|
||||||
targetHexAddrs = append(targetHexAddrs, formatProcNetAddress(ipv4, Port(srcPort)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portFallback := ""
|
portFallback := ""
|
||||||
@@ -57,7 +55,7 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
portFallback = fmt.Sprintf(":%04X", srcPort)
|
portFallback = fmt.Sprintf(":%04X", srcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
inode, err := findInodeInFiles(procFiles, targetHexAddrs, portFallback)
|
inode, err := findInodeInFiles(procFiles, targetHexAddr, portFallback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", "", errors.New("could not search in ", strings.Join(procFiles, " and ")).Base(err)
|
return 0, "", "", errors.New("could not search in ", strings.Join(procFiles, " and ")).Base(err)
|
||||||
}
|
}
|
||||||
@@ -89,20 +87,27 @@ func FindProcess(network, srcIP string, srcPort uint16, destIP string, destPort
|
|||||||
return pid, procName, absPath, nil
|
return pid, procName, absPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatProcNetAddress formats the 4 or 16 bytes of addr as they are: an IPv4-mapped IPv6 address stays one
|
func formatLittleEndianString(addr net.IP, port Port) (string, error) {
|
||||||
func formatProcNetAddress(addr net.IP, port Port) string {
|
ip := addr
|
||||||
ipBytes := []byte(addr)
|
var ipBytes []byte
|
||||||
|
if ip.To4() != nil {
|
||||||
var formatted strings.Builder
|
ipBytes = ip.To4()
|
||||||
formatted.Grow(len(ipBytes)*2 + 5)
|
} else {
|
||||||
for i := 0; i < len(ipBytes); i += 4 {
|
ipBytes = ip.To16()
|
||||||
fmt.Fprintf(&formatted, "%08X", binary.NativeEndian.Uint32(ipBytes[i:i+4]))
|
|
||||||
}
|
}
|
||||||
fmt.Fprintf(&formatted, ":%04X", uint16(port))
|
if ipBytes == nil {
|
||||||
return formatted.String()
|
return "", errors.New("invalid IP format for ", addr, ": ", ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, j := 0, len(ipBytes)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
ipBytes[i], ipBytes[j] = ipBytes[j], ipBytes[i]
|
||||||
|
}
|
||||||
|
portHex := fmt.Sprintf("%04X", uint16(port))
|
||||||
|
ipHex := strings.ToUpper(hex.EncodeToString(ipBytes))
|
||||||
|
return fmt.Sprintf("%s:%s", ipHex, portHex), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findInodeInFiles(filePaths []string, targetHexAddrs []string, portFallback string) (string, error) {
|
func findInodeInFiles(filePaths []string, targetHexAddr, portFallback string) (string, error) {
|
||||||
onlyMatchedPort := ""
|
onlyMatchedPort := ""
|
||||||
|
|
||||||
for i, filePath := range filePaths {
|
for i, filePath := range filePaths {
|
||||||
@@ -123,7 +128,7 @@ func findInodeInFiles(filePaths []string, targetHexAddrs []string, portFallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
localAddress := fields[1]
|
localAddress := fields[1]
|
||||||
if slices.Contains(targetHexAddrs, localAddress) {
|
if localAddress == targetHexAddr {
|
||||||
return fields[9], nil
|
return fields[9], nil
|
||||||
}
|
}
|
||||||
if portFallback != "" && strings.HasSuffix(localAddress, portFallback) {
|
if portFallback != "" && strings.HasSuffix(localAddress, portFallback) {
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
//go:build linux && !android
|
|
||||||
|
|
||||||
package net
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
stdnet "net"
|
|
||||||
"net/netip"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFindProcessIPv4Mapped(t *testing.T) {
|
|
||||||
listener, err := stdnet.Listen("tcp4", "127.0.0.1:0")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer listener.Close()
|
|
||||||
peer, err := stdnet.ListenPacket("udp4", "127.0.0.1:0")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer peer.Close()
|
|
||||||
|
|
||||||
// an IPv6 socket that connects to an IPv4 address, as the sockets of Java and .NET are
|
|
||||||
for _, c := range []struct{ local, remote stdnet.Addr }{
|
|
||||||
{&stdnet.TCPAddr{IP: stdnet.IPv6zero}, listener.Addr()},
|
|
||||||
{&stdnet.UDPAddr{IP: stdnet.IPv6zero}, peer.LocalAddr()},
|
|
||||||
} {
|
|
||||||
network := c.remote.Network()
|
|
||||||
conn, err := (&stdnet.Dialer{LocalAddr: c.local}).Dial(network, c.remote.String())
|
|
||||||
if errors.Is(err, syscall.EAFNOSUPPORT) {
|
|
||||||
t.Skip("no IPv6 sockets here")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
local := netip.MustParseAddrPort(conn.LocalAddr().String())
|
|
||||||
remote := netip.MustParseAddrPort(c.remote.String())
|
|
||||||
pid, _, _, err := FindProcess(network, "127.0.0.1", local.Port(), "127.0.0.1", remote.Port())
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%s: %v", network, err)
|
|
||||||
} else if pid != os.Getpid() {
|
|
||||||
t.Errorf("%s: found PID %d, want %d", network, pid, os.Getpid())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/net/network.proto
|
// source: common/net/network.proto
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/net/port.proto
|
// source: common/net/port.proto
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/platform"
|
"github.com/xtls/xray-core/common/platform"
|
||||||
@@ -27,6 +26,14 @@ func ReadFile(path string) ([]byte, error) {
|
|||||||
return buf.ReadAllToBytes(reader)
|
return buf.ReadAllToBytes(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadAsset(file string) ([]byte, error) {
|
||||||
|
path, _, err := getAssetFileLocation(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ReadFile(path)
|
||||||
|
}
|
||||||
|
|
||||||
func OpenAsset(file string) (io.ReadCloser, int64, error) {
|
func OpenAsset(file string) (io.ReadCloser, int64, error) {
|
||||||
path, info, err := getAssetFileLocation(file)
|
path, info, err := getAssetFileLocation(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -36,6 +43,11 @@ func OpenAsset(file string) (io.ReadCloser, int64, error) {
|
|||||||
return r, info.Size(), err
|
return r, info.Size(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StatAsset(file string) (os.FileInfo, error) {
|
||||||
|
_, info, err := getAssetFileLocation(file)
|
||||||
|
return info, err
|
||||||
|
}
|
||||||
|
|
||||||
func ResolveAsset(file string) (string, error) {
|
func ResolveAsset(file string) (string, error) {
|
||||||
path, _, err := getAssetFileLocation(file)
|
path, _, err := getAssetFileLocation(file)
|
||||||
return path, err
|
return path, err
|
||||||
@@ -67,29 +79,17 @@ func ReadCert(file string) ([]byte, error) {
|
|||||||
return ReadFile(platform.GetCertLocation(file))
|
return ReadFile(platform.GetCertLocation(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveLuaFile finds a local .lua script and returns its absolute path.
|
func CopyFile(dst string, src string) error {
|
||||||
// Relative paths: XRAY_LOCATION_CONFDIR > XRAY_LOCATION_CONFIG > working dir > executable dir.
|
bytes, err := ReadFile(src)
|
||||||
func ResolveLuaFile(path string) (string, error) {
|
if err != nil {
|
||||||
if !strings.EqualFold(filepath.Ext(path), ".lua") {
|
return err
|
||||||
return "", errors.New("Lua file extension must be .lua")
|
|
||||||
}
|
}
|
||||||
if filepath.IsAbs(path) {
|
f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0o644)
|
||||||
return path, nil
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
for _, dir := range []string{
|
defer f.Close()
|
||||||
platform.GetConfDirPath(),
|
|
||||||
platform.NewEnvFlag(platform.ConfigLocation).GetValue(func() string { return "" }),
|
_, err = f.Write(bytes)
|
||||||
".",
|
return err
|
||||||
platform.GetExecutableDir(),
|
|
||||||
} {
|
|
||||||
if dir != "" {
|
|
||||||
resolved := filepath.Join(dir, path)
|
|
||||||
if _, err := os.Stat(resolved); err == nil {
|
|
||||||
return filepath.Abs(resolved)
|
|
||||||
} else if !os.IsNotExist(err) {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", os.ErrNotExist
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
package filesystem_test
|
package filesystem_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/platform"
|
|
||||||
. "github.com/xtls/xray-core/common/platform/filesystem"
|
. "github.com/xtls/xray-core/common/platform/filesystem"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveAssetRejectsInvalidPath(t *testing.T) {
|
func TestStatAssetRejectsInvalidPath(t *testing.T) {
|
||||||
for _, file := range []string{
|
for _, file := range []string{
|
||||||
"",
|
"",
|
||||||
".",
|
".",
|
||||||
@@ -29,49 +25,8 @@ func TestResolveAssetRejectsInvalidPath(t *testing.T) {
|
|||||||
`nested\..\geoip.dat`,
|
`nested\..\geoip.dat`,
|
||||||
filepath.Join(t.TempDir(), "geoip.dat"),
|
filepath.Join(t.TempDir(), "geoip.dat"),
|
||||||
} {
|
} {
|
||||||
if _, err := ResolveAsset(file); err == nil {
|
if _, err := StatAsset(file); err == nil {
|
||||||
t.Fatalf("expected error for %q", file)
|
t.Fatalf("expected error for %q", file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveLuaFile(t *testing.T) {
|
|
||||||
t.Chdir(t.TempDir())
|
|
||||||
workingDir, err := os.Getwd()
|
|
||||||
common.Must(err)
|
|
||||||
executable, err := os.Executable()
|
|
||||||
common.Must(err)
|
|
||||||
file, err := os.CreateTemp(filepath.Dir(executable), "lua-*.lua")
|
|
||||||
common.Must(err)
|
|
||||||
common.Must(file.Close())
|
|
||||||
defer os.Remove(file.Name())
|
|
||||||
|
|
||||||
name := filepath.Base(file.Name())
|
|
||||||
paths := []string{
|
|
||||||
filepath.Join(t.TempDir(), name),
|
|
||||||
filepath.Join(t.TempDir(), name),
|
|
||||||
filepath.Join(workingDir, name),
|
|
||||||
file.Name(),
|
|
||||||
}
|
|
||||||
t.Setenv(platform.ConfdirLocation, filepath.Dir(paths[0]))
|
|
||||||
t.Setenv(platform.ConfigLocation, filepath.Dir(paths[1]))
|
|
||||||
for _, path := range paths[:3] {
|
|
||||||
common.Must(os.WriteFile(path, nil, 0o600))
|
|
||||||
}
|
|
||||||
if got, err := ResolveLuaFile(paths[2]); err != nil || got != paths[2] {
|
|
||||||
t.Fatalf("absolute path = %q, %v; want %q", got, err, paths[2])
|
|
||||||
}
|
|
||||||
for i, want := range paths {
|
|
||||||
if i == 2 {
|
|
||||||
t.Setenv(platform.ConfdirLocation, "")
|
|
||||||
t.Setenv(platform.ConfigLocation, "")
|
|
||||||
}
|
|
||||||
if got, err := ResolveLuaFile(name); err != nil || got != want {
|
|
||||||
t.Fatalf("resolved path = %q, %v; want %q", got, err, want)
|
|
||||||
}
|
|
||||||
common.Must(os.Remove(want))
|
|
||||||
}
|
|
||||||
if _, err := ResolveLuaFile(name); !errors.Is(err, os.ErrNotExist) {
|
|
||||||
t.Fatalf("missing file error = %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ func LineSeparator() string {
|
|||||||
|
|
||||||
// GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations
|
// GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations
|
||||||
func GetAssetLocation(file string) string {
|
func GetAssetLocation(file string) string {
|
||||||
assetPath := NewEnvFlag(AssetLocation).GetValue(GetExecutableDir)
|
assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
|
||||||
defPath := filepath.Join(assetPath, file)
|
defPath := filepath.Join(assetPath, file)
|
||||||
for _, p := range []string{
|
for _, p := range []string{
|
||||||
defPath,
|
defPath,
|
||||||
@@ -35,6 +36,6 @@ func GetAssetLocation(file string) string {
|
|||||||
|
|
||||||
// GetCertLocation searches for `file` in the env dir and the executable dir
|
// GetCertLocation searches for `file` in the env dir and the executable dir
|
||||||
func GetCertLocation(file string) string {
|
func GetCertLocation(file string) string {
|
||||||
certPath := NewEnvFlag(CertLocation).GetValue(GetExecutableDir)
|
certPath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
|
||||||
return filepath.Join(certPath, file)
|
return filepath.Join(certPath, file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package platform // import "github.com/xtls/xray-core/common/platform"
|
package platform // import "github.com/xtls/xray-core/common/platform"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -16,6 +18,7 @@ const (
|
|||||||
UseReadV = "xray.buf.readv"
|
UseReadV = "xray.buf.readv"
|
||||||
UseFreedomSplice = "xray.buf.splice"
|
UseFreedomSplice = "xray.buf.splice"
|
||||||
UseVmessPadding = "xray.vmess.padding"
|
UseVmessPadding = "xray.vmess.padding"
|
||||||
|
UseCone = "xray.cone.disabled"
|
||||||
UseStrictJSON = "xray.json.strict"
|
UseStrictJSON = "xray.json.strict"
|
||||||
|
|
||||||
BufferSize = "xray.ray.buffer.size"
|
BufferSize = "xray.ray.buffer.size"
|
||||||
@@ -71,7 +74,7 @@ func NormalizeEnvName(name string) string {
|
|||||||
return strings.ReplaceAll(strings.ToUpper(strings.TrimSpace(name)), ".", "_")
|
return strings.ReplaceAll(strings.ToUpper(strings.TrimSpace(name)), ".", "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetExecutableDir() string {
|
func getExecutableDir() string {
|
||||||
exec, err := os.Executable()
|
exec, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -80,7 +83,7 @@ func GetExecutableDir() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigurationPath() string {
|
func GetConfigurationPath() string {
|
||||||
configPath := NewEnvFlag(ConfigLocation).GetValue(GetExecutableDir)
|
configPath := NewEnvFlag(ConfigLocation).GetValue(getExecutableDir)
|
||||||
return filepath.Join(configPath, "config.json")
|
return filepath.Join(configPath, "config.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,3 +92,64 @@ func GetConfDirPath() string {
|
|||||||
configPath := NewEnvFlag(ConfdirLocation).GetValue(func() string { return "" })
|
configPath := NewEnvFlag(ConfdirLocation).GetValue(func() string { return "" })
|
||||||
return configPath
|
return configPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResolveLuaFile finds a local .lua script and returns its resolved absolute path.
|
||||||
|
// Relative paths: XRAY_LOCATION_CONFDIR > XRAY_LOCATION_CONFIG > working dir > executable dir.
|
||||||
|
func ResolveLuaFile(path string) (string, error) {
|
||||||
|
if path == "" {
|
||||||
|
return "", errors.New("Lua file path is empty")
|
||||||
|
}
|
||||||
|
paths := []string{path}
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
paths = nil
|
||||||
|
for _, dir := range []string{
|
||||||
|
GetConfDirPath(),
|
||||||
|
NewEnvFlag(ConfigLocation).GetValue(func() string { return "" }),
|
||||||
|
".",
|
||||||
|
getExecutableDir(),
|
||||||
|
} {
|
||||||
|
if dir != "" {
|
||||||
|
paths = append(paths, filepath.Join(dir, path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path, err := resolveFile(paths)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return resolveLuaTarget(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveLuaTarget(path string) (string, error) {
|
||||||
|
path, err := filepath.EvalSymlinks(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to resolve Lua file symlinks: %w", err)
|
||||||
|
}
|
||||||
|
if filepath.Ext(path) != ".lua" {
|
||||||
|
return "", errors.New("Lua file extension must be .lua")
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveFile(paths []string) (string, error) {
|
||||||
|
var tried []string
|
||||||
|
for _, path := range paths {
|
||||||
|
path, err := filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to resolve file path: %w", err)
|
||||||
|
}
|
||||||
|
tried = append(tried, path)
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to inspect file %q: %w", path, err)
|
||||||
|
}
|
||||||
|
if !info.Mode().IsRegular() {
|
||||||
|
return "", fmt.Errorf("file is not a regular file: %s", path)
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("file not found; tried %q: %w", tried, os.ErrNotExist)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package platform_test
|
package platform_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@@ -64,3 +66,89 @@ func TestGetAssetLocation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResolveLuaFile(t *testing.T) {
|
||||||
|
workingDir := t.TempDir()
|
||||||
|
t.Chdir(workingDir)
|
||||||
|
executable, err := os.Executable()
|
||||||
|
common.Must(err)
|
||||||
|
file, err := os.CreateTemp(filepath.Dir(executable), "lua-*.lua")
|
||||||
|
common.Must(err)
|
||||||
|
common.Must(file.Close())
|
||||||
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
|
name := filepath.Base(file.Name())
|
||||||
|
paths := []string{
|
||||||
|
filepath.Join(t.TempDir(), name),
|
||||||
|
filepath.Join(t.TempDir(), name),
|
||||||
|
filepath.Join(workingDir, name),
|
||||||
|
file.Name(),
|
||||||
|
}
|
||||||
|
t.Setenv(ConfdirLocation, filepath.Dir(paths[0]))
|
||||||
|
t.Setenv(ConfigLocation, filepath.Dir(paths[1]))
|
||||||
|
for _, path := range paths[:3] {
|
||||||
|
common.Must(os.WriteFile(path, nil, 0o600))
|
||||||
|
}
|
||||||
|
for i, path := range paths {
|
||||||
|
paths[i], err = filepath.EvalSymlinks(path)
|
||||||
|
common.Must(err)
|
||||||
|
}
|
||||||
|
if got, err := ResolveLuaFile(paths[2]); err != nil || got != paths[2] {
|
||||||
|
t.Fatalf("absolute path = %q, %v; want %q", got, err, paths[2])
|
||||||
|
}
|
||||||
|
for i, want := range paths {
|
||||||
|
if i == 2 {
|
||||||
|
t.Setenv(ConfdirLocation, "")
|
||||||
|
t.Setenv(ConfigLocation, "")
|
||||||
|
}
|
||||||
|
if got, err := ResolveLuaFile(name); err != nil || got != want {
|
||||||
|
t.Fatalf("resolved path = %q, %v; want %q", got, err, want)
|
||||||
|
}
|
||||||
|
common.Must(os.Remove(want))
|
||||||
|
}
|
||||||
|
if _, err := ResolveLuaFile(name); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
t.Fatalf("missing file error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Setenv(ConfdirLocation, filepath.Dir(paths[0]))
|
||||||
|
t.Setenv(ConfigLocation, filepath.Dir(paths[1]))
|
||||||
|
common.Must(os.Mkdir(paths[0], 0o700))
|
||||||
|
common.Must(os.WriteFile(paths[1], nil, 0o600))
|
||||||
|
for _, path := range []string{"", name, filepath.Join(t.TempDir(), name)} {
|
||||||
|
if _, err := ResolveLuaFile(path); err == nil {
|
||||||
|
t.Fatalf("accepted invalid path %q", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveLuaFileSymlink(t *testing.T) {
|
||||||
|
for _, tc := range []struct {
|
||||||
|
link, target string
|
||||||
|
valid bool
|
||||||
|
}{
|
||||||
|
{"alias.lua", "data.dat", false},
|
||||||
|
{"alias.dat", "script.lua", true},
|
||||||
|
} {
|
||||||
|
t.Run(tc.link, func(t *testing.T) {
|
||||||
|
dir, err := filepath.EvalSymlinks(t.TempDir())
|
||||||
|
common.Must(err)
|
||||||
|
target := filepath.Join(dir, tc.target)
|
||||||
|
common.Must(os.WriteFile(target, nil, 0o600))
|
||||||
|
link := filepath.Join(dir, tc.link)
|
||||||
|
if err := os.Symlink(tc.target, link); err != nil {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skipf("cannot create symlinks: %v", err)
|
||||||
|
}
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got, err := ResolveLuaFile(link)
|
||||||
|
if tc.valid {
|
||||||
|
if err != nil || got != target {
|
||||||
|
t.Fatalf("ResolveLuaFile(%q) = %q, %v; want %q", link, got, err, target)
|
||||||
|
}
|
||||||
|
} else if err == nil || got != "" || !strings.Contains(err.Error(), "Lua file extension must be .lua") {
|
||||||
|
t.Fatalf("ResolveLuaFile(%q) = %q, %v; want .lua extension error", link, got, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build windows
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
@@ -10,12 +11,12 @@ func LineSeparator() string {
|
|||||||
|
|
||||||
// GetAssetLocation searches for `file` in the env dir and the executable dir
|
// GetAssetLocation searches for `file` in the env dir and the executable dir
|
||||||
func GetAssetLocation(file string) string {
|
func GetAssetLocation(file string) string {
|
||||||
assetPath := NewEnvFlag(AssetLocation).GetValue(GetExecutableDir)
|
assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
|
||||||
return filepath.Join(assetPath, file)
|
return filepath.Join(assetPath, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCertLocation searches for `file` in the env dir and the executable dir
|
// GetCertLocation searches for `file` in the env dir and the executable dir
|
||||||
func GetCertLocation(file string) string {
|
func GetCertLocation(file string) string {
|
||||||
certPath := NewEnvFlag(CertLocation).GetValue(GetExecutableDir)
|
certPath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
|
||||||
return filepath.Join(certPath, file)
|
return filepath.Join(certPath, file)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/protocol/headers.proto
|
// source: common/protocol/headers.proto
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/protocol/server_spec.proto
|
// source: common/protocol/server_spec.proto
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|||||||
@@ -101,10 +101,6 @@ func ReadClientHello(data []byte, h *SniffHeader) error {
|
|||||||
return errNotClientHello
|
return errNotClientHello
|
||||||
}
|
}
|
||||||
if nameType == 0 {
|
if nameType == 0 {
|
||||||
// RFC 6066 requires a non-empty HostName.
|
|
||||||
if nameLen == 0 {
|
|
||||||
return errNotClientHello
|
|
||||||
}
|
|
||||||
// QUIC separated across packets
|
// QUIC separated across packets
|
||||||
// May cause the serverName to be incomplete
|
// May cause the serverName to be incomplete
|
||||||
b := byte(0)
|
b := byte(0)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/protocol/user.proto
|
// source: common/protocol/user.proto
|
||||||
|
|
||||||
package protocol
|
package protocol
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func TestMarshalConfigJson(t *testing.T) {
|
|||||||
func getConfig() string {
|
func getConfig() string {
|
||||||
return `{
|
return `{
|
||||||
"log": {
|
"log": {
|
||||||
"logLevel": "debug"
|
"loglevel": "debug"
|
||||||
},
|
},
|
||||||
"stats": {},
|
"stats": {},
|
||||||
"policy": {
|
"policy": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: common/serial/typed_message.proto
|
// source: common/serial/typed_message.proto
|
||||||
|
|
||||||
package serial
|
package serial
|
||||||
|
|||||||
+32
-31
@@ -3,11 +3,7 @@ package signal
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/task"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActivityUpdater interface {
|
type ActivityUpdater interface {
|
||||||
@@ -17,10 +13,10 @@ type ActivityUpdater interface {
|
|||||||
type ActivityTimer struct {
|
type ActivityTimer struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
updated chan struct{}
|
updated chan struct{}
|
||||||
checkTask *task.Periodic
|
checker *time.Timer
|
||||||
|
timeout time.Duration
|
||||||
onTimeout func()
|
onTimeout func()
|
||||||
consumed atomic.Bool
|
consumed bool
|
||||||
once sync.Once
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ActivityTimer) Update() {
|
func (t *ActivityTimer) Update() {
|
||||||
@@ -30,30 +26,29 @@ func (t *ActivityTimer) Update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ActivityTimer) check() error {
|
func (t *ActivityTimer) check() bool {
|
||||||
select {
|
select {
|
||||||
case <-t.updated:
|
case <-t.updated:
|
||||||
|
return true
|
||||||
default:
|
default:
|
||||||
t.finish()
|
t.finish()
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ActivityTimer) finish() {
|
func (t *ActivityTimer) finish() {
|
||||||
t.once.Do(func() {
|
t.mu.Lock()
|
||||||
t.consumed.Store(true)
|
if t.consumed {
|
||||||
t.mu.Lock()
|
t.mu.Unlock()
|
||||||
defer t.mu.Unlock()
|
return
|
||||||
|
}
|
||||||
common.CloseIfExists(t.checkTask)
|
t.checker.Stop()
|
||||||
t.onTimeout()
|
t.consumed = true
|
||||||
})
|
t.mu.Unlock()
|
||||||
|
t.onTimeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||||
if t.consumed.Load() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
t.finish()
|
t.finish()
|
||||||
return
|
return
|
||||||
@@ -61,25 +56,31 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
|||||||
|
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
defer t.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
// double check, just in case
|
if t.consumed {
|
||||||
if t.consumed.Load() {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newCheckTask := &task.Periodic{
|
t.timeout = timeout
|
||||||
Interval: timeout,
|
t.checker.Reset(timeout)
|
||||||
Execute: t.check,
|
|
||||||
}
|
|
||||||
common.CloseIfExists(t.checkTask)
|
|
||||||
t.checkTask = newCheckTask
|
|
||||||
t.Update()
|
|
||||||
common.Must(newCheckTask.Start())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
||||||
timer := &ActivityTimer{
|
timer := &ActivityTimer{
|
||||||
updated: make(chan struct{}, 1),
|
updated: make(chan struct{}, 1),
|
||||||
onTimeout: cancel,
|
onTimeout: cancel,
|
||||||
|
timeout: timeout,
|
||||||
|
}
|
||||||
|
timer.checker = time.AfterFunc(timeout, func() {
|
||||||
|
if timer.check() {
|
||||||
|
timer.mu.Lock()
|
||||||
|
defer timer.mu.Unlock()
|
||||||
|
if timer.consumed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
timer.checker.Reset(timer.timeout)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if timeout == 0 {
|
||||||
|
timer.SetTimeout(0)
|
||||||
}
|
}
|
||||||
timer.SetTimeout(timeout)
|
|
||||||
return timer
|
return timer
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetGlobalID(ctx context.Context) (globalID [8]byte) {
|
func GetGlobalID(ctx context.Context) (globalID [8]byte) {
|
||||||
|
if cone := ctx.Value("cone"); cone == nil || !cone.(bool) { // cone is nil only in some unit tests
|
||||||
|
return
|
||||||
|
}
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.Network == net.Network_UDP &&
|
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.Network == net.Network_UDP &&
|
||||||
(inbound.Name == "dokodemo-door" || inbound.Name == "socks" || inbound.Name == "shadowsocks" || inbound.Name == "tun") {
|
(inbound.Name == "dokodemo-door" || inbound.Name == "socks" || inbound.Name == "shadowsocks" || inbound.Name == "tun") {
|
||||||
h := blake3.New(8, ensureBaseKey())
|
h := blake3.New(8, ensureBaseKey())
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.36.12
|
// protoc-gen-go v1.36.11
|
||||||
// protoc (unknown)
|
// protoc v6.33.5
|
||||||
// source: core/config.proto
|
// source: core/config.proto
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
Version_x byte = 26
|
Version_x byte = 26
|
||||||
Version_y byte = 11
|
Version_y byte = 10
|
||||||
Version_z byte = 9
|
Version_z byte = 17
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestXrayDial(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -105,7 +105,7 @@ func TestXrayDialUDPConn(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -174,7 +174,7 @@ func TestXrayDialUDP(t *testing.T) {
|
|||||||
Outbound: []*core.OutboundHandlerConfig{
|
Outbound: []*core.OutboundHandlerConfig{
|
||||||
{
|
{
|
||||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{Action: freedom.RuleAction_Allow}},
|
FinalRules: []*freedom.FinalRuleConfig{{Action: freedom.RuleAction_Allow}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
|
//go:generate go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||||
|
//go:generate go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
//go:generate go run ../infra/vprotogen/main.go -pwd ./..
|
//go:generate go run ../infra/vprotogen/main.go -pwd ./..
|
||||||
|
|||||||
@@ -192,6 +192,8 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
|
|||||||
if err := platform.ReloadEnvSettings(); err != nil {
|
if err := platform.ReloadEnvSettings(); err != nil {
|
||||||
return true, errors.New("failed to reload environment settings").Base(err)
|
return true, errors.New("failed to reload environment settings").Base(err)
|
||||||
}
|
}
|
||||||
|
server.ctx = context.WithValue(server.ctx, "cone",
|
||||||
|
platform.NewEnvFlag(platform.UseCone).GetValue(func() string { return "" }) != "true")
|
||||||
|
|
||||||
for _, appSettings := range config.App {
|
for _, appSettings := range config.App {
|
||||||
settings, err := appSettings.GetInstance()
|
settings, err := appSettings.GetInstance()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package localdns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/netip"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -101,15 +100,6 @@ func New() *Client {
|
|||||||
if internet.IsSkippedDNSServer(address) {
|
if internet.IsSkippedDNSServer(address) {
|
||||||
return nil, errors.New("skipped DNS server ", address)
|
return nil, errors.New("skipped DNS server ", address)
|
||||||
}
|
}
|
||||||
// A socket of the server's IP version only needs that version bound
|
|
||||||
// to the interface, which a dual-stack one would need both of.
|
|
||||||
if ap, err := netip.ParseAddrPort(address); err == nil && (network == "udp" || network == "tcp") {
|
|
||||||
if ap.Addr().Unmap().Is4() {
|
|
||||||
network += "4"
|
|
||||||
} else {
|
|
||||||
network += "6"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d.DialContext(ctx, network, address)
|
return d.DialContext(ctx, network, address)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,36 +3,35 @@ module github.com/xtls/xray-core
|
|||||||
go 1.27
|
go 1.27
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c
|
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e
|
||||||
github.com/bufbuild/protocompile v0.14.1
|
|
||||||
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
|
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344
|
||||||
github.com/golang/mock v1.7.0-rc.1
|
github.com/golang/mock v1.7.0-rc.1
|
||||||
github.com/google/go-cmp v0.7.0
|
github.com/google/go-cmp v0.7.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/klauspost/cpuid/v2 v2.4.2
|
github.com/klauspost/cpuid/v2 v2.4.1
|
||||||
github.com/libp2p/go-nat v1.0.1-0.20250821073202-01afc089f138
|
github.com/libp2p/go-nat v1.0.1-0.20250821073202-01afc089f138
|
||||||
github.com/miekg/dns v1.1.73
|
github.com/miekg/dns v1.1.73
|
||||||
github.com/pelletier/go-toml v1.9.5
|
github.com/pelletier/go-toml v1.9.5
|
||||||
github.com/pion/stun/v3 v3.1.7
|
github.com/pion/stun/v3 v3.1.7
|
||||||
github.com/pires/go-proxyproto v0.16.0
|
github.com/pires/go-proxyproto v0.15.0
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b
|
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/stretchr/testify v1.12.1
|
github.com/stretchr/testify v1.12.1
|
||||||
github.com/vishvananda/netlink v1.3.1
|
github.com/vishvananda/netlink v1.3.1
|
||||||
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b
|
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8
|
||||||
github.com/yuin/gopher-lua v1.1.2
|
github.com/yuin/gopher-lua v1.1.2
|
||||||
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
|
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
|
||||||
golang.org/x/crypto v0.58.0
|
golang.org/x/crypto v0.58.0
|
||||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20261020153306-9f2b28d4331a
|
golang.org/x/crypto/x509roots/fallback v0.0.0-20261020153306-9f2b28d4331a
|
||||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
|
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
|
||||||
golang.org/x/net v0.62.0
|
golang.org/x/net v0.61.0
|
||||||
golang.org/x/sync v0.24.0
|
golang.org/x/sync v0.24.0
|
||||||
golang.org/x/sys v0.49.0
|
golang.org/x/sys v0.49.0
|
||||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
|
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb
|
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb
|
||||||
golang.zx2c4.com/wireguard/windows v1.1.1
|
golang.zx2c4.com/wireguard/windows v1.1.1
|
||||||
google.golang.org/grpc v1.85.0
|
google.golang.org/grpc v1.84.0
|
||||||
google.golang.org/protobuf v1.36.12
|
google.golang.org/protobuf v1.36.12
|
||||||
h12.io/socks v1.0.3
|
h12.io/socks v1.0.3
|
||||||
layeh.com/gopher-luar v1.0.11
|
layeh.com/gopher-luar v1.0.11
|
||||||
@@ -41,14 +40,14 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/andybalholm/brotli v1.2.3 // indirect
|
||||||
github.com/google/gopacket v1.1.19 // indirect
|
github.com/google/gopacket v1.1.19 // indirect
|
||||||
github.com/huin/goupnp v1.2.0 // indirect
|
github.com/huin/goupnp v1.2.0 // indirect
|
||||||
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||||
github.com/juju/ratelimit v1.0.2 // indirect
|
github.com/juju/ratelimit v1.0.2 // indirect
|
||||||
github.com/klauspost/compress v1.20.4 // indirect
|
github.com/klauspost/compress v1.20.0 // indirect
|
||||||
github.com/koron/go-ssdp v0.0.4 // indirect
|
github.com/koron/go-ssdp v0.0.4 // indirect
|
||||||
github.com/libp2p/go-netroute v0.2.1 // indirect
|
github.com/libp2p/go-netroute v0.2.1 // indirect
|
||||||
github.com/molecule-man/go-brrr v1.2.0 // indirect
|
|
||||||
github.com/pion/dtls/v3 v3.1.5 // indirect
|
github.com/pion/dtls/v3 v3.1.5 // indirect
|
||||||
github.com/pion/logging v0.2.4 // indirect
|
github.com/pion/logging v0.2.4 // indirect
|
||||||
github.com/pion/transport/v4 v4.1.0 // indirect
|
github.com/pion/transport/v4 v4.1.0 // indirect
|
||||||
@@ -58,13 +57,7 @@ require (
|
|||||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||||
golang.org/x/text v0.43.0 // indirect
|
golang.org/x/text v0.43.0 // indirect
|
||||||
golang.org/x/tools v0.51.0 // indirect
|
golang.org/x/tools v0.51.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260817212433-ac3dfec99bb1 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 // indirect
|
||||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.2 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gvisor.dev/gvisor v0.0.0-20260122175437-89a5d21be8f0 // indirect
|
gvisor.dev/gvisor v0.0.0-20260122175437-89a5d21be8f0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
tool (
|
|
||||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
|
||||||
google.golang.org/protobuf/cmd/protoc-gen-go
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c h1:cxK8qTA0YCsj68A7zLYDCfPgMTOyt3ePkHh+oXEmYU0=
|
github.com/andybalholm/brotli v1.2.3 h1:8H1qwOkl2LPfjf3YezB90JnCliZb6SInJ/OJkEbA5NQ=
|
||||||
github.com/apernet/quic-go v0.63.1-0.20261004180939-a10df75c260c/go.mod h1:J7UZVOMF2M1LiE3iiUZWPuy8YCPAcLJOwVURrfJCvc0=
|
github.com/andybalholm/brotli v1.2.3/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||||
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e h1:5mgtR5gwIgBKMiGI1QdXldZZ+SNor06Nbu1wCBulQBg=
|
||||||
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
github.com/apernet/quic-go v0.61.1-0.20260806010916-184d081eef3e/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||||
@@ -31,12 +31,10 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
|
|||||||
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
||||||
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
|
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
|
||||||
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
|
||||||
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
|
github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA=
|
||||||
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
||||||
github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI=
|
github.com/klauspost/cpuid/v2 v2.4.1 h1:I9KxadAkvo+QjtcEE2f2tyfEvmIla/T0m+14PrZNl0U=
|
||||||
github.com/klauspost/compress v1.20.4/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
github.com/klauspost/cpuid/v2 v2.4.1/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
||||||
github.com/klauspost/cpuid/v2 v2.4.2 h1:xRw7IZEsAgVCp6trS/DgWbTAqpixhmywgVgBjYGg1bQ=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.4.2/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
|
||||||
github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
|
github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0=
|
||||||
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
|
github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
@@ -49,8 +47,6 @@ github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9t
|
|||||||
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
github.com/libp2p/go-netroute v0.2.1/go.mod h1:hraioZr0fhBjG0ZRXJJ6Zj2IVEVNx6tDTFQfSmcq7mQ=
|
||||||
github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
|
github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE=
|
||||||
github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
|
github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ=
|
||||||
github.com/molecule-man/go-brrr v1.2.0 h1:dOJU45BC3Gc2WXoxAW0rgCAgVuu2gruAOGncfieA0Jw=
|
|
||||||
github.com/molecule-man/go-brrr v1.2.0/go.mod h1:7ybW6/7gA3oKY45jOfVNjSJDtrr6ea4tzbsTkjmQDC4=
|
|
||||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
||||||
@@ -63,14 +59,14 @@ github.com/pion/stun/v3 v3.1.7 h1:uRXMTlGLf89WgItGNyZ6aR5jMTX0NBbybXADpQCzn+E=
|
|||||||
github.com/pion/stun/v3 v3.1.7/go.mod h1:Nq77RW4aRrSNrltf2ksUJLjxWeipj4lnlgdsYIxC8g8=
|
github.com/pion/stun/v3 v3.1.7/go.mod h1:Nq77RW4aRrSNrltf2ksUJLjxWeipj4lnlgdsYIxC8g8=
|
||||||
github.com/pion/transport/v4 v4.1.0 h1:8S+nF2reM2cJuqC6g78OVy2BBgmbdns+acx3jA97BvQ=
|
github.com/pion/transport/v4 v4.1.0 h1:8S+nF2reM2cJuqC6g78OVy2BBgmbdns+acx3jA97BvQ=
|
||||||
github.com/pion/transport/v4 v4.1.0/go.mod h1:06hFI+jCFcok2X2MekVufNZ/uzNZXivGBPfviSVcjgM=
|
github.com/pion/transport/v4 v4.1.0/go.mod h1:06hFI+jCFcok2X2MekVufNZ/uzNZXivGBPfviSVcjgM=
|
||||||
github.com/pires/go-proxyproto v0.16.0 h1:9KYT/fM3wpjT8bdMEj/7FBcoiUG1KyzEjRYnPu+vz7A=
|
github.com/pires/go-proxyproto v0.15.0 h1:dTshmNbFm/D+0+sbrxUuddPOZ5Y0B7c5NhtsBkm6LqI=
|
||||||
github.com/pires/go-proxyproto v0.16.0/go.mod h1:n7yhg8yIfNl3KgYDCwBzmeUHNpKTVnUhcWpc7rV4RW4=
|
github.com/pires/go-proxyproto v0.15.0/go.mod h1:OXsCrKwrK2tXS9YrI5tkHx5xaQlO8FH3lFW76orFh24=
|
||||||
github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0=
|
github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0=
|
||||||
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
|
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
|
||||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b h1:Mi/DuaTxHeNIQ9g1ylZicAqa6Cb9wkHRiNtQH9uZ7Ts=
|
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af h1:er2acxbi3N1nvEq6HXHUAR1nTWEJmQfqiGR8EVT9rfs=
|
||||||
github.com/refraction-networking/utls v1.8.3-0.20261108164504-a13c59ffe98b/go.mod h1:rc/ctWeKlh9LSk5k90KlSPcwF7P6D31mn/9GI2NAfBI=
|
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
|
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
|
||||||
@@ -83,8 +79,10 @@ github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zd
|
|||||||
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
|
||||||
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
|
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
|
||||||
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
||||||
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b h1:fAn11r21QiUY2oAGwENWb5ummjhWwMcs2WzkbjDMh+k=
|
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8 h1:RjLnVvlzK4q6zWaSBPNRGsrgx2fbJDeUWffjw574uzs=
|
||||||
github.com/xtls/reality v0.0.0-20261108101329-4bb46b2afd8b/go.mod h1:ptlSkJ8k/7IDauNH0SA96JPOo+nYGLTv2Y3UMpwvAsY=
|
github.com/xtls/reality v0.0.0-20261014101318-83f621788ca8/go.mod h1:ptlSkJ8k/7IDauNH0SA96JPOo+nYGLTv2Y3UMpwvAsY=
|
||||||
|
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||||
|
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||||
github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA=
|
github.com/yuin/gopher-lua v1.1.2 h1:yF/FjE3hD65tBbt0VXLE13HWS9h34fdzJmrWRXwobGA=
|
||||||
@@ -109,8 +107,8 @@ golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
|||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
|
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
|
||||||
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||||
@@ -150,12 +148,10 @@ golang.zx2c4.com/wireguard/windows v1.1.1 h1:8/H97U1v1PNDNcBsMZgU3KFuND9MQdTsU2N
|
|||||||
golang.zx2c4.com/wireguard/windows v1.1.1/go.mod h1:+fbT3FFdX4zzYDLwJh5+HPEcNN/3HyNdzhNSVsQM+zs=
|
golang.zx2c4.com/wireguard/windows v1.1.1/go.mod h1:+fbT3FFdX4zzYDLwJh5+HPEcNN/3HyNdzhNSVsQM+zs=
|
||||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||||
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260817212433-ac3dfec99bb1 h1:utmqiUzZAEINbLmRyAt1QjVkMyLQ+lvIwCpLaB1rZfw=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800 h1:qEHAMpSaUhtD0p3NbEEI83HwNGFxEwaSJ1G9PLnCBZE=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260817212433-ac3dfec99bb1/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260706201446-f0a921348800/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||||
google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw=
|
google.golang.org/grpc v1.84.0 h1:soMyaPJ8pAak5PIQ0DGBUir0XRo2fRoMqhNWMLlLxO0=
|
||||||
google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ=
|
google.golang.org/grpc v1.84.0/go.mod h1:ljCht0DrxQrXBDRTZp52Qxh3Ffk8CdYm2sj4O2QN2C0=
|
||||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.2 h1:rgSNvqscFZ1JgV/4wH5GOsZFSFkR2Eua9As3KIr2LlM=
|
|
||||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.2/go.mod h1:iMEtFwDlAhjDU9L5mY6U1XLwlIId/G3h+QcBHDIvrJ8=
|
|
||||||
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
|
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
|
||||||
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
+6
-12
@@ -5,8 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/log"
|
"github.com/xtls/xray-core/proxy/blackhole"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,29 +19,24 @@ type BlackholeConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
func (v *BlackholeConfig) Build() (proto.Message, error) {
|
||||||
errors.PrintDeprecatedFeatureWarning(`"blackhole" outbound`, `"freedom" outbound with a blocking "firewall" rule`)
|
config := new(blackhole.Config)
|
||||||
rule := &freedom.FirewallConfig{
|
|
||||||
Action: freedom.RuleAction_Block,
|
|
||||||
Delay: &freedom.Range{},
|
|
||||||
LogLevel: log.Severity_Unknown.Enum(),
|
|
||||||
}
|
|
||||||
if v.Response != nil {
|
if v.Response != nil {
|
||||||
responseName := strings.ToLower(v.Response.Type)
|
responseName := strings.ToLower(v.Response.Type)
|
||||||
switch responseName {
|
switch responseName {
|
||||||
case "none", "":
|
case "none", "":
|
||||||
rule.Reply = &freedom.Reply{Type: "none"}
|
config.Response = &blackhole.Response{Type: "none"}
|
||||||
case "http":
|
case "http":
|
||||||
rule.Reply = &freedom.Reply{Type: "http"}
|
config.Response = &blackhole.Response{Type: "http"}
|
||||||
case "custom":
|
case "custom":
|
||||||
data, err := base64.StdEncoding.DecodeString(v.Response.CustomResponseData)
|
data, err := base64.StdEncoding.DecodeString(v.Response.CustomResponseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to decode custom response data: " + err.Error())
|
return nil, errors.New("failed to decode custom response data: " + err.Error())
|
||||||
}
|
}
|
||||||
rule.Reply = &freedom.Reply{Type: "custom", CustomResponseData: data}
|
config.Response = &blackhole.Response{Type: "custom", CustomResponseData: data}
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unknown blackhole response: " + responseName)
|
return nil, errors.New("unknown blackhole response: " + responseName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &freedom.Config{Firewall: []*freedom.FirewallConfig{rule}}, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package conf_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/log"
|
|
||||||
. "github.com/xtls/xray-core/infra/conf"
|
. "github.com/xtls/xray-core/infra/conf"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/blackhole"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPResponseJSON(t *testing.T) {
|
func TestHTTPResponseJSON(t *testing.T) {
|
||||||
@@ -21,25 +20,14 @@ func TestHTTPResponseJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &freedom.Config{
|
Output: &blackhole.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{
|
Response: &blackhole.Response{Type: "http"},
|
||||||
Action: freedom.RuleAction_Block,
|
|
||||||
Delay: &freedom.Range{},
|
|
||||||
LogLevel: log.Severity_Unknown.Enum(),
|
|
||||||
Reply: &freedom.Reply{Type: "http"},
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{}`,
|
Input: `{}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &freedom.Config{
|
Output: &blackhole.Config{},
|
||||||
Firewall: []*freedom.FirewallConfig{{
|
|
||||||
Action: freedom.RuleAction_Block,
|
|
||||||
Delay: &freedom.Range{},
|
|
||||||
LogLevel: log.Severity_Unknown.Enum(),
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -58,16 +46,11 @@ func TestCustomResponseJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &freedom.Config{
|
Output: &blackhole.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{{
|
Response: &blackhole.Response{
|
||||||
Action: freedom.RuleAction_Block,
|
Type: "custom",
|
||||||
Delay: &freedom.Range{},
|
CustomResponseData: []byte("custom response"),
|
||||||
LogLevel: log.Severity_Unknown.Enum(),
|
},
|
||||||
Reply: &freedom.Reply{
|
|
||||||
Type: "custom",
|
|
||||||
CustomResponseData: []byte("custom response"),
|
|
||||||
},
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
+25
-97
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
"github.com/xtls/xray-core/common/log"
|
|
||||||
xnet "github.com/xtls/xray-core/common/net"
|
xnet "github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/proxy/freedom"
|
"github.com/xtls/xray-core/proxy/freedom"
|
||||||
@@ -18,17 +17,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FreedomConfig struct {
|
type FreedomConfig struct {
|
||||||
TargetStrategy string `json:"targetStrategy"`
|
TargetStrategy string `json:"targetStrategy"`
|
||||||
DomainStrategy string `json:"domainStrategy"`
|
DomainStrategy string `json:"domainStrategy"`
|
||||||
Redirect string `json:"redirect"`
|
Redirect string `json:"redirect"`
|
||||||
UserLevel uint32 `json:"userLevel"`
|
UserLevel uint32 `json:"userLevel"`
|
||||||
Fragment *Fragment `json:"fragment"`
|
Fragment *Fragment `json:"fragment"`
|
||||||
Noise *Noise `json:"noise"`
|
Noise *Noise `json:"noise"`
|
||||||
Noises []*Noise `json:"noises"`
|
Noises []*Noise `json:"noises"`
|
||||||
ProxyProtocol uint32 `json:"proxyProtocol"`
|
ProxyProtocol uint32 `json:"proxyProtocol"`
|
||||||
IPsBlocked *StringList `json:"ipsBlocked"`
|
IPsBlocked *StringList `json:"ipsBlocked"`
|
||||||
Firewall []*FreedomFirewallConfig `json:"firewall"`
|
FinalRules []*FreedomFinalRuleConfig `json:"finalRules"`
|
||||||
FinalRules []*FreedomFirewallConfig `json:"finalRules"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Fragment struct {
|
type Fragment struct {
|
||||||
@@ -45,45 +43,19 @@ type Noise struct {
|
|||||||
ApplyTo string `json:"applyTo"`
|
ApplyTo string `json:"applyTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FreedomFirewallConfig struct {
|
type FreedomFinalRuleConfig struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Network *NetworkList `json:"network"`
|
Network *NetworkList `json:"network"`
|
||||||
Port *PortList `json:"port"`
|
Port *PortList `json:"port"`
|
||||||
IP *StringList `json:"ip"`
|
IP *StringList `json:"ip"`
|
||||||
Delay *Int32Range `json:"delay"`
|
BlockDelay *Int32Range `json:"blockDelay"`
|
||||||
LogLevel string `json:"logLevel"`
|
|
||||||
Reply *FreedomReplyConfig `json:"reply"`
|
|
||||||
BlockDelay *Int32Range `json:"blockDelay"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type FreedomReplyConfig struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
CustomResponseData string `json:"customResponseData"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FreedomReplyConfig) Build() (*freedom.Reply, error) {
|
|
||||||
replyType := strings.ToLower(c.Type)
|
|
||||||
switch replyType {
|
|
||||||
case "none", "":
|
|
||||||
return &freedom.Reply{Type: "none"}, nil
|
|
||||||
case "http":
|
|
||||||
return &freedom.Reply{Type: "http"}, nil
|
|
||||||
case "custom":
|
|
||||||
data, err := base64.StdEncoding.DecodeString(c.CustomResponseData)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("failed to decode custom reply data: " + err.Error())
|
|
||||||
}
|
|
||||||
return &freedom.Reply{Type: "custom", CustomResponseData: data}, nil
|
|
||||||
default:
|
|
||||||
return nil, errors.New("unknown firewall reply: " + replyType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable
|
// Build implements Buildable
|
||||||
func (c *FreedomConfig) Build() (proto.Message, error) {
|
func (c *FreedomConfig) Build() (proto.Message, error) {
|
||||||
if c.IPsBlocked != nil {
|
if c.IPsBlocked != nil {
|
||||||
// todo: remove legacy
|
// todo: remove legacy
|
||||||
errors.LogWarning(context.Background(), `The feature "ipsBlocked" has been removed and migrated to "firewall". Please update your config(s) according to release note and documentation.`)
|
errors.LogWarning(context.Background(), `The feature "ipsBlocked" has been removed and migrated to "finalRules". Please update your config(s) according to release note and documentation.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
config := new(freedom.Config)
|
config := new(freedom.Config)
|
||||||
@@ -119,7 +91,6 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Fragment != nil {
|
if c.Fragment != nil {
|
||||||
errors.PrintDeprecatedFeatureWarning(`"fragment" in Freedom`, `"fragment" in "streamSettings.finalmask.tcp"`)
|
|
||||||
config.Fragment = new(freedom.Fragment)
|
config.Fragment = new(freedom.Fragment)
|
||||||
|
|
||||||
switch strings.ToLower(c.Fragment.Packets) {
|
switch strings.ToLower(c.Fragment.Packets) {
|
||||||
@@ -176,7 +147,6 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Noises != nil {
|
if c.Noises != nil {
|
||||||
errors.PrintDeprecatedFeatureWarning(`"noises" in Freedom`, `"noise" in "streamSettings.finalmask.udp"`)
|
|
||||||
for _, n := range c.Noises {
|
for _, n := range c.Noises {
|
||||||
NConfig, err := ParseNoise(n)
|
NConfig, err := ParseNoise(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -209,22 +179,15 @@ func (c *FreedomConfig) Build() (proto.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.ProxyProtocol > 0 && c.ProxyProtocol <= 2 {
|
if c.ProxyProtocol > 0 && c.ProxyProtocol <= 2 {
|
||||||
errors.PrintDeprecatedFeatureWarning(`"proxyProtocol" in Freedom`, `"proxy-protocol" in "streamSettings.finalmask.tcp"`)
|
config.ProxyProtocol = c.ProxyProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
firewall := c.Firewall
|
for _, r := range c.FinalRules {
|
||||||
if c.FinalRules != nil {
|
|
||||||
errors.PrintDeprecatedFeatureWarning("finalRules", "firewall")
|
|
||||||
if firewall == nil {
|
|
||||||
firewall = c.FinalRules
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, r := range firewall {
|
|
||||||
rule, err := r.Build()
|
rule, err := r.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.Firewall = append(config.Firewall, rule)
|
config.FinalRules = append(config.FinalRules, rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -286,8 +249,8 @@ func ParseNoise(noise *Noise) (*freedom.Noise, error) {
|
|||||||
return NConfig, nil
|
return NConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FreedomFirewallConfig) Build() (*freedom.FirewallConfig, error) {
|
func (c *FreedomFinalRuleConfig) Build() (*freedom.FinalRuleConfig, error) {
|
||||||
rule := &freedom.FirewallConfig{}
|
rule := &freedom.FinalRuleConfig{}
|
||||||
|
|
||||||
switch strings.ToLower(c.Action) {
|
switch strings.ToLower(c.Action) {
|
||||||
case "allow":
|
case "allow":
|
||||||
@@ -315,45 +278,10 @@ func (c *FreedomFirewallConfig) Build() (*freedom.FirewallConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.BlockDelay != nil {
|
if c.BlockDelay != nil {
|
||||||
errors.PrintDeprecatedFeatureWarning("firewall.blockDelay", "firewall.delay")
|
rule.BlockDelay = &freedom.Range{
|
||||||
c.Delay = c.BlockDelay
|
Min: uint64(c.BlockDelay.From),
|
||||||
}
|
Max: uint64(c.BlockDelay.To),
|
||||||
|
|
||||||
if rule.Action != freedom.RuleAction_Block {
|
|
||||||
if c.Delay != nil || c.LogLevel != "" || c.Reply != nil {
|
|
||||||
return nil, errors.New("delay, logLevel and reply are only supported for firewall action block")
|
|
||||||
}
|
}
|
||||||
return rule, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Delay != nil {
|
|
||||||
rule.Delay = &freedom.Range{
|
|
||||||
Min: uint64(c.Delay.From),
|
|
||||||
Max: uint64(c.Delay.To),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Reply != nil {
|
|
||||||
reply, err := c.Reply.Build()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rule.Reply = reply
|
|
||||||
}
|
|
||||||
|
|
||||||
switch strings.ToLower(c.LogLevel) {
|
|
||||||
case "", "info":
|
|
||||||
rule.LogLevel = log.Severity_Info.Enum()
|
|
||||||
case "none":
|
|
||||||
rule.LogLevel = log.Severity_Unknown.Enum()
|
|
||||||
case "debug":
|
|
||||||
rule.LogLevel = log.Severity_Debug.Enum()
|
|
||||||
case "warning":
|
|
||||||
rule.LogLevel = log.Severity_Warning.Enum()
|
|
||||||
case "error":
|
|
||||||
rule.LogLevel = log.Severity_Error.Enum()
|
|
||||||
default:
|
|
||||||
return nil, errors.New("unknown firewall.logLevel: ", c.LogLevel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rule, nil
|
return rule, nil
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/geodata"
|
"github.com/xtls/xray-core/common/geodata"
|
||||||
"github.com/xtls/xray-core/common/log"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
. "github.com/xtls/xray-core/infra/conf"
|
. "github.com/xtls/xray-core/infra/conf"
|
||||||
@@ -42,17 +41,12 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Input: `{
|
Input: `{
|
||||||
"firewall": [{
|
"finalRules": [{
|
||||||
"action": "block",
|
"action": "block",
|
||||||
"network": "tcp,udp",
|
"network": "tcp,udp",
|
||||||
"port": "53,443",
|
"port": "53,443",
|
||||||
"ip": ["10.0.0.0/8", "2001:db8::/32"],
|
"ip": ["10.0.0.0/8", "2001:db8::/32"],
|
||||||
"delay": "30-60",
|
"blockDelay": "30-60"
|
||||||
"logLevel": "debug",
|
|
||||||
"reply": {
|
|
||||||
"type": "custom",
|
|
||||||
"customResponseData": "Y3VzdG9tIHJlc3BvbnNl"
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
"action": "allow",
|
"action": "allow",
|
||||||
"network": ["udp"]
|
"network": ["udp"]
|
||||||
@@ -60,7 +54,7 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
}`,
|
}`,
|
||||||
Parser: loadJSON(creator),
|
Parser: loadJSON(creator),
|
||||||
Output: &freedom.Config{
|
Output: &freedom.Config{
|
||||||
Firewall: []*freedom.FirewallConfig{
|
FinalRules: []*freedom.FinalRuleConfig{
|
||||||
{
|
{
|
||||||
Action: freedom.RuleAction_Block,
|
Action: freedom.RuleAction_Block,
|
||||||
Networks: []net.Network{net.Network_TCP, net.Network_UDP},
|
Networks: []net.Network{net.Network_TCP, net.Network_UDP},
|
||||||
@@ -92,11 +86,9 @@ func TestFreedomConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Delay: &freedom.Range{Min: 30, Max: 60},
|
BlockDelay: &freedom.Range{
|
||||||
LogLevel: log.Severity_Debug.Enum(),
|
Min: 30,
|
||||||
Reply: &freedom.Reply{
|
Max: 60,
|
||||||
Type: "custom",
|
|
||||||
CustomResponseData: []byte("custom response"),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-11
@@ -2,11 +2,11 @@ package conf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/xtls/xray-core/app/geodata"
|
"github.com/xtls/xray-core/app/geodata"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
|
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,21 +19,15 @@ func (c *GeodataAssetConfig) Build() (*geodata.Asset, error) {
|
|||||||
if err := validateHTTPS(c.URL); err != nil {
|
if err := validateHTTPS(c.URL); err != nil {
|
||||||
return nil, errors.New("invalid geodata asset url: ", c.URL).Base(err)
|
return nil, errors.New("invalid geodata asset url: ", c.URL).Base(err)
|
||||||
}
|
}
|
||||||
|
if _, err := filesystem.StatAsset(c.File); err != nil {
|
||||||
|
return nil, errors.New("invalid geodata asset file: ", c.File).Base(err)
|
||||||
|
}
|
||||||
return &geodata.Asset{
|
return &geodata.Asset{
|
||||||
Url: migrateGeodataURL(c.URL),
|
Url: c.URL,
|
||||||
File: c.File,
|
File: c.File,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrateGeodataURL(assetURL string) string {
|
|
||||||
if strings.HasSuffix(strings.ToLower(assetURL), ".dat") && (strings.HasPrefix(strings.ToLower(assetURL), "https://github.com/xtls/xray-rules-dat/") ||
|
|
||||||
strings.HasPrefix(strings.ToLower(assetURL), "https://raw.githubusercontent.com/xtls/xray-rules-dat/")) {
|
|
||||||
errors.PrintDeprecatedFeatureWarning(assetURL, assetURL+".gz")
|
|
||||||
return assetURL + ".gz"
|
|
||||||
}
|
|
||||||
return assetURL
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateHTTPS(s string) error {
|
func validateHTTPS(s string) error {
|
||||||
u, err := url.ParseRequestURI(s)
|
u, err := url.ParseRequestURI(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package conf_test
|
package conf_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/app/geodata"
|
"github.com/xtls/xray-core/app/geodata"
|
||||||
@@ -8,6 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGeodataConfig(t *testing.T) {
|
func TestGeodataConfig(t *testing.T) {
|
||||||
|
t.Setenv("xray.location.asset", filepath.Join("..", "..", "resources"))
|
||||||
|
|
||||||
creator := func() Buildable {
|
creator := func() Buildable {
|
||||||
return new(GeodataConfig)
|
return new(GeodataConfig)
|
||||||
}
|
}
|
||||||
@@ -35,7 +38,27 @@ func TestGeodataConfig(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGeodataAssetConfig(t *testing.T) {
|
||||||
|
t.Setenv("xray.location.asset", filepath.Join("..", "..", "resources"))
|
||||||
|
|
||||||
|
if _, err := (&GeodataAssetConfig{
|
||||||
|
URL: "https://example.com/geoip.dat",
|
||||||
|
File: "geoip.dat",
|
||||||
|
}).Build(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := (&GeodataAssetConfig{
|
||||||
|
URL: "https://example.com/geoip.dat",
|
||||||
|
File: "missing.dat",
|
||||||
|
}).Build(); err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeodataAssetConfigInvalidURL(t *testing.T) {
|
func TestGeodataAssetConfigInvalidURL(t *testing.T) {
|
||||||
|
t.Setenv("xray.location.asset", filepath.Join("..", "..", "resources"))
|
||||||
|
|
||||||
for _, rawURL := range []string{
|
for _, rawURL := range []string{
|
||||||
"",
|
"",
|
||||||
"http://example.com/geoip.dat",
|
"http://example.com/geoip.dat",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user