@@ -25,6 +25,7 @@ import (
2525 "strconv"
2626 "strings"
2727 "sync"
28+ "sync/atomic"
2829 "time"
2930
3031 "github.com/Jigsaw-Code/ech-research/internal/curl"
@@ -171,7 +172,7 @@ func main() {
171172 verboseFlag = flag .Bool ("verbose" , false , "Enable verbose logging" )
172173 maxTimeFlag = flag .Duration ("maxTime" , 30 * time .Second , "Maximum time per curl request" )
173174 curlPathFlag = flag .String ("curl" , "" , "Path to the ECH-enabled curl binary" )
174- parallelismFlag = flag .Int ("parallelism" , 10 , "Maximum number of parallel requests" )
175+ parallelismFlag = flag .Int ("parallelism" , 16 , "Maximum number of parallel requests" )
175176 )
176177 flag .Parse ()
177178
@@ -263,6 +264,8 @@ func main() {
263264 runSessionID := time .Now ().Format ("0102150405" )
264265 sem := semaphore .NewWeighted (int64 (* parallelismFlag ))
265266 var wg sync.WaitGroup
267+ var total , finished atomic.Int32
268+
266269 for _ , country := range countries {
267270 slog .Debug ("Processing country" , "name" , country .Name , "code" , country .Code )
268271
@@ -272,35 +275,28 @@ func main() {
272275 continue
273276 }
274277
278+ total .Add (int32 (len (isps ) * 2 ))
275279 for i , isp := range isps {
276280 wg .Add (2 )
277281 sessionID := fmt .Sprintf ("%s%s%d" , runSessionID , country .Code , i )
278282
279- if err := sem .Acquire (context .Background (), 1 ); err != nil {
280- slog .Error ("Failed to acquire semaphore" , "error" , err )
281- wg .Done ()
282- } else {
283- go func (c Country , isp , sid string ) {
284- defer sem .Release (1 )
285- defer wg .Done ()
286- proxyURL := client .BuildProxyURL (c .Code , isp , sid )
287- slog .Info ("Testing ISP" , "country" , c .Code , "isp" , isp , "ech_grease" , false , "session" , sid )
288- resultsCh <- runSoaxTest (runner , domain , c .Code , c .Name , isp , proxyURL , false , * maxTimeFlag )
289- }(country , isp , sessionID )
283+ startTest := func (c Country , isp , sid string , ech bool ) {
284+ defer wg .Done ()
285+ if err := sem .Acquire (context .Background (), 1 ); err != nil {
286+ slog .Error ("Failed to acquire semaphore" , "error" , err )
287+ return
288+ }
289+ defer sem .Release (1 )
290+
291+ proxyURL := client .BuildProxyURL (c .Code , isp , sid )
292+ slog .Debug ("Testing ISP" , "country" , c .Code , "isp" , isp , "ech_grease" , ech , "session" , sid )
293+ resultsCh <- runSoaxTest (runner , domain , c .Code , c .Name , isp , proxyURL , ech , * maxTimeFlag )
294+ progress := fmt .Sprintf ("%d/%d" , finished .Add (1 ), total .Load ())
295+ slog .Info ("Finished" , "country" , c .Code , "isp" , isp , "progress" , progress )
290296 }
291297
292- if err := sem .Acquire (context .Background (), 1 ); err != nil {
293- slog .Error ("Failed to acquire semaphore" , "error" , err )
294- wg .Done ()
295- } else {
296- go func (c Country , isp , sid string ) {
297- defer sem .Release (1 )
298- defer wg .Done ()
299- proxyURL := client .BuildProxyURL (c .Code , isp , sid )
300- slog .Info ("Testing ISP" , "country" , c .Code , "isp" , isp , "ech_grease" , true , "session" , sid )
301- resultsCh <- runSoaxTest (runner , domain , c .Code , c .Name , isp , proxyURL , true , * maxTimeFlag )
302- }(country , isp , sessionID )
303- }
298+ go startTest (country , isp , sessionID , false )
299+ go startTest (country , isp , sessionID , true )
304300 }
305301 }
306302
0 commit comments