Skip to content

Commit d13faed

Browse files
Add files via upload
1 parent 73a6e14 commit d13faed

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

core_engine/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ func runTest(j TestJob, results chan<- TestResult) {
150150
func testProxy(listenIP string, port int) (int64, string) {
151151
const maxRetries = 3
152152
const retryDelay = 200 * time.Millisecond
153-
var lastError string
154153

154+
var lastError string
155+
bestPing := int64(-1)
155156
for attempt := 1; attempt <= maxRetries; attempt++ {
156157
targetURL := "http://www.google.com/generate_204"
157-
timeout := 5 * time.Second
158+
timeout := 8 * time.Second
158159

159160
dialer, err := proxy.SOCKS5("tcp", fmt.Sprintf("%s:%d", listenIP, port), nil, proxy.Direct)
160161
if err != nil {
@@ -176,7 +177,6 @@ func testProxy(listenIP string, port int) (int64, string) {
176177
time.Sleep(retryDelay)
177178
continue
178179
}
179-
180180
defer resp.Body.Close()
181181

182182
if resp.StatusCode != http.StatusNoContent {
@@ -185,7 +185,16 @@ func testProxy(listenIP string, port int) (int64, string) {
185185
continue
186186
}
187187

188-
return time.Since(start).Milliseconds(), "success"
188+
189+
currentPing := time.Since(start).Milliseconds()
190+
if bestPing == -1 || currentPing < bestPing {
191+
192+
bestPing = currentPing
193+
}
194+
}
195+
196+
if bestPing != -1 {
197+
return bestPing, "success"
189198
}
190199

191200
return -1, lastError

0 commit comments

Comments
 (0)