Commit Graph
149 Commits
Author SHA1 Message Date
tsosunchia 2a5717aedf Fix explicit source/device handling across platforms
Keep the default traceroute path unchanged when neither --source nor --dev is set so existing source address selection, socket setup, and logging stay untouched.

Add a shared explicit source/device normalization helper and route the CLI traceroute path, standalone --mtu path, fast_trace, and server trace requests through it. The helper keeps --source higher priority than --dev, resolves device-derived source addresses by destination family, rejects devices without a usable address, and emits at most one runtime warning.

On macOS, bind TCP and UDP send sockets to the requested interface with IP_BOUND_IF/IPV6_BOUND_IF so explicit --dev survives utun default routes. On Linux, bind ICMP/TCP/UDP send sockets with SO_BINDTODEVICE only when a source device is explicitly configured.

On Windows, keep the existing no-rewrite constraint for real device binding. Explicit --dev now resolves a source address, clears SourceDevice before the tracer is built, and surfaces a single warning that actual egress still follows system routing.

Update CLI help text and README platform notes to document the supported --dev semantics, and add unit tests that cover no-op behavior without explicit overrides, --source priority, device family resolution, mismatch errors, and the Windows downgrade warning.
2026-04-07 17:00:53 +08:00
tsosunchia b513155647 Handle missing WinDivert runtime gracefully on Windows 2026-03-22 12:53:04 +08:00
tsosunchia 1cda0e53bb Fix context propagation and FastIP cache synchronization 2026-03-19 15:58:35 +08:00
tsosunchia 7c96e4ce76 Fix globalping stub signature for tiny and ntr builds 2026-03-19 15:17:53 +08:00
tsosunchia 7b8e68710c Fix cancellation handling across DNS, trace, and ws flows 2026-03-19 12:22:02 +08:00
tsosunchia d05329276b Fix CLI, MTU, logging, and websocket regressions 2026-03-19 11:08:20 +08:00
tsosunchia 21396148d0 fix: improve Windows mtu handling and privilege prompts 2026-03-19 00:14:08 +08:00
tsosunchia e060c33777 feat: Enhance traceroute output handling and add tests
- Added support for output path and default output flag in traceroute commands.
- Implemented output path resolution logic with conflict checks.
- Updated globalping and MTR modes to handle new output options.
- Enhanced MTU mode with styled output and improved result printing.
- Refactored table printer to support clear screen option and added tests for table output.
- Introduced new logging functions in tracelog for better file handling and real-time output.
- Added comprehensive tests for new features and existing functionalities.
2026-03-18 22:49:22 +08:00
tsosunchia 976156ba91 fix: restore windows icmpv6 tos handling 2026-03-17 23:12:15 +08:00
tsosunchia cff34d401e feat: update probe packet size handling and defaults across CLI and server 2026-03-17 22:11:13 +08:00
tsosunchia 6eec12e78c fix: accept negative psize CLI values 2026-03-17 21:44:41 +08:00
tsosunchia d9dbcc2a38 feat: align psize semantics and add tos 2026-03-17 16:41:10 +08:00
tsosunchia f6816f9592 feat: add standalone mtu mode metadata and flavor gating 2026-03-17 11:33:36 +08:00
tsosunchia 3c956068ee fix: make mtu probing follow hop pmtu updates 2026-03-16 23:51:16 +08:00
tsosunchia e448ad7320 fix: show hop-level pmtu updates in mtu mode 2026-03-16 23:37:22 +08:00
tsosunchia 4d967ba7aa feat: add standalone mtu trace mode 2026-03-16 23:10:06 +08:00
tsosunchia 8806c3b24f fix: close stale ws client loops and clear init deadline 2026-03-16 21:43:06 +08:00
tsosunchia 0b0c6662e8 修复 MTR 调度 goroutine 泄漏 2026-03-15 22:11:44 +08:00
tsosunchia fe8f1aea75 feat: refactor flag registration functions and enhance trace map URL handling 2026-03-13 20:49:38 +08:00
tsosunchia fc125bea4c refactor mtr ui render hotspots 2026-03-08 13:59:46 +08:00
tsosunchia 81797d4b5f Improve gocyclo complexity 2026-03-08 10:54:41 +08:00
tsosunchia d8e93c2a35 feat: improve fast trace flag naming and enhance layout computation tests 2026-03-07 23:05:43 +08:00
tsosunchia 816949e90c feat: enhance Windows compatibility by adjusting flag initialization and layout computation 2026-03-07 20:26:42 +08:00
tsosunchia 77abf1b515 Refactor MTR signal handling and context management
- Unified signal handling in MTR CLI using `signal.NotifyContext(...)` for Ctrl-C/SIGTERM, removing the need for separate `sigCh` and goroutine.
- Updated `runMTRTUI`, `runMTRReport`, and `runMTRRaw` functions to utilize the new context management.
- Enhanced `mtrUI` to safely call `cancel()` only if it is not nil.
- Modified `IPDBOneClient` to clone HTTP clients with timeout settings, ensuring proper timeout handling without modifying global state.
- Adjusted raw aggregation keys in the frontend to collapse based on TTL, improving display of timeout/success results.
- Added context support in various tracer functions to allow cancellation and timeout handling.
- Improved error handling and test coverage for MTR operations, ensuring robustness against nil results and empty responses.
- Refined DNS resolver functions to use mutexes for thread-safe access to the geo resolver override.
2026-03-06 14:07:58 +08:00
tsosunchia a9a2325762 feat: enhance build scripts and improve error handling for Windows TCP traces 2026-03-06 13:48:16 +08:00
tsosunchia f69903a00c fix(web): resolve post-v1.5.0 review findings
Address all three review findings from the v1.5.0..HEAD audit:\n- Remove Web MTR reliance on process-wide globals (SrcDev/DisableMPLS) by passing session-scoped trace.Config fields.\n- Apply dot_server consistently to Web/API Geo DNS and LeoMoe/FastIP initialization via scoped resolver setup.\n- Restore Web MTR default per-hop cadence to 1000ms and send hop_interval_ms from frontend.\n\nAlso added regression tests in server/trace_handler_test.go and util/dns_resolver_test.go, and updated CLAUDE.md.\n\nValidation passed:\n- go test ./...\n- go build ./...\n- go build -tags flavor_ntr ./...\n- go build -tags flavor_tiny ./...\n- node --check server/web/assets/app.js
2026-03-06 13:04:42 +08:00
tsosunchia 9eff7aabf4 feat: introduce build variants for NextTrace with flavor options
- Added three build flavors: `nexttrace` (full), `nexttrace-tiny`, and `ntr` (MTR-focused).
- Updated README.md and README_zh_CN.md to reflect new build variants and their features.
- Implemented manual build instructions for each flavor.
- Enhanced command-line argument parsing to accommodate flavor-specific options.
- Disabled WebUI and Globalping features in `nexttrace-tiny` and `ntr` flavors.
- Created separate files for handling Globalping and WebUI functionality based on build flavor.
- Added error handling for unavailable features in non-full builds.
2026-03-05 22:05:38 +08:00
tsosunchia efb437fbac fix: improve error handling and logging across multiple packages
- Enhanced error handling in `mtr_ui.go` to log warnings when raw mode cannot be enabled.
- Updated `geofeed.go` to return a more informative error instead of panicking when geofeed data cannot be loaded.
- Refined error handling in `ptr.go` to return an error if `ptrPath` is not configured.
- Improved error handling in `fast_trace.go` for network interface address retrieval.
- Added error checks in `chunzhen.go` and `ipapicom.go` for HTTP request creation and response reading.
- Enhanced error handling in `ipdbone.go` to return descriptive errors for authentication failures.
- Updated `ipfilter.go` to ensure proper IP parsing before filtering.
- Improved error handling in `ipinfoLocal.go` for database access and record parsing.
- Enhanced error handling in `ipsb.go` for HTTP request creation and response reading.
- Added checks for closed channels in `leo.go` to prevent panics.
- Improved panic recovery in `ws_handler.go` to log errors in the write loop.
- Added read deadline to WebSocket connections in `ws_handler.go` to prevent blocking.
- Enhanced configuration checks in `globalping.go` to avoid nil pointer dereferences.
- Improved error logging in `icmp_ipv4.go` and `icmp_ipv6.go` for send errors.
- Enhanced error handling in `icmp_darwin.go`, `icmp_unix.go`, and `icmp_windows.go` for checksum setting.
- Improved error handling in TCP and UDP implementations across various platforms for checksum settings.
- Enhanced error handling in `tracemap.go` for proxy configuration.
- Improved type assertions in `util.go` for DNS cache lookups.
2026-03-02 00:14:49 +08:00
tsosunchia 89ce9a660d feat: 增强 MTR 调度器,支持每跳多个并发探测,优化超时处理和统计逻辑 2026-03-01 20:20:25 +08:00
tsosunchia ad3ecbd401 fix: 统一处理 context.Canceled 错误检查,确保一致性
feat(ipgeo): 在 API 请求中添加 defer 关闭响应体
fix: 修复 MTR 模式中错误处理逻辑,确保资源正确释放
test: 更新测试用例以验证 context.Canceled 错误处理
refactor: 优化 mplsSet 初始化逻辑
test: 修改测试断言为 require,增强错误处理
2026-03-01 19:24:20 +08:00
tsosunchia 8ef2caa6de feat(tests): 增加多个单元测试以验证 IP 地址过滤和处理功能 2026-03-01 17:05:47 +08:00
tsosunchia f95cce8312 feat(cmd): 更新命令行参数帮助信息,明确 -z/--send-time 在 MTR 模式下被忽略 2026-03-01 05:08:28 +08:00
tsosunchia 361e14a27d feat(mtr): 更新 MTR 模式参数,调整每跳探测间隔,忽略 -z/--send-time,新增 MPLS 显示切换功能 2026-03-01 04:58:49 +08:00
tsosunchia 92e93ff0d4 feat(mtr): 压缩 TUI 指标区、折叠高 TTL 目标、重排显示模式并新增 -y/--ipinfo
本次修改仅影响 CLI 下的 MTR TUI 模式,不涉及 --report/--wide/--raw、普通 traceroute 或 Web MTR。

主要变更:
- 指标区压缩:将 Loss% 列宽缩至 5、Snt 缩至 3、RTT 五列缩至 7,列名不变,双行表头仍保留,提高 Host 列宽度。
- 目标折叠:目标在某个 TTL 确认后,后续更高 TTL 的 dst‑ip 响应不再单独显示,而是折叠到最终 TTL;折叠后 Snt 不得超过 MaxPerHop,超出部分丢弃;调度器区分 originTTL/accountTTL,disabled TTL 的 dst‑ip 回复允许折叠。
- 显示模式扩展:新增 HostModeBase (0),五档依次为 IP/PTR、ASN、City、Owner、Full;默认显示 IP/PTR。`y` 键循环顺序调整为 0→1→2→3→4→0。
- 新增 CLI 参数 `-y, --ipinfo` (0..4) 用于设置 TUI 初始显示模式;在 --report/--wide/--raw 中可解析但被忽略;非法值报错。
- `runMTRTUI`/`newMTRUI` 支持传入初始 mode,`r` 键重置统计不再影响显示模式。
- 当 mode ≥ ASN 且无 ASN 时插入 `AS???` 占位符;Base 模式不显示占位符。
- 更新 CLI 帮助、README 与 README_zh_CN 文档,说明新的默认模式、y 键循环和 `-y/--ipinfo` 映射关系。
- 新增或调整单元测试,覆盖显示模式循环、默认与初始值、参数校验与忽略逻辑、主机信息渲染、紧凑布局以及目标折叠等场景。

非目标:report/wide/raw 模式、Web MTR 和普通 traceroute。
2026-03-01 02:03:56 +08:00
tsosunchia 233d4eea5d Implement per-hop independent MTR scheduler and associated tests
- Added `mtr_scheduler.go` to implement a per-hop independent scheduling mechanism for MTR (My Traceroute) probes.
- Introduced `mtrTTLProber` interface for probing TTLs and handling probe results.
- Implemented `runMTRScheduler` function to manage the scheduling of probes based on TTL, handle errors, and aggregate results.
- Added configuration options for hop intervals, maximum hops, and error handling.
- Created `mtr_scheduler_test.go` to include comprehensive unit tests for the scheduler, covering various scenarios such as maximum probes per hop, context cancellation, destination detection, error budgets, and reset functionality.
- Mocked TTL prober to simulate probe responses and track probe counts for testing.
2026-02-28 15:47:40 +08:00
tsosunchia 69f2ca680b feat: 更新文档和代码,增强 MTR 功能,优化 API 信息输出 2026-02-28 13:14:03 +08:00
tsosunchia bd32808ceb Disable geo lookup for non wide MTR 2026-02-28 11:55:31 +08:00
tsosunchia c3bfb6c21e Revert MTR TUI host spacing 2026-02-28 11:49:13 +08:00
tsosunchia ea15375b5b feat: 增强 MTR 原始流式模式,添加 API 信息输出和 TTL 间隔控制 2026-02-28 11:09:06 +08:00
tsosunchia d41d8b2fba feat: Introduce MTR raw streaming functionality
- Added support for streaming probe-level MTR raw events via `trace.RunMTRRaw`.
- Implemented a new `mtrRawAggregator` to handle raw MTR data aggregation.
- Updated the web client to handle `mtr_raw` messages and render statistics accordingly.
- Introduced new JavaScript module `mtr_agg.js` for aggregating MTR raw data.
- Created new printer functions for formatting MTR raw records.
- Added tests for the new MTR raw functionality to ensure correct behavior.
- Deprecated the legacy snapshot aggregator for MTR.
2026-02-28 09:41:25 +08:00
tsosunchia 4bf6d68dc5 feat: 添加 --show-ips 选项以在 MTR 输出中同时显示 PTR 和 IP 地址 2026-02-28 01:23:17 +08:00
tsosunchia a523cda440 feat: 更新 Go 版本至 1.26.0,调整构建和测试工作流,增强输入解析器 2026-02-28 00:13:21 +08:00
tsosunchia 6c8912d78d feat(dns): 添加 Geo DNS 解析策略,支持 DoT 和系统 DNS 回退 2026-02-27 23:16:34 +08:00
tsosunchia ae08ec9796 fix(mtr): 提前冲突校验并修复 report 模式 CJK 对齐
- 将 MTR 冲突检查前移到所有 early-return 分支之前,避免 `-r --from`、`-t --fast-trace`、`--file` 等组合绕过校验
- report 输出改用 `go-runewidth` 计算显示宽度与截断(`StringWidth`/`Truncate`)
- 新增 `reportPadRight`,替换 `%*s` 对齐路径,修复中文场景下 HOST 与指标列错位
- 保持 wide/非 wide 逻辑不变,仅修复布局与参数校验时序
- tests: `go test -ldflags "-checklinkname=0" ./...`
2026-02-27 21:51:38 +08:00
tsosunchia 24224cf943 feat: Enhance MTR mode with source IP resolution and name mode toggle
- Removed the conflicting `--report` flag from MTR mode.
- Added `dataOrigin` parameter to `runMTRMode` for preferred API information.
- Implemented `resolveSrcIP` function to determine source IP based on priority.
- Introduced `nameMode` in `mtrUI` to toggle between PTR/IP and IP only display.
- Updated MTR table rendering functions to accommodate the new name mode.
- Enhanced tests to cover name mode functionality and API info display in TUI.
- Suppressed output of preferred API IP in MTR mode to avoid terminal pollution.
2026-02-27 20:50:47 +08:00
tsosunchia 86a2fd555b feat(mtr): 对齐 mtr 风格显示并完善窄屏右锚定
- 重构 TUI Header:
  - Line1 改为 `NextTrace [vX.Y.Z]`
  - Line2 改为 `srcHost(srcIP) -> dstName(dstIP) + 时间戳`(时间右侧对齐)
  - Keys 行增加 `y-display(...)` 模式提示
- Host 列新增 4 种显示模式并支持 `y/Y` 循环切换:
  - ASN / City / Owner / Full
  - `r` 重置统计不影响当前显示模式
- Host 基础标识调整为 PTR-or-IP(有 PTR 显示 PTR,无 PTR 显示 IP)
- City 模式改为单级回退链:`City -> Prov -> Country`
- 语言一致性修正:默认中文,`--language en` 才优先英文(缺失字段自动回退)
- MPLS 从主行内联改为独立续行显示(更贴近 mtr)

布局修复(review P2):
- 修复窄屏下指标区未贴右边界问题:
  - `computeLayout` 在 phase-2/3 收敛后回填 slack 到 hostW
  - 保证 `metricsStart + metricsWidth == termWidth`,指标区严格右锚定

测试:
- 更新/新增 Host 模式、语言回退、MPLS 多行、Header、`y` 键循环、窄屏右锚定断言等测试
- 全量测试通过
2026-02-27 20:09:16 +08:00
tsosunchia da10275b51 feat(mtr): 对齐 mtr 交互与展示,支持流式首屏/重置统计/目的跳截断
1. 启动与刷新:引入 `mtrPeeker + ProgressThrottle`,在首轮未完成时按节流推送预览快照,不再“整轮结束才出画面”。
2. 跳数前缀:每行开头改为 mtr 简约风格(`N.` / 同 TTL 续行空前缀)。
3. 运行中重置统计:新增 `r` 键(Restart statistics),重置聚合统计、轮次计数、退避状态与目的 TTL 缓存。
4. 表头版本信息:新增 `My traceroute [NextTrace <version>]`。
5. 表头目标信息:第二行展示 `domain (ip)`;当输入本身是 IP 时避免 `1.1.1.1 (1.1.1.1)` 重复显示。
6. MPLS 展示恢复:Host 列直接拼接底层提取的 MPLS 标签,修复不显示/双重包裹问题。
7. 目的跳后停止:检测 `DstIP` 命中后记录 `roundFinalTTL/knownFinalTTL`,后续轮次提前截断,不再把目标 IP 重复打印到 `maxHops`。

补充修正:
1. 流式预览中“未发送 TTL”保持 `nil` 槽位,不再被误计为 timeout(避免虚高 `Snt/Loss`)。
2. 新增对应单测覆盖未发送 TTL 场景与流式快照路径。

测试:
1. 新增/更新 `peekPartialResult`、流式刷新、重置统计、目的跳截断、Header/IP 去重、MPLS 展示等测试。
2. `go test ./...` 全量通过。
2026-02-27 19:05:06 +08:00
tsosunchia 52b6b5cb22 mtr模式 2026-02-27 17:34:46 +08:00
tsosunchia 26e2ff547c fix: 更新文档以移除对 Npcap 的依赖,改为使用 WinDivert 进行 ICMP 和 TCP/UDP 监听 2026-02-10 10:17:59 +08:00
Yunlq 071a496cc3 修改了README,并完善了一些参数的说明和处理 2025-11-20 01:39:21 +08:00