From cdcdfd8ff0353c328010c8797893c106dde53592 Mon Sep 17 00:00:00 2001 From: sagitchu Date: Sat, 2 May 2026 14:23:51 +0800 Subject: [PATCH] fix: use custom probe targets for diagnostics Move custom probe target controls into the tunnel advanced settings and reuse the configured target in tunnel diagnosis output. --- .../internal/http/handler/control_plane.go | 13 +- .../handler/tunnel_probe_target_api_test.go | 16 +++ vite-frontend/src/pages/tunnel.tsx | 121 +++++++++++------- vite-frontend/src/pages/tunnel/diagnosis.ts | 8 +- 4 files changed, 102 insertions(+), 56 deletions(-) diff --git a/go-backend/internal/http/handler/control_plane.go b/go-backend/internal/http/handler/control_plane.go index ef5ab60..3f69dea 100644 --- a/go-backend/internal/http/handler/control_plane.go +++ b/go-backend/internal/http/handler/control_plane.go @@ -978,6 +978,7 @@ func (h *Handler) prepareTunnelDiagnosis(tunnelID int64) (string, string, []diag ipPreference := h.repo.GetTunnelIPPreference(tunnelID) protocol := strings.ToLower(strings.TrimSpace(tunnel.Protocol)) + probeTarget := effectiveTunnelProbeTargetValues(tunnel.ProbeTargetHost, tunnel.ProbeTargetPort) inNodes, chainHops, outNodes := splitChainNodeGroups(chainRows) workItems := make([]diagnosisWorkItem, 0, len(chainRows)*2) @@ -987,8 +988,8 @@ func (h *Handler) prepareTunnelDiagnosis(tunnelID int64) (string, string, []diag description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName) workItems = append(workItems, diagnosisWorkItem{ fromNodeID: inNode.NodeID, - targetIP: "www.bing.com", - targetPort: 443, + targetIP: probeTarget.Host, + targetPort: probeTarget.Port, description: description, protocol: "tcp", metadata: map[string]interface{}{ @@ -1079,8 +1080,8 @@ func (h *Handler) prepareTunnelDiagnosis(tunnelID int64) (string, string, []diag description := fmt.Sprintf("出口(%s)->外网", outNode.NodeName) workItems = append(workItems, diagnosisWorkItem{ fromNodeID: outNode.NodeID, - targetIP: "www.bing.com", - targetPort: 443, + targetIP: probeTarget.Host, + targetPort: probeTarget.Port, description: description, protocol: "tcp", metadata: map[string]interface{}{ @@ -1093,8 +1094,8 @@ func (h *Handler) prepareTunnelDiagnosis(tunnelID int64) (string, string, []diag description := fmt.Sprintf("入口(%s)->外网", inNode.NodeName) workItems = append(workItems, diagnosisWorkItem{ fromNodeID: inNode.NodeID, - targetIP: "www.bing.com", - targetPort: 443, + targetIP: probeTarget.Host, + targetPort: probeTarget.Port, description: description, protocol: "tcp", metadata: map[string]interface{}{ diff --git a/go-backend/internal/http/handler/tunnel_probe_target_api_test.go b/go-backend/internal/http/handler/tunnel_probe_target_api_test.go index 159076f..1114116 100644 --- a/go-backend/internal/http/handler/tunnel_probe_target_api_test.go +++ b/go-backend/internal/http/handler/tunnel_probe_target_api_test.go @@ -209,6 +209,22 @@ func TestTunnelUpdateInvalidProbeTargetDoesNotCleanFederationBindings(t *testing } } +func TestTunnelDiagnosisUsesConfiguredProbeTarget(t *testing.T) { + h := setupProbeTargetTunnelHandler(t) + seedProbeTargetTunnel(t, h, 90, "diagnosis-target", "speed.example.com", 8443) + + _, _, workItems, err := h.prepareTunnelDiagnosis(90) + if err != nil { + t.Fatalf("prepare tunnel diagnosis: %v", err) + } + if len(workItems) != 1 { + t.Fatalf("expected one diagnosis item, got %d", len(workItems)) + } + if workItems[0].targetIP != "speed.example.com" || workItems[0].targetPort != 8443 { + t.Fatalf("expected custom diagnosis target speed.example.com:8443, got %s:%d", workItems[0].targetIP, workItems[0].targetPort) + } +} + func setupProbeTargetTunnelHandler(t *testing.T) *Handler { t.Helper() r, err := repo.Open(filepath.Join(t.TempDir(), "panel.db")) diff --git a/vite-frontend/src/pages/tunnel.tsx b/vite-frontend/src/pages/tunnel.tsx index 4a2550b..d3bfce4 100644 --- a/vite-frontend/src/pages/tunnel.tsx +++ b/vite-frontend/src/pages/tunnel.tsx @@ -46,6 +46,7 @@ import { Alert } from "@/shadcn-bridge/heroui/alert"; import { Checkbox } from "@/shadcn-bridge/heroui/checkbox"; import { Progress } from "@/shadcn-bridge/heroui/progress"; import { Radio, RadioGroup } from "@/shadcn-bridge/heroui/radio"; +import { Accordion, AccordionItem } from "@/shadcn-bridge/heroui/accordion"; import { Table, TableHeader, @@ -137,6 +138,14 @@ interface Tunnel { createdTime: string; } +const DEFAULT_PROBE_TARGET_HOST = "www.bing.com"; +const DEFAULT_PROBE_TARGET_PORT = 443; + +const getTunnelDiagnosisTarget = (tunnel: Tunnel) => ({ + targetIp: tunnel.probeTargetHost || DEFAULT_PROBE_TARGET_HOST, + targetPort: tunnel.probeTargetPort || DEFAULT_PROBE_TARGET_PORT, +}); + interface Node { id: number; name: string; @@ -902,6 +911,7 @@ export default function TunnelPage() { const handleDiagnose = async (tunnel: Tunnel) => { diagnosisAbortRef.current?.abort(); const abortController = new AbortController(); + const diagnosisTarget = getTunnelDiagnosisTarget(tunnel); diagnosisAbortRef.current = abortController; @@ -1043,6 +1053,7 @@ export default function TunnelPage() { tunnelType: tunnel.type, description: "诊断失败", message: response.msg || "诊断过程中发生错误", + ...diagnosisTarget, }), ); setDiagnosisProgress({ @@ -1074,6 +1085,7 @@ export default function TunnelPage() { tunnelType: tunnel.type, description: "网络错误", message: "无法连接到服务器", + ...diagnosisTarget, }), ); setDiagnosisProgress({ @@ -2335,54 +2347,67 @@ export default function TunnelPage() { )} -
-
-
质量检测目标
-

- 用于实时隧道质量检测和 best 最优出口评分,留空使用 - www.bing.com:443 -

-
-
- - setForm((prev) => ({ - ...prev, - probeTargetHost: e.target.value, - })) - } - /> - - setForm((prev) => ({ - ...prev, - probeTargetPort: e.target.value - ? Number(e.target.value) - : 0, - })) - } - /> -
-
+ + + 高级设置 + + } + > +
+
+
质量检测目标
+

+ 用于实时隧道质量检测、诊断目标和 best + 最优出口评分,留空使用 www.bing.com:443 +

+
+
+ + setForm((prev) => ({ + ...prev, + probeTargetHost: e.target.value, + })) + } + /> + + setForm((prev) => ({ + ...prev, + probeTargetPort: e.target.value + ? Number(e.target.value) + : 0, + })) + } + /> +
+
+
+

入口配置

diff --git a/vite-frontend/src/pages/tunnel/diagnosis.ts b/vite-frontend/src/pages/tunnel/diagnosis.ts index 64f8271..81a7b94 100644 --- a/vite-frontend/src/pages/tunnel/diagnosis.ts +++ b/vite-frontend/src/pages/tunnel/diagnosis.ts @@ -27,6 +27,8 @@ export interface DiagnosisFallbackInput { tunnelType: number; description: string; message: string; + targetIp?: string; + targetPort?: number; } export const buildDiagnosisFallbackResult = ({ @@ -34,6 +36,8 @@ export const buildDiagnosisFallbackResult = ({ tunnelType, description, message, + targetIp = "-", + targetPort = 443, }: DiagnosisFallbackInput): DiagnosisResult => { return { tunnelName, @@ -45,8 +49,8 @@ export const buildDiagnosisFallbackResult = ({ description, nodeName: "-", nodeId: "-", - targetIp: "-", - targetPort: 443, + targetIp, + targetPort, message, }, ],