ProbeSNIs runs ProbeSNI for every sni in the slice concurrently bounded by cfg.Concurrency. Results are returned in the same order as input.
(ctx context.Context, snis []string, cfg ProbeConfig, onResult func(Result))
| 158 | // ProbeSNIs runs ProbeSNI for every sni in the slice concurrently bounded |
| 159 | // by cfg.Concurrency. Results are returned in the same order as input. |
| 160 | func ProbeSNIs(ctx context.Context, snis []string, cfg ProbeConfig, onResult func(Result)) []Result { |
| 161 | cfg.defaults() |
| 162 | sem := make(chan struct{}, cfg.Concurrency) |
| 163 | results := make([]Result, len(snis)) |
| 164 | var wg sync.WaitGroup |
| 165 | for i, sni := range snis { |
| 166 | i, sni := i, sni |
| 167 | wg.Add(1) |
| 168 | sem <- struct{}{} |
| 169 | go func() { |
| 170 | defer wg.Done() |
| 171 | defer func() { <-sem }() |
| 172 | r := ProbeSNI(ctx, sni, cfg) |
| 173 | results[i] = r |
| 174 | if onResult != nil { |
| 175 | onResult(r) |
| 176 | } |
| 177 | }() |
| 178 | } |
| 179 | wg.Wait() |
| 180 | return results |
| 181 | } |
| 182 | |
| 183 | // classifyDialErr maps net.Dialer errors into the Outcome taxonomy. |
| 184 | func classifyDialErr(err error) (Outcome, string) { |