优化gost执行诊断时计入DNS解析时间的问题

This commit is contained in:
qaq
2025-11-21 16:27:58 +08:00
parent 4a23f3b45a
commit 31290137fe
2 changed files with 75 additions and 77 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ func main() {
log := xlogger.NewLogger() log := xlogger.NewLogger()
logger.SetDefault(log) logger.SetDefault(log)
wsReporter := socket.StartWebSocketReporterWithConfig(config.Addr, config.Secret, config.Http, config.Tls, config.Socks, "2.0.1") wsReporter := socket.StartWebSocketReporterWithConfig(config.Addr, config.Secret, config.Http, config.Tls, config.Socks, "2.0.2")
defer wsReporter.Stop() defer wsReporter.Stop()
service.SetHTTPReportURL(config.Addr, config.Secret) service.SetHTTPReportURL(config.Addr, config.Secret)
+1 -3
View File
@@ -14,8 +14,8 @@ import (
"time" "time"
"github.com/go-gost/x/config" "github.com/go-gost/x/config"
"github.com/go-gost/x/service"
"github.com/go-gost/x/internal/util/crypto" "github.com/go-gost/x/internal/util/crypto"
"github.com/go-gost/x/service"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/shirou/gopsutil/v3/cpu" "github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/host"
@@ -1133,7 +1133,6 @@ func tcpPingHost(ip string, port int, count int, timeoutMs int) (float64, float6
fmt.Printf("🔍 开始TCP ping测试: %s,次数: %d,超时: %dms\n", target, count, timeoutMs) fmt.Printf("🔍 开始TCP ping测试: %s,次数: %d,超时: %dms\n", target, count, timeoutMs)
// 如果是域名,先解析一次DNS,避免每次连接都重新解析导致延迟累加 // 如果是域名,先解析一次DNS,避免每次连接都重新解析导致延迟累加
var resolvedIPs []string
if net.ParseIP(ip) == nil { if net.ParseIP(ip) == nil {
// 是域名,需要解析 // 是域名,需要解析
fmt.Printf("🔍 检测到域名,正在解析DNS...\n") fmt.Printf("🔍 检测到域名,正在解析DNS...\n")
@@ -1149,7 +1148,6 @@ func tcpPingHost(ip string, port int, count int, timeoutMs int) (float64, float6
return 0, 100.0, fmt.Errorf("DNS解析未返回任何IP地址") return 0, 100.0, fmt.Errorf("DNS解析未返回任何IP地址")
} }
resolvedIPs = addrs
fmt.Printf("✅ DNS解析完成 (%.2fms),解析到 %d 个IP: %v\n", fmt.Printf("✅ DNS解析完成 (%.2fms),解析到 %d 个IP: %v\n",
dnsDuration.Seconds()*1000, len(addrs), addrs) dnsDuration.Seconds()*1000, len(addrs), addrs)