mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-12-03 17:46:44 +00:00
Merge pull request #405 from nxtrace/codex/sync-core-20261114
升级 Go 1.27.4 与依赖,统一超时并修复 Nali v4
This commit is contained in:
30 files changed
+326
-90
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
export GOTOOLCHAIN=go1.27.3
|
||||
export GOTOOLCHAIN=go1.27.4
|
||||
|
||||
# -------- Config --------
|
||||
# Usage: .cross_compile.sh [full|tiny|ntr|all] [debug]
|
||||
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
- { goos: openbsd, goarch: arm64 }
|
||||
- { goos: openbsd, goarch: arm, goarm: 7 }
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
CGO_ENABLED: ${{ matrix.goos == 'android' && 1 || 0 }}
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
@@ -95,7 +95,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
@@ -226,7 +226,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix: { goarch: [ amd64, arm64 ] }
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
CGO_ENABLED: 1
|
||||
GOOS: darwin
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
@@ -240,7 +240,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
- name: Install fixture dependencies
|
||||
run: sudo apt-get update && sudo apt-get install -y iproute2 tcpdump
|
||||
- name: Build
|
||||
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v7
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: "1.27.3"
|
||||
go-version: "1.27.4"
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
@@ -325,17 +325,17 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Set up head Go 1.27.3
|
||||
- name: Set up head Go 1.27.4
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: "1.27.3"
|
||||
go-version: "1.27.4"
|
||||
check-latest: true
|
||||
cache: false
|
||||
|
||||
- name: Record head environment
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
run: |
|
||||
set -Eeuo pipefail
|
||||
result_dir="${RUNNER_TEMP}/performance-evidence/head"
|
||||
@@ -357,7 +357,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
PERF_RESULT_DIR: ${{ runner.temp }}/performance-evidence/head
|
||||
run: bash scripts/perf/run_benchmarks.sh head
|
||||
|
||||
@@ -366,7 +366,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
run: |
|
||||
set -Eeuo pipefail
|
||||
result_dir="${RUNNER_TEMP}/performance-evidence/head"
|
||||
@@ -379,7 +379,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
PERF_RESULT_DIR: ${{ runner.temp }}/performance-evidence/head
|
||||
run: bash scripts/perf/profile_benchmark.sh ./trace BenchmarkMTRAggregatorSnapshot64TTL4Paths head-mtr
|
||||
|
||||
@@ -388,7 +388,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
MTR_GOROUTINE_ACTIVE_PROFILE: ${{ runner.temp }}/performance-evidence/head/head-mtr-workers-active.goroutine.pprof
|
||||
MTR_GOROUTINE_LEAK_PROFILE: ${{ runner.temp }}/performance-evidence/head/head-mtr-workers-final.goroutine.pprof
|
||||
run: go test -count=1 -run '^(TestMTRSchedulerJoinsSessionListener|TestMTRWorkerGoroutineProfileCarriesOwnerLabel)$' ./trace
|
||||
@@ -398,7 +398,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
run: |
|
||||
set -Eeuo pipefail
|
||||
result_dir="${RUNNER_TEMP}/performance-evidence/head"
|
||||
@@ -423,7 +423,7 @@ jobs:
|
||||
continue-on-error: true
|
||||
shell: bash
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
REFERENCE_SHA: ${{ steps.refs.outputs.reference_sha }}
|
||||
run: |
|
||||
set -Eeuo pipefail
|
||||
|
||||
@@ -109,7 +109,7 @@ jobs:
|
||||
name: ${{ matrix.name }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -130,7 +130,7 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: "1.27.3"
|
||||
go-version: "1.27.4"
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ jobs:
|
||||
name: Default JSON (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -173,7 +173,7 @@ jobs:
|
||||
if: ${{ (needs.changes.outputs.go == 'true' || needs.changes.outputs.pty == 'true' || needs.changes.outputs.doctor == 'true' || needs.changes.outputs.dns == 'true') }}
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
@@ -305,7 +305,7 @@ jobs:
|
||||
name: Windows ARM64 IPv6 Traffic Class
|
||||
runs-on: windows-11-arm
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v7
|
||||
@@ -313,7 +313,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
@@ -326,7 +326,7 @@ jobs:
|
||||
name: Race detector (Ubuntu)
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GOTOOLCHAIN: go1.27.3
|
||||
GOTOOLCHAIN: go1.27.4
|
||||
steps:
|
||||
- name: Checkout codebase
|
||||
uses: actions/checkout@v7
|
||||
@@ -334,7 +334,7 @@ jobs:
|
||||
- name: Set up Go (built-in cache)
|
||||
uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
check-latest: true
|
||||
cache: true
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
- name: Install Linux fixture dependencies
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get update && sudo apt-get install -y tcpdump iproute2
|
||||
@@ -155,7 +155,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-go@v7
|
||||
with:
|
||||
go-version: '1.27.3'
|
||||
go-version: '1.27.4'
|
||||
- name: Build and prepare the existing WinDivert backend
|
||||
shell: pwsh
|
||||
run: |
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
- 名称:NextTrace (NTrace-core)
|
||||
- 仓库:github.com/nxtrace/NTrace-core
|
||||
- 模块:`github.com/nxtrace/NTrace-core`
|
||||
- 语言:Go(`go 1.27.3`)
|
||||
- 语言:Go(`go 1.27.4`)
|
||||
- 入口:`main.go -> cmd.Execute()`
|
||||
- 核心能力:ICMP/TCP/UDP traceroute、GeoIP/RDNS、MTR 连续探测、Web/API、多平台构建
|
||||
|
||||
@@ -381,16 +381,16 @@
|
||||
|
||||
## CI 与工具链(当前)
|
||||
|
||||
- `go.mod`: `go 1.27.3`;通过 `tool` directive 固定 `golang.org/x/perf/cmd/benchstat` 版本。
|
||||
- `go.mod`: `go 1.27.4`;通过 `tool` directive 固定 `golang.org/x/perf/cmd/benchstat` 版本。
|
||||
- GitHub Actions:
|
||||
- `.github/workflows/build.yml` 使用 `setup-go@v7` + `go-version: 1.27.3`
|
||||
- `.github/workflows/test.yml` 使用 `setup-go@v7` + `go-version: 1.27.3`
|
||||
- `.github/workflows/regression.yml` 使用 `setup-go@v7` + `go-version: 1.27.3`
|
||||
- `.github/workflows/golangci-lint.yml` 使用 `setup-go@v7` + `go-version: 1.27.3`
|
||||
- `.github/workflows/build.yml` 使用 `setup-go@v7` + `go-version: 1.27.4`
|
||||
- `.github/workflows/test.yml` 使用 `setup-go@v7` + `go-version: 1.27.4`
|
||||
- `.github/workflows/regression.yml` 使用 `setup-go@v7` + `go-version: 1.27.4`
|
||||
- `.github/workflows/golangci-lint.yml` 使用 `setup-go@v7` + `go-version: 1.27.4`
|
||||
- test workflow 使用 Go 默认 JSON 运行时,并在 `windows-11-arm` 上运行 IPv6 Traffic Class 专项回归
|
||||
- 正式发布、性能脚本与 CI 统一使用默认 JSON 后端,不再固定旧实现或维护旧实现测试 lane;源码继续使用 `encoding/json` v1 API
|
||||
- build matrix 已移除 `windows/arm`
|
||||
- `.cross_compile.sh` 固定 `GOTOOLCHAIN=go1.27.3`,使用默认 JSON 运行时;脚本与 workflow 里的 `go build` 都用数组构造 `-tags` 参数,避免 shell word-splitting;脚本也会把当前 `GOARM` 传给 `compress_with_upx`,使 linux/armv7 目标能命中对应压缩分支。
|
||||
- `.cross_compile.sh` 固定 `GOTOOLCHAIN=go1.27.4`,使用默认 JSON 运行时;脚本与 workflow 里的 `go build` 都用数组构造 `-tags` 参数,避免 shell word-splitting;脚本也会把当前 `GOARM` 传给 `compress_with_upx`,使 linux/armv7 目标能命中对应压缩分支。
|
||||
- Darwin 正式构建最低支持 macOS 13.0:CGO 编译/链接使用 `-mmacosx-version-min=13.0`,Go linker 显式传 `-macos=13.0`。
|
||||
- `ipgeo/ipdbone.go` 不再原地修改全局 `defaultClient.httpClient.Timeout`;超时覆盖会通过克隆 client(复用 token cache / token init,同步替换整个 HTTP client)实现,避免 dial timeout 与 client timeout 脱节。
|
||||
|
||||
|
||||
@@ -214,11 +214,11 @@ Starting from this release, NextTrace is published in **three flavors** under th
|
||||
|
||||
### Manual Build
|
||||
|
||||
Build from source with Go 1.27.3+ installed. Release builds and CI use the
|
||||
Build from source with Go 1.27.4+ installed. Release builds and CI use the
|
||||
default Go JSON runtime. See the [JSON runtime ADR](docs/adr/0001-go127-json-runtime.md).
|
||||
|
||||
```bash
|
||||
export GOTOOLCHAIN=go1.27.3
|
||||
export GOTOOLCHAIN=go1.27.4
|
||||
|
||||
# Full (all features)
|
||||
go build -trimpath -o dist/nexttrace -ldflags "-w -s" .
|
||||
@@ -236,7 +236,7 @@ Cross-compile example:
|
||||
|
||||
```bash
|
||||
# Linux arm64, Tiny flavor
|
||||
GOTOOLCHAIN=go1.27.3 \
|
||||
GOTOOLCHAIN=go1.27.4 \
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
||||
go build -tags flavor_tiny -trimpath -o dist/nexttrace-tiny_linux_arm64 -ldflags "-w -s" .
|
||||
```
|
||||
@@ -622,7 +622,7 @@ export NO_COLOR=1
|
||||
| `--parallel-requests` | Total in-flight probes across TTLs | `18` | Use `1` on multipath/load-balanced paths; keep `6-18` on stable links |
|
||||
| `--send-time` | Gap between packets inside one TTL group | `50ms` | Raise to `100-200ms` on rate-limited devices; ignored in MTR |
|
||||
| `--ttl-time` | Gap between TTL groups in traceroute; per-hop interval in MTR | traceroute: `300ms`; MTR: `1000ms` when omitted | Lower to speed up; raise on remote/rate-limited paths |
|
||||
| `--timeout` | Per-probe timeout | `1000ms` | Raise to `2000-3000ms` for intercontinental or high-loss paths |
|
||||
| `--timeout` | Per-probe timeout | `3000ms` | Increase for intercontinental or high-loss paths |
|
||||
| `--psize` | Probe packet size | Protocol/IP-family minimum | Inclusive IP + probe headers; negative values randomize each probe up to `abs(value)`; sizes above the egress/path MTU may fragment on wire |
|
||||
| `-Q`, `--tos` | IP TOS / traffic class | `0` | Set the full 8-bit IP field (DSCP*4+ECN); nonzero ICMP on Windows amd64 requires `WinDivert` |
|
||||
|
||||
@@ -1082,9 +1082,9 @@ Arguments:
|
||||
(--mtr/-r/-w, including --raw), this
|
||||
becomes per-hop probe interval. 500-1000ms
|
||||
is a good MTR starting range
|
||||
--timeout Per-probe timeout [ms]. Raise to 2000-3000
|
||||
on slow intercontinental or high-loss
|
||||
paths. Default: 1000
|
||||
--timeout Per-probe timeout [ms]. Increase on slow
|
||||
intercontinental or high-loss paths.
|
||||
Default: 3000
|
||||
--psize Probe packet size in bytes, inclusive IP
|
||||
and active probe headers. Default is the
|
||||
minimum legal size for the chosen protocol
|
||||
|
||||
+7
-7
@@ -236,11 +236,11 @@ Windows 的 `--dev` 仅用于源地址选择,不能表述为设备绑定已验
|
||||
|
||||
### 手动编译
|
||||
|
||||
需要 Go 1.27.3+ 环境。正式发布与 CI 统一使用 Go 默认 JSON 运行时。
|
||||
需要 Go 1.27.4+ 环境。正式发布与 CI 统一使用 Go 默认 JSON 运行时。
|
||||
详见 [JSON 运行时 ADR](docs/adr/0001-go127-json-runtime.md)。
|
||||
|
||||
```bash
|
||||
export GOTOOLCHAIN=go1.27.3
|
||||
export GOTOOLCHAIN=go1.27.4
|
||||
|
||||
# 完整版(所有功能)
|
||||
go build -trimpath -o dist/nexttrace -ldflags "-w -s" .
|
||||
@@ -258,7 +258,7 @@ macOS 源码编译需要 macOS 13.0 或更高版本、Xcode Command Line Tools
|
||||
|
||||
```bash
|
||||
# Linux arm64 精简版
|
||||
GOTOOLCHAIN=go1.27.3 \
|
||||
GOTOOLCHAIN=go1.27.4 \
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
||||
go build -tags flavor_tiny -trimpath -o dist/nexttrace-tiny_linux_arm64 -ldflags "-w -s" .
|
||||
```
|
||||
@@ -614,7 +614,7 @@ export NO_COLOR=1
|
||||
| `--parallel-requests` | 跨 TTL 的总并发 in-flight 探测数 | `18` | 多路径/负载均衡链路用 `1`;稳定链路一般 `6-18` |
|
||||
| `--send-time` | 同一 TTL 组内相邻探测包间隔 | `50ms` | 设备限速时升到 `100-200ms`;MTR 下忽略 |
|
||||
| `--ttl-time` | 常规 traceroute 的 TTL 组间隔;MTR 的每跳探测间隔 | traceroute: `300ms`;MTR: 未指定时 `1000ms` | 想加速就调低;远程/限速链路调高 |
|
||||
| `--timeout` | 单个探测包超时 | `1000ms` | 跨洲或高丢包链路升到 `2000-3000ms` |
|
||||
| `--timeout` | 单个探测包超时 | `3000ms` | 跨洲或高丢包链路可适当调高 |
|
||||
| `--psize` | 探测包大小 | 按协议/IP 族自动取最小合法值 | 含 IP + 探测协议头;负值表示每个 probe 在 `abs(value)` 内随机;超过出接口/路径 MTU 时,链路上可能看到分片 |
|
||||
| `-Q`, `--tos` | IP TOS / traffic class | `0` | 设置完整 8 位字段(DSCP*4+ECN);Windows amd64 非零 ICMP TOS 依赖 `WinDivert` |
|
||||
|
||||
@@ -1058,9 +1058,9 @@ Arguments:
|
||||
(--mtr/-r/-w, including --raw), this
|
||||
becomes per-hop probe interval. 500-1000ms
|
||||
is a good MTR starting range
|
||||
--timeout Per-probe timeout [ms]. Raise to 2000-3000
|
||||
on slow intercontinental or high-loss
|
||||
paths. Default: 1000
|
||||
--timeout Per-probe timeout [ms]. Increase on slow
|
||||
intercontinental or high-loss paths.
|
||||
Default: 3000
|
||||
--psize Probe packet size in bytes, inclusive IP
|
||||
and active probe headers. Default is the
|
||||
minimum legal size for the chosen protocol
|
||||
|
||||
+2
-2
@@ -431,7 +431,7 @@ func buildPacketIntervalHelp() string {
|
||||
}
|
||||
|
||||
func buildTimeoutHelp() string {
|
||||
return "Per-probe timeout [ms]. Raise to 2000-3000 on slow intercontinental or high-loss paths"
|
||||
return "Per-probe timeout [ms]. Increase on slow intercontinental or high-loss paths"
|
||||
}
|
||||
|
||||
func buildPayloadSizeHelp() string {
|
||||
@@ -1465,7 +1465,7 @@ func Execute() {
|
||||
// ── Send-time: hidden in ntr (always ignored in MTR mode) ──
|
||||
packetInterval := registerPacketIntervalFlag(parser)
|
||||
ttlInterval := registerTTLIntervalFlag(parser)
|
||||
timeout := parser.Int("", "timeout", &argparse.Options{Default: 1000, Help: buildTimeoutHelp()})
|
||||
timeout := parser.Int("", "timeout", &argparse.Options{Default: 3000, Help: buildTimeoutHelp()})
|
||||
packetSize := parser.Int("", "psize", &argparse.Options{Help: buildPayloadSizeHelp()})
|
||||
tos := parser.Int("Q", "tos", &argparse.Options{Default: 0, Help: buildTOSHelp()})
|
||||
dot := parser.Selector("", "dot-server", []string{"dnssb", "aliyun", "dnspod", "google", "cloudflare"}, &argparse.Options{
|
||||
|
||||
+1
-1
@@ -1166,7 +1166,7 @@ func TestAdvancedHelpTextMentionsTuningGuidance(t *testing.T) {
|
||||
registerPacketIntervalFlag(parser)
|
||||
parser.Int("", "max-attempts", &argparse.Options{Help: buildMaxAttemptsHelp()})
|
||||
parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: buildParallelRequestsHelp()})
|
||||
parser.Int("", "timeout", &argparse.Options{Default: 1000, Help: buildTimeoutHelp()})
|
||||
parser.Int("", "timeout", &argparse.Options{Default: 3000, Help: buildTimeoutHelp()})
|
||||
parser.Int("", "psize", &argparse.Options{Help: buildPayloadSizeHelp()})
|
||||
|
||||
usage := parser.Usage(nil)
|
||||
|
||||
+8
-2
@@ -235,9 +235,15 @@ func runNaliMode(ctx context.Context, opts naliRunOptions) error {
|
||||
} else if opts.ipv6Only {
|
||||
family = nali.Family6
|
||||
}
|
||||
descriptor := ipgeo.GetSourceDescriptorWithGeoDNS(opts.data, opts.dot)
|
||||
timeout := time.Duration(opts.timeoutMs) * time.Millisecond
|
||||
if descriptor.Backend == ipgeo.SourceBackendNextTraceAPIV4 && timeout < ipgeo.NextTraceAPIV4MinTimeout {
|
||||
// The cache waiter must allow the same minimum budget as the v4 client.
|
||||
timeout = ipgeo.NextTraceAPIV4MinTimeout
|
||||
}
|
||||
return nali.Run(ctx, nali.Config{
|
||||
Source: trace.CachedGeoSource(ipgeo.GetSourceDescriptorWithGeoDNS(opts.data, opts.dot)),
|
||||
Timeout: time.Duration(opts.timeoutMs) * time.Millisecond,
|
||||
Source: trace.CachedGeoSource(descriptor),
|
||||
Timeout: timeout,
|
||||
Lang: opts.lang,
|
||||
Family: family,
|
||||
DN42: isDN42Provider(opts.data),
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestBuildNaliModeOptionsDetectsExplicitDefaults(t *testing.T) {
|
||||
parser.Int("", "source-port", &argparse.Options{Default: 0})
|
||||
parser.Flag("", "show-ips", &argparse.Options{})
|
||||
parser.Int("y", "ipinfo", &argparse.Options{Default: 0})
|
||||
parser.Int("", "timeout", &argparse.Options{Default: 1000})
|
||||
parser.Int("", "timeout", &argparse.Options{Default: 3000})
|
||||
if err := parser.Parse([]string{"nexttrace", "-q", "3", "--max-hops", "30", "-i", "300", "--source-port", "0", "--show-ips", "-y", "0"}); err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nxtrace/NTrace-core/ipgeo"
|
||||
"github.com/nxtrace/NTrace-core/trace"
|
||||
"github.com/nxtrace/NTrace-core/util"
|
||||
)
|
||||
|
||||
func TestRunNaliModeV4WaitsForSlowLookup(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
timeoutMs int
|
||||
delay time.Duration
|
||||
}{
|
||||
{name: "short explicit timeout", timeoutMs: 1000, delay: 1200 * time.Millisecond},
|
||||
{name: "longer explicit timeout", timeoutMs: 3500, delay: 2200 * time.Millisecond},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
upstream := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v4/ipGeo" || r.URL.Query().Get("ip") != "218.33.109.164" {
|
||||
t.Errorf("unexpected GeoIP request: %s", r.URL)
|
||||
}
|
||||
time.Sleep(tc.delay)
|
||||
w.Header().Set("Connection", "close")
|
||||
_, _ = io.WriteString(w, `{"ip":"218.33.109.164","asnumber":"153371","country":"日本"}`)
|
||||
}))
|
||||
defer upstream.Close()
|
||||
proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodConnect || r.Host != "api.nxtrace.org:443" {
|
||||
t.Errorf("unexpected proxy request: %s %s", r.Method, r.Host)
|
||||
http.Error(w, "unexpected proxy request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
remote, err := net.Dial("tcp", upstream.Listener.Addr().String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = remote.Close() }()
|
||||
client, _, err := w.(http.Hijacker).Hijack()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = client.Close() }()
|
||||
_, _ = io.WriteString(client, "HTTP/1.1 200 Connection Established\r\n\r\n")
|
||||
go func() { _, _ = io.Copy(remote, client) }()
|
||||
_, _ = io.Copy(client, remote)
|
||||
}))
|
||||
defer proxy.Close()
|
||||
|
||||
oldProxy, oldTransport := util.EnvProxyURL, http.DefaultTransport
|
||||
oldPolicy := util.CurrentGeoDNSPolicy()
|
||||
proxyURL, err := url.Parse(proxy.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
// All TLS connections are tunneled to the local test server.
|
||||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
transport.Proxy = http.ProxyURL(proxyURL)
|
||||
http.DefaultTransport = transport
|
||||
util.EnvProxyURL = proxy.URL
|
||||
t.Setenv(util.EnvNextTraceAPIV4TokenKey, "test-token")
|
||||
trace.ClearCaches()
|
||||
t.Cleanup(func() {
|
||||
util.EnvProxyURL, http.DefaultTransport = oldProxy, oldTransport
|
||||
util.SetGeoDNSResolver(oldPolicy.Resolver())
|
||||
transport.CloseIdleConnections()
|
||||
trace.ClearCaches()
|
||||
})
|
||||
|
||||
var out bytes.Buffer
|
||||
err = runNaliMode(context.Background(), naliRunOptions{
|
||||
stdout: &out, data: ipgeo.NextTraceAPIProvider, pow: "api.nxtrace.org",
|
||||
dot: strings.TrimPrefix(proxy.URL, "http://"), lang: "cn",
|
||||
timeoutMs: tc.timeoutMs, target: "218.33.109.164",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("runNaliMode() error = %v", err)
|
||||
}
|
||||
if got, want := out.String(), "218.33.109.164 [AS153371, 日本]\n"; got != want {
|
||||
t.Fatalf("runNaliMode() output = %q, want %q", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
- 状态:接受
|
||||
- 日期:2026-11-01(修订 2026-09-05 决策)
|
||||
- 工具链:Go 1.27.3
|
||||
- 工具链:Go 1.27.4
|
||||
- Darwin 最低版本:macOS 13.0
|
||||
|
||||
## 背景
|
||||
@@ -21,7 +21,7 @@ golden 验证字节和语义。JSON 后端的性能取舍结合实际调用量
|
||||
|
||||
## 决策
|
||||
|
||||
1. 项目固定使用 Go 1.27.3,Darwin 正式产物最低支持 macOS 13.0。
|
||||
1. 项目固定使用 Go 1.27.4,Darwin 正式产物最低支持 macOS 13.0。
|
||||
2. 源码继续使用 `encoding/json` v1 API,不直接导入 `encoding/json/v2`。
|
||||
3. 正式发布、`.cross_compile.sh`、性能和 PGO 脚本统一使用 Go 默认 JSON 后端,
|
||||
移除 `nojsonv2` 固定项和 PGO 专用 JSON 后端配置。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module github.com/nxtrace/NTrace-core
|
||||
|
||||
go 1.27.3
|
||||
go 1.27.4
|
||||
|
||||
tool golang.org/x/perf/cmd/benchstat
|
||||
|
||||
@@ -8,7 +8,7 @@ require (
|
||||
github.com/akamensky/argparse v1.4.0
|
||||
github.com/ameshkov/dnscrypt/v2 v2.4.0
|
||||
github.com/charmbracelet/log v1.0.0
|
||||
github.com/charmbracelet/x/ansi v0.11.6
|
||||
github.com/charmbracelet/x/ansi v0.11.9
|
||||
github.com/fatih/color v1.19.0
|
||||
github.com/gin-gonic/gin v1.12.0
|
||||
github.com/google/gopacket v1.1.19
|
||||
@@ -21,18 +21,18 @@ require (
|
||||
github.com/modelcontextprotocol/go-sdk v1.8.0
|
||||
github.com/natesales/q v0.19.12
|
||||
github.com/oschwald/maxminddb-golang v1.13.1
|
||||
github.com/quic-go/quic-go v0.64.1
|
||||
github.com/quic-go/quic-go v0.65.0
|
||||
github.com/rodaine/table v1.4.1
|
||||
github.com/spf13/viper v1.21.0
|
||||
github.com/sthorne/odoh-go v1.0.4
|
||||
github.com/stretchr/testify v1.12.1
|
||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||
github.com/tidwall/gjson v1.20.0
|
||||
github.com/tidwall/gjson v1.20.1
|
||||
github.com/tsosunchia/powclient v0.3.0
|
||||
github.com/xjasonlyu/windivert-go v0.0.0-20201010013527-4239d0afa76f
|
||||
golang.org/x/mod v0.42.0
|
||||
golang.org/x/net v0.61.0
|
||||
golang.org/x/sync v0.24.0
|
||||
golang.org/x/net v0.62.0
|
||||
golang.org/x/sync v0.25.0
|
||||
golang.org/x/sys v0.49.0
|
||||
golang.org/x/term v0.47.0
|
||||
)
|
||||
@@ -71,7 +71,7 @@ require (
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
|
||||
@@ -25,8 +25,8 @@ github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoF
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/log v1.0.0 h1:HVVVMmfOorfj3BA9i8X8UL69Hoz9lI0PYwXfJvOdRc4=
|
||||
github.com/charmbracelet/log v1.0.0/go.mod h1:uYgY3SmLpwJWxmlrPwXvzVYujxis1vAKRV/0VQB7yWA=
|
||||
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||
github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM=
|
||||
github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
@@ -104,8 +104,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
@@ -136,8 +136,8 @@ github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4
|
||||
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/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/quic-go v0.64.1 h1:BCNTP+6x6++OPKrGST2FR3f1tycx8O3QOA3QQv09g70=
|
||||
github.com/quic-go/quic-go v0.64.1/go.mod h1:RAro2j2yN9a9EiPACLHT9IB2NXCvGQmmo/alT0yYI0w=
|
||||
github.com/quic-go/quic-go v0.65.0 h1:BJQSjdTvLPLmWtaCupUphRbgxgpZhdO/GMpr9Eoe3B4=
|
||||
github.com/quic-go/quic-go v0.65.0/go.mod h1:RAro2j2yN9a9EiPACLHT9IB2NXCvGQmmo/alT0yYI0w=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rodaine/table v1.4.1 h1:E6biWCzTV91H1sGNlW/cUtqqgxUJnmcThmWAyhPiToo=
|
||||
@@ -176,8 +176,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
|
||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
|
||||
github.com/tidwall/gjson v1.20.0 h1:+agJ3rEzKcCXKDKo0ml26UROcpcAlnZyjq+TjbY5Fto=
|
||||
github.com/tidwall/gjson v1.20.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc=
|
||||
github.com/tidwall/gjson v1.20.1 h1:Jmex4ygKZxn92HFHlejG8sHcEODHttXyrj63hsJ7/GE=
|
||||
github.com/tidwall/gjson v1.20.1/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc=
|
||||
github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM=
|
||||
github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
@@ -218,15 +218,15 @@ golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
|
||||
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
|
||||
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.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
|
||||
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
|
||||
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
||||
golang.org/x/perf v0.0.0-20260825160852-19be9d8e6c70 h1:M+kM03JKR23KkrutTue5KEQYDSbZTZTJ4FJ1v5zYrHM=
|
||||
golang.org/x/perf v0.0.0-20260825160852-19be9d8e6c70/go.mod h1:ihD/LfJrdVe40PFEzKgix8YPzoXS4LFO4elW9HAFNqo=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sync v0.25.0 h1:dJnifr0nMV8/SBnBvdo4eSGGnrc3O4FFx6IqvtLcmRs=
|
||||
golang.org/x/sync v0.25.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
//go:build !flavor_tiny && !flavor_ntr
|
||||
|
||||
package dnsclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/natesales/q/cli"
|
||||
"github.com/quic-go/quic-go/http3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const doH3SmokeHelperEnv = "NEXTTRACE_DOH3_SMOKE_HELPER"
|
||||
|
||||
func TestQPublicTransportAgainstLocalDoH3(t *testing.T) {
|
||||
if os.Getenv(doH3SmokeHelperEnv) != "1" {
|
||||
// q v0.19.12 closes idle HTTP connections but not the HTTP/3
|
||||
// transport's UDP socket. Bound its lifetime to a helper process,
|
||||
// as well as bounding exchanges that have no context parameter.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
command := exec.CommandContext(ctx, os.Args[0],
|
||||
"-test.run=^TestQPublicTransportAgainstLocalDoH3$", "-test.timeout=10s")
|
||||
command.Env = append(os.Environ(), doH3SmokeHelperEnv+"=1")
|
||||
output, err := command.CombinedOutput()
|
||||
if ctx.Err() != nil {
|
||||
t.Fatalf("HTTP/3 helper timed out: %v, output=%q", ctx.Err(), output)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("HTTP/3 helper failed: %v, output=%q", err, output)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, method := range []string{http.MethodGet, http.MethodPost} {
|
||||
t.Run(method, func(t *testing.T) {
|
||||
listener, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = listener.Close() })
|
||||
server := &http3.Server{
|
||||
TLSConfig: &tls.Config{
|
||||
Certificates: []tls.Certificate{testTLSCertificate(t)},
|
||||
MinVersion: tls.VersionTLS13,
|
||||
},
|
||||
Handler: http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||
if request.ProtoMajor != 3 || request.Method != method || request.URL.Path != "/dns-query" {
|
||||
http.Error(writer, "unexpected DNS request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if request.Header.Get("Accept") != "application/dns-message" {
|
||||
http.Error(writer, "missing DNS Accept header", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var wire []byte
|
||||
var readErr error
|
||||
if method == http.MethodGet {
|
||||
wire, readErr = base64.RawURLEncoding.DecodeString(request.URL.Query().Get("dns"))
|
||||
} else {
|
||||
if request.Header.Get("Content-Type") != "application/dns-message" {
|
||||
http.Error(writer, "missing DNS Content-Type", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
wire, readErr = io.ReadAll(request.Body)
|
||||
}
|
||||
query := new(dns.Msg)
|
||||
if readErr != nil || query.Unpack(wire) != nil {
|
||||
http.Error(writer, "invalid DNS query", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
response, packErr := testDNSReply(query).Pack()
|
||||
if packErr != nil {
|
||||
http.Error(writer, packErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
writer.Header().Set("Content-Type", "application/dns-message")
|
||||
_, _ = writer.Write(response)
|
||||
}),
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- server.Serve(listener) }()
|
||||
t.Cleanup(func() {
|
||||
_ = server.Close()
|
||||
select {
|
||||
case serveErr := <-done:
|
||||
require.ErrorIs(t, serveErr, http.ErrServerClosed)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("HTTP/3 server did not stop")
|
||||
}
|
||||
})
|
||||
|
||||
parsed := mustParseServer(t, "https://"+listener.LocalAddr().String()+"/dns-query")
|
||||
txp, err := NewTransport(parsed, cli.Flags{
|
||||
HTTP3: true, HTTPMethod: method, ReuseConn: true,
|
||||
}, insecureTestTLSConfig())
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = txp.Close() })
|
||||
// A second exchange also exercises the reused HTTP/3 transport.
|
||||
for range 2 {
|
||||
reply, exchangeErr := txp.Exchange(testDNSQuery())
|
||||
assertTestDNSReply(t, reply, exchangeErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ const (
|
||||
defaultLanguage = "cn"
|
||||
defaultQueries = 3
|
||||
defaultMaxHops = 30
|
||||
defaultTimeoutMs = 1000
|
||||
defaultTimeoutMs = 3000
|
||||
defaultParallelRequests = 18
|
||||
defaultBeginHop = 1
|
||||
defaultPacketIntervalMs = 50
|
||||
|
||||
@@ -18,6 +18,9 @@ import (
|
||||
"golang.org/x/net/http/httpproxy"
|
||||
)
|
||||
|
||||
// NextTraceAPIV4MinTimeout is the minimum total budget for a v4 GeoIP lookup.
|
||||
const NextTraceAPIV4MinTimeout = 2 * time.Second
|
||||
|
||||
const (
|
||||
NextTraceAPIV4TokenPageURL = "https://api.nxtrace.org/v4/api-tokens"
|
||||
nextTraceAPIV4APIHost = "api.nxtrace.org"
|
||||
@@ -26,7 +29,6 @@ const (
|
||||
nextTraceAPIV4TokenHeader = "X-NextTrace-Token"
|
||||
nextTraceAPIV4MaxErrorBody = 512
|
||||
nextTraceAPIV4MaxGeoBody = 1 << 20
|
||||
nextTraceAPIV4MinTimeout = 2 * time.Second
|
||||
nextTraceAPIV4FastIPTimeout = time.Second
|
||||
nextTraceAPIV4MaxAttempts = 3
|
||||
nextTraceAPIV4CacheMaxSize = 32
|
||||
@@ -76,7 +78,7 @@ type NextTraceAPIV4Client struct {
|
||||
func NewNextTraceAPIV4Client(endpoint string, token string, httpClient *http.Client) *NextTraceAPIV4Client {
|
||||
endpoint = normalizeNextTraceAPIV4Endpoint(endpoint)
|
||||
if httpClient == nil {
|
||||
httpClient = defaultNextTraceAPIV4HTTPClient(endpoint, nextTraceAPIV4MinTimeout)
|
||||
httpClient = defaultNextTraceAPIV4HTTPClient(endpoint, NextTraceAPIV4MinTimeout)
|
||||
}
|
||||
return &NextTraceAPIV4Client{
|
||||
endpoint: endpoint,
|
||||
@@ -514,8 +516,8 @@ func sleepBeforeNextTraceAPIV4Retry(ctx context.Context, delay time.Duration) er
|
||||
}
|
||||
|
||||
func normalizeNextTraceAPIV4Timeout(timeout time.Duration) time.Duration {
|
||||
if timeout < nextTraceAPIV4MinTimeout {
|
||||
return nextTraceAPIV4MinTimeout
|
||||
if timeout < NextTraceAPIV4MinTimeout {
|
||||
return NextTraceAPIV4MinTimeout
|
||||
}
|
||||
return timeout
|
||||
}
|
||||
|
||||
@@ -1273,8 +1273,8 @@ func TestNewNextTraceAPIV4ClientDefaultsBoundedHTTPClient(t *testing.T) {
|
||||
if client.httpClient == nil {
|
||||
t.Fatal("httpClient = nil, want bounded default client")
|
||||
}
|
||||
if client.httpClient.Timeout < nextTraceAPIV4MinTimeout {
|
||||
t.Fatalf("httpClient.Timeout = %s, want at least %s", client.httpClient.Timeout, nextTraceAPIV4MinTimeout)
|
||||
if client.httpClient.Timeout < NextTraceAPIV4MinTimeout {
|
||||
t.Fatalf("httpClient.Timeout = %s, want at least %s", client.httpClient.Timeout, NextTraceAPIV4MinTimeout)
|
||||
}
|
||||
if client.httpClient == http.DefaultClient {
|
||||
t.Fatal("httpClient = http.DefaultClient, want bounded default client")
|
||||
|
||||
@@ -9,7 +9,7 @@ RESULT_DIR="${PERF_RESULT_DIR:-${ROOT_DIR}/.cache/perf}"
|
||||
PROFILE_COMPONENT_TIME="${PROFILE_COMPONENT_TIME:-10s}"
|
||||
BENCH_GOMAXPROCS="${BENCH_GOMAXPROCS:-10}"
|
||||
PGO_SEED=20260905
|
||||
REQUIRED_GO_VERSION=go1.27.3
|
||||
REQUIRED_GO_VERSION=go1.27.4
|
||||
|
||||
export GOTOOLCHAIN="${REQUIRED_GO_VERSION}"
|
||||
export GOEXPERIMENT=
|
||||
|
||||
@@ -15,7 +15,7 @@ RESULT_DIR="${PERF_RESULT_DIR:-${ROOT_DIR}/.cache/perf}"
|
||||
BENCH_COUNT="${BENCH_COUNT:-10}"
|
||||
BENCH_TIME="${BENCH_TIME:-1s}"
|
||||
BENCH_GOMAXPROCS="${BENCH_GOMAXPROCS:-10}"
|
||||
REQUIRED_GO_VERSION=go1.27.3
|
||||
REQUIRED_GO_VERSION=go1.27.4
|
||||
|
||||
export GOTOOLCHAIN="${REQUIRED_GO_VERSION}"
|
||||
export GOEXPERIMENT=
|
||||
|
||||
@@ -271,6 +271,14 @@ check_json_pure() {
|
||||
record "${name}" SKIP "${note}; external service unavailable"
|
||||
return
|
||||
fi
|
||||
if [[ "${name}" == json_globalping ]]; then
|
||||
case "$(tr -d '\r' < "${out}")" in
|
||||
'globalping measurement results did not include hop data'|'no matching IPv4 probes available - please try a different location')
|
||||
record "${name}" SKIP "${note}; external Globalping probe unavailable"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if ! allowed_exit_matches "${rc}" "${allowed_csv}"; then
|
||||
record "${name}" FAIL "${note}; exit=${rc}"
|
||||
return
|
||||
@@ -622,7 +630,7 @@ if DEPLOY_BASE_URL="$(wait_deploy_base_url "${DEPLOY_LOG}")" && wait_http_ready
|
||||
else
|
||||
record deploy_options FAIL 'Options API check failed'
|
||||
fi
|
||||
if curl -fsS --connect-timeout 2 --max-time 5 -X POST -H 'Content-Type: application/json' --data '{"target":"1.1.1.1","queries":1,"max_hops":3,"timeout_ms":1000}' "${DEPLOY_BASE_URL}/api/trace" >"${ART_DIR}/deploy_trace.txt" 2>&1 && grep -Fq '"resolved_ip"' "${ART_DIR}/deploy_trace.txt"; then
|
||||
if curl -fsS --connect-timeout 2 --max-time 5 -X POST -H 'Content-Type: application/json' --data '{"target":"1.1.1.1","queries":1,"max_hops":3,"timeout_ms":1000,"data_provider":"disable-geoip","disable_rdns":true,"disable_maptrace":true}' "${DEPLOY_BASE_URL}/api/trace" >"${ART_DIR}/deploy_trace.txt" 2>&1 && grep -Fq '"resolved_ip"' "${ART_DIR}/deploy_trace.txt"; then
|
||||
record deploy_trace PASS 'REST trace endpoint works'
|
||||
else
|
||||
record deploy_trace FAIL 'REST trace endpoint failed'
|
||||
|
||||
@@ -440,6 +440,13 @@ function Check-JsonPure {
|
||||
Write-Record $Name SKIP "$Note; external service unavailable"
|
||||
return
|
||||
}
|
||||
if ($Name -eq "json_globalping" -and ([string]$content).Trim() -in @(
|
||||
"globalping measurement results did not include hop data",
|
||||
"no matching IPv4 probes available - please try a different location"
|
||||
)) {
|
||||
Write-Record $Name SKIP "$Note; external Globalping probe unavailable"
|
||||
return
|
||||
}
|
||||
$sanitizedContent = [regex]::Replace($content, $powLogPattern, "")
|
||||
$bytes = [System.Text.Encoding]::UTF8.GetBytes($sanitizedContent)
|
||||
$first = ""
|
||||
@@ -883,7 +890,7 @@ try {
|
||||
}
|
||||
if ($icmp4Capability.Supported) {
|
||||
try {
|
||||
$body = '{"target":"1.1.1.1","queries":1,"max_hops":3,"timeout_ms":1000}'
|
||||
$body = '{"target":"1.1.1.1","queries":1,"max_hops":3,"timeout_ms":1000,"data_provider":"disable-geoip","disable_rdns":true,"disable_maptrace":true}'
|
||||
Invoke-WebRequest -UseBasicParsing -Method Post -ContentType "application/json" -Body $body -Uri "$deployBaseUrl/api/trace" -TimeoutSec 15 | Select-Object -ExpandProperty Content | Tee-Object -FilePath (Join-Path $ArtifactsDir "deploy_trace.txt") | Out-Null
|
||||
$traceBody = Get-Content -Raw -Path (Join-Path $ArtifactsDir "deploy_trace.txt")
|
||||
if ($traceBody.Contains('"resolved_ip"')) {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
"protocol": "icmp",
|
||||
"queries": 3,
|
||||
"max_hops": 30,
|
||||
"timeout_ms": 1000,
|
||||
"timeout_ms": 3000,
|
||||
"packet_size": nil,
|
||||
"tos": 0,
|
||||
"parallel_requests": 18,
|
||||
|
||||
@@ -33,7 +33,7 @@ Supported:
|
||||
"port": 443,
|
||||
"queries": 3,
|
||||
"max_hops": 30,
|
||||
"timeout_ms": 1000,
|
||||
"timeout_ms": 3000,
|
||||
"packet_size": 64,
|
||||
"tos": 0,
|
||||
"parallel_requests": 18,
|
||||
|
||||
Reference in new issue
Block a user