mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
channel: master
version: 1.2.0
source-ref: D:\code\open_source\ant-chrome master
source-commit: f3d7ec5
merged-public-base: 3d264eb
29 lines
734 B
Go
29 lines
734 B
Go
package proxy
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"time"
|
|
|
|
"ant-chrome/backend/internal/logger"
|
|
)
|
|
|
|
// ─── TCP Ping 降级 ───
|
|
|
|
func tcpPingFallback(proxyId, src string, timeout time.Duration, log *logger.Logger) TestResult {
|
|
endpoint, err := proxyEndpoint(src)
|
|
if err != nil {
|
|
return TestResult{ProxyId: proxyId, Ok: false, Error: fmt.Sprintf("无法解析代理地址: %v", err)}
|
|
}
|
|
|
|
start := time.Now()
|
|
conn, err := net.DialTimeout("tcp", endpoint, timeout)
|
|
latency := time.Since(start).Milliseconds()
|
|
|
|
if err != nil {
|
|
return TestResult{ProxyId: proxyId, Ok: false, LatencyMs: latency, Error: fmt.Sprintf("TCP 连接失败: %v", err)}
|
|
}
|
|
conn.Close()
|
|
return TestResult{ProxyId: proxyId, Ok: true, LatencyMs: latency}
|
|
}
|