Skip to content

Commit 73a6e14

Browse files
Add files via upload
1 parent 0de4c30 commit 73a6e14

1 file changed

Lines changed: 40 additions & 21 deletions

File tree

core_engine/main.go

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,45 @@ func runTest(j TestJob, results chan<- TestResult) {
148148
}
149149

150150
func testProxy(listenIP string, port int) (int64, string) {
151-
targetURL := "http://www.google.com/generate_204"
152-
timeout := 8 * time.Second
153-
dialer, err := proxy.SOCKS5("tcp", fmt.Sprintf("%s:%d", listenIP, port), nil, proxy.Direct)
154-
if err != nil {
155-
return -1, fmt.Sprintf("failed_dialer: %v", err)
156-
}
157-
transport := &http.Transport{
158-
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
159-
return dialer.Dial(network, addr)
160-
},
161-
}
162-
httpClient := &http.Client{Transport: transport, Timeout: timeout}
163-
start := time.Now()
164-
resp, err := httpClient.Get(targetURL)
165-
if err != nil {
166-
return -1, fmt.Sprintf("failed_http: %v", err)
167-
}
168-
defer resp.Body.Close()
169-
if resp.StatusCode != http.StatusNoContent {
170-
return -1, fmt.Sprintf("bad_status_%d", resp.StatusCode)
151+
const maxRetries = 3
152+
const retryDelay = 200 * time.Millisecond
153+
var lastError string
154+
155+
for attempt := 1; attempt <= maxRetries; attempt++ {
156+
targetURL := "http://www.google.com/generate_204"
157+
timeout := 5 * time.Second
158+
159+
dialer, err := proxy.SOCKS5("tcp", fmt.Sprintf("%s:%d", listenIP, port), nil, proxy.Direct)
160+
if err != nil {
161+
return -1, fmt.Sprintf("failed_dialer: %v", err)
162+
}
163+
164+
transport := &http.Transport{
165+
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
166+
return dialer.Dial(network, addr)
167+
},
168+
}
169+
httpClient := &http.Client{Transport: transport, Timeout: timeout}
170+
171+
start := time.Now()
172+
resp, err := httpClient.Get(targetURL)
173+
174+
if err != nil {
175+
lastError = fmt.Sprintf("failed_http: %v (attempt %d/%d)", err, attempt, maxRetries)
176+
time.Sleep(retryDelay)
177+
continue
178+
}
179+
180+
defer resp.Body.Close()
181+
182+
if resp.StatusCode != http.StatusNoContent {
183+
lastError = fmt.Sprintf("bad_status_%d (attempt %d/%d)", resp.StatusCode, attempt, maxRetries)
184+
time.Sleep(retryDelay)
185+
continue
186+
}
187+
188+
return time.Since(start).Milliseconds(), "success"
171189
}
172-
return time.Since(start).Milliseconds(), "success"
190+
191+
return -1, lastError
173192
}

0 commit comments

Comments
 (0)