-
Notifications
You must be signed in to change notification settings - Fork 15
/
testhelperspolicy.go
71 lines (59 loc) · 1.86 KB
/
testhelperspolicy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package enginenetx
import (
"context"
"slices"
)
// testHelpersDomains is our understanding of TH domains.
var testHelpersDomains = []string{
"0.th.ooni.org",
"1.th.ooni.org",
"2.th.ooni.org",
"3.th.ooni.org",
"d33d1gs9kpq1c5.cloudfront.net",
}
// testHelpersPolicy is a policy where we extend TH related policies
// by adding additional SNIs that it makes sense to try.
//
// The zero value is invalid; please, init MANDATORY fields.
type testHelpersPolicy struct {
// Child is the MANDATORY child policy.
Child httpsDialerPolicy
}
var _ httpsDialerPolicy = &testHelpersPolicy{}
// LookupTactics implements httpsDialerPolicy.
func (p *testHelpersPolicy) LookupTactics(ctx context.Context, domain, port string) <-chan *httpsDialerTactic {
out := make(chan *httpsDialerTactic)
go func() {
// tell the parent when we're done
defer close(out)
// collect tactics that we may want to modify later
var todo []*httpsDialerTactic
// always emit the original tactic first
//
// See https://github.com/ooni/probe-cli/pull/1552 review for
// a rationale of why we're emitting the original first
for tactic := range p.Child.LookupTactics(ctx, domain, port) {
out <- tactic
// When we're not connecting to a TH, our job is done
if !slices.Contains(testHelpersDomains, tactic.VerifyHostname) {
continue
}
// otherwise, let's rememeber to modify this later
todo = append(todo, tactic)
}
// This is the case where we're connecting to a test helper. Let's try
// to produce tactics using different SNIs for the domain.
for _, tactic := range todo {
for _, sni := range bridgesDomainsInRandomOrder() {
out <- &httpsDialerTactic{
Address: tactic.Address,
InitialDelay: 0, // set when dialing
Port: tactic.Port,
SNI: sni,
VerifyHostname: tactic.VerifyHostname,
}
}
}
}()
return out
}