Skip to content

Commit c991982

Browse files
authored
Merge pull request #375 from nxtrace/main
Fix fast-trace initialization issues and update dependencies
2 parents 4c4c07c + 3e584ed commit c991982

13 files changed

Lines changed: 568 additions & 94 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- name: Set up Go (built-in cache)
8181
uses: actions/setup-go@v6
8282
with:
83-
go-version: '1.26.x'
83+
go-version: '1.26.4'
8484
check-latest: true
8585
cache: true
8686

@@ -203,7 +203,7 @@ jobs:
203203
- name: Set up Go (built-in cache)
204204
uses: actions/setup-go@v6
205205
with:
206-
go-version: '1.26.x'
206+
go-version: '1.26.4'
207207
check-latest: true
208208
cache: true
209209

.github/workflows/regression.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- name: Set up Go
5151
uses: actions/setup-go@v6
5252
with:
53-
go-version: "1.26.x"
53+
go-version: "1.26.4"
5454
check-latest: true
5555
cache: true
5656

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ jobs:
4646
- name: Set up Go (built-in cache)
4747
uses: actions/setup-go@v6
4848
with:
49-
go-version: '1.26.x'
49+
go-version: '1.26.4'
5050
check-latest: true
5151
cache: true
5252

5353
- name: Test with unix
5454
if: ${{ matrix.os != 'windows-latest' }}
5555
shell: bash
5656
run: |
57-
sudo go env -w GOTOOLCHAIN=go1.26.0+auto
57+
sudo go env -w GOTOOLCHAIN=go1.26.4+auto
5858
sudo go test -v -covermode=count -coverprofile='coverage.out' ./...
5959
6060
- name: Smoke test nt_install.sh
@@ -68,5 +68,5 @@ jobs:
6868
- name: Test with windows
6969
if: ${{ matrix.os == 'windows-latest' }}
7070
run: |
71-
go env -w GOTOOLCHAIN=go1.26.0+auto
71+
go env -w GOTOOLCHAIN=go1.26.4+auto
7272
go test -v -covermode=count -coverprofile="coverage.out" ./...

AGENTS.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- 名称:NextTrace (NTrace-core)
88
- 仓库:github.com/nxtrace/NTrace-core
99
- 模块:`github.com/nxtrace/NTrace-core`
10-
- 语言:Go(`go 1.26.0`
10+
- 语言:Go(`go 1.26.4`
1111
- 入口:`main.go -> cmd.Execute()`
1212
- 核心能力:ICMP/TCP/UDP traceroute、GeoIP/RDNS、MTR 连续探测、Web/API、多平台构建
1313

@@ -31,6 +31,8 @@
3131
- 一个提交包含多个互不相关主题时,优先拆分提交;确实需要放在一起时,subject 写主影响,body 写清每个具体改动。
3232
- 提交或 push PR 前必须检查 `git log --oneline main..HEAD`,发现泛化、误导或与 diff 不匹配的 commit message,应先 reword/amend。
3333
- 改写已推送 PR 分支历史后,只使用 `git push --force-with-lease`,不要用无保护的强推覆盖远端新提交。
34+
- 在本工作区发布 PR 时,目标仓库必须是 `nxtrace/NTrace-dev`;禁止直接向 `nxtrace/NTrace-core` 创建 PR。
35+
- 如果 GitHub 工具或远端推断结果指向 `nxtrace/NTrace-core`,必须改为 `nxtrace/NTrace-dev` 或停止确认,不能直接创建 PR。
3436

3537
## 当前 CLI 语义(重点)
3638

@@ -350,11 +352,12 @@
350352

351353
## CI 与工具链(当前)
352354

353-
- `go.mod`: `go 1.26.0`
355+
- `go.mod`: `go 1.26.4`
354356
- GitHub Actions:
355-
- `.github/workflows/build.yml` 使用 `setup-go@v6` + `go-version: 1.26.x`
356-
- `.github/workflows/test.yml` 使用 `setup-go@v6` + `go-version: 1.26.x`
357-
- test workflow 中 `GOTOOLCHAIN=go1.26.0+auto`
357+
- `.github/workflows/build.yml` 使用 `setup-go@v6` + `go-version: 1.26.4`
358+
- `.github/workflows/test.yml` 使用 `setup-go@v6` + `go-version: 1.26.4`
359+
- `.github/workflows/regression.yml` 使用 `setup-go@v6` + `go-version: 1.26.4`
360+
- test workflow 中 `GOTOOLCHAIN=go1.26.4+auto`
358361
- build matrix 已移除 `windows/arm`
359362
- `.cross_compile.sh` 与 workflow 里的 `go build` 现在都用数组构造 `-tags` 参数,避免 shell word-splitting;脚本也会把当前 `GOARM` 传给 `compress_with_upx`,使 linux/armv7 目标能命中对应压缩分支。
360363
- `ipgeo/ipdbone.go` 不再原地修改全局 `defaultClient.httpClient.Timeout`;超时覆盖会通过克隆 client(复用 token cache / token init,同步替换整个 HTTP client)实现,避免 dial timeout 与 client timeout 脱节。

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,19 @@ This software is still in the early stages of development and may have many flaw
918918
919919
[https://github.com/Archeb/opentrace](https://github.com/Archeb/opentrace)
920920
921-
## NEXTTRACE WEB API
921+
## GlobalTrace
922922
923-
`NextTraceWebApi` is a web-based server implementation of `NextTrace` in the `MTR` style, offering various deployment options including `Docker`.
923+
`GlobalTrace` is an open-source `Globalping x NextTrace` web traceroute project. It uses Globalping's worldwide probe network to run `MTR` measurements from multiple regions, then enriches hop IPs with the NextTrace / NTrace backbone IP database for GeoIP, ASN, and network ownership details.
924924
925-
For WebSocket continuous tracing, MTR now streams per-event payloads with `type: "mtr_raw"` (instead of periodic `mtr` snapshots).
925+
Website: [https://lg.nxtrace.org](https://lg.nxtrace.org)
926926
927-
[https://github.com/nxtrace/nexttracewebapi](https://github.com/nxtrace/nexttracewebapi)
927+
Project: [nxtrace/GlobalTrace](https://github.com/nxtrace/GlobalTrace)
928+
929+
## NextTrace Web
930+
931+
`NextTrace Web` is a web-based server implementation of `NextTrace` in the `MTR` style, offering various deployment options including `Docker`.
932+
933+
[https://github.com/nxtrace/nexttraceweb](https://github.com/nxtrace/nexttraceweb)
928934
929935
## Deploy WebUI and MCP
930936

README_zh_CN.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,19 @@ nexttrace --pow-provider sakura
918918
919919
[https://github.com/Archeb/opentrace](https://github.com/Archeb/opentrace)
920920
921-
## NEXTTRACE WEB API
921+
## GlobalTrace
922922
923-
`NextTraceWebApi`是一个`MTR`风格的`NextTrace`网页版服务端实现,提供了包括`Docker`在内多种部署方式
923+
`GlobalTrace` 是一个 `Globalping x NextTrace` 开源 Web 路由追踪项目。它借助 Globalping 遍布全球的 Probe 从不同地区发起 `MTR` measurement,并结合 NextTrace / NTrace 骨干网 IP 数据库补充 hop 的 GeoIP、ASN 与网络归属信息
924924
925-
在 WebSocket 持续探测模式中,MTR 现改为逐事件推送 `type: "mtr_raw"`(不再使用周期性 `mtr` 快照消息)。
925+
网站:[https://lg.nxtrace.org](https://lg.nxtrace.org)
926926
927-
[https://github.com/nxtrace/nexttracewebapi](https://github.com/nxtrace/nexttracewebapi)
927+
项目地址:[nxtrace/GlobalTrace](https://github.com/nxtrace/GlobalTrace)
928+
929+
## NextTrace Web
930+
931+
`NextTrace Web`是一个`MTR`风格的`NextTrace`网页版服务端实现,提供了包括`Docker`在内多种部署方式。
932+
933+
[https://github.com/nxtrace/nexttraceweb](https://github.com/nxtrace/nexttraceweb)
928934
929935
## Deploy WebUI 与 MCP
930936

cmd/cmd.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
prepareNextTraceAPIV4FastIPFn = ipgeo.PrepareNextTraceAPIV4FastIP
5454
newLeoWebsocketFn = wshandle.NewWithContext
5555
newLeoWebsocketAsyncFn = wshandle.NewWithContextAsync
56+
runFastTraceFn = fastTrace.FastTest
5657
)
5758

5859
func normalizeListenAddr(addr string) string {
@@ -801,14 +802,23 @@ func maybeRunFastTraceMode(from string, fastTraceFlag bool, file string, params
801802
if from != "" || (!fastTraceFlag && file == "") {
802803
return false
803804
}
804-
fastTrace.FastTest(method, params)
805+
runFastTraceFn(method, params)
805806
if params.OutputPath != "" {
806807
fmt.Printf("您的追踪日志已经存放在 %s 中\n", params.OutputPath)
807808
}
808-
os.Exit(0)
809809
return true
810810
}
811811

812+
func runFastTraceModeWithRuntime(ctx context.Context, dn42 bool, dataOrigin *string, disableMaptrace *bool, powProvider *string, from string, fastTraceFlag bool, file string, params fastTrace.ParamsFastTrace, method trace.Method) bool {
813+
if from != "" || (!fastTraceFlag && file == "") {
814+
return false
815+
}
816+
leoWs, runtimePrepared := prepareFastTraceRuntimeEnvironment(ctx, dn42, dataOrigin, disableMaptrace, powProvider)
817+
defer closeLeoWebsocket(leoWs)
818+
params.RuntimePrepared = runtimePrepared
819+
return maybeRunFastTraceMode(from, fastTraceFlag, file, params, method)
820+
}
821+
812822
func configureGeoDNS(dot string) {
813823
if dot != "" {
814824
util.SetGeoDNSResolver(dot)
@@ -874,9 +884,20 @@ func prepareRuntimeEnvironment(ctx context.Context, dn42 bool, dataOrigin *strin
874884
return initLeoWebsocket(ctx, dataOrigin, powProvider, asyncLeo)
875885
}
876886

887+
func prepareFastTraceRuntimeEnvironment(ctx context.Context, dn42 bool, dataOrigin *string, disableMaptrace *bool, powProvider *string) (*wshandle.WsConn, bool) {
888+
capabilitiesCheck()
889+
applyDN42Mode(dn42, dataOrigin, disableMaptrace)
890+
return initLeoRuntime(ctx, dataOrigin, powProvider, false)
891+
}
892+
877893
func initLeoWebsocket(ctx context.Context, dataOrigin, powProvider *string, async bool) *wshandle.WsConn {
894+
leoWs, _ := initLeoRuntime(ctx, dataOrigin, powProvider, async)
895+
return leoWs
896+
}
897+
898+
func initLeoRuntime(ctx context.Context, dataOrigin, powProvider *string, async bool) (*wshandle.WsConn, bool) {
878899
if !strings.EqualFold(*dataOrigin, "LEOMOEAPI") {
879-
return nil
900+
return nil, false
880901
}
881902
if !strings.EqualFold(*powProvider, "api.nxtrace.org") {
882903
util.PowProviderParam = *powProvider
@@ -885,11 +906,11 @@ func initLeoWebsocket(ctx context.Context, dataOrigin, powProvider *string, asyn
885906
*dataOrigin = util.EnvDataProvider
886907
}
887908
if !strings.EqualFold(*dataOrigin, "LEOMOEAPI") {
888-
return nil
909+
return nil, false
889910
}
890911
if ipgeo.NextTraceAPIV4TokenConfigured() {
891912
if err := prepareNextTraceAPIV4FastIPFn(ctx, true); err == nil {
892-
return nil
913+
return nil, true
893914
}
894915
}
895916

@@ -899,7 +920,7 @@ func initLeoWebsocket(ctx context.Context, dataOrigin, powProvider *string, asyn
899920
} else {
900921
leoWs = newLeoWebsocketFn(ctx)
901922
}
902-
return leoWs
923+
return leoWs, leoWs != nil
903924
}
904925

905926
func closeLeoWebsocket(leoWs *wshandle.WsConn) {
@@ -1515,7 +1536,7 @@ func Execute() {
15151536
Dot: *dot,
15161537
OutputPath: resolvedOutputPath,
15171538
}
1518-
if maybeRunFastTraceMode(*from, *fastTraceFlag, *file, paramsFastTrace, method) {
1539+
if runFastTraceModeWithRuntime(rootCtx, *dn42, dataOrigin, disableMaptrace, powProvider, *from, *fastTraceFlag, *file, paramsFastTrace, method) {
15191540
return
15201541
}
15211542

0 commit comments

Comments
 (0)