Skip to content

Commit e6fa052

Browse files
committed
Implement atomic progress tracking and simplify test func
1 parent d7f5a50 commit e6fa052

2 files changed

Lines changed: 22 additions & 26 deletions

File tree

soaxreport/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The SOAX configuration file should be a JSON file with the following structure:
2626
}
2727
```
2828

29-
**Country List (`countries.txt`)**
29+
**Country List (`countries.csv`)**
3030

3131
The countries file should be a CSV file containing country names and their 2-letter ISO codes. Lines starting with `#` are ignored.
3232

@@ -45,7 +45,7 @@ You can download a complete list of country codes from [here](https://raw.github
4545
To run the tool, use the `go run` command from the project root directory:
4646

4747
```sh
48-
go run ./soaxreport --countries workspace/countries.txt --targetDomain www.google.com
48+
go run ./soaxreport --countries workspace/countries.csv --targetDomain www.google.com
4949
```
5050

5151
This will:

soaxreport/main.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)