Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(enginenetx): split generation and mixing #1591

Merged
merged 146 commits into from
May 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
80b5e1f
doc(enginenetx): improve documentation
bassosimone Apr 15, 2024
62c3917
fix(enginenetx): mix bridges and DNS tactics
bassosimone Apr 15, 2024
0d2b0f2
fix: update test name and add comment
bassosimone Apr 15, 2024
aee17cf
feat: test for the mixed policies case
bassosimone Apr 15, 2024
7576fc7
feat(enginenetx): add support for filtering tactics
bassosimone Apr 15, 2024
8120c06
refactor: rename function
bassosimone Apr 15, 2024
3207255
feat: improve TCP connect statistics
bassosimone Apr 15, 2024
5618b72
fix previous
bassosimone Apr 15, 2024
2153e36
feat: start to prepare for filtering endpoints
bassosimone Apr 16, 2024
e5cdbb0
ongoing work while documenting and clarifying
bassosimone Apr 16, 2024
089f70b
x
bassosimone Apr 16, 2024
20e71e8
[ci skip]
bassosimone Apr 16, 2024
b5b2e49
[ci skip]
bassosimone Apr 16, 2024
94eb284
[ci skip]
bassosimone Apr 16, 2024
90601c6
[ci skip]
bassosimone Apr 16, 2024
ef8fdfe
[ci skip]
bassosimone Apr 16, 2024
aa65cb7
[ci skip]
bassosimone Apr 16, 2024
28a6265
[ci skip]
bassosimone Apr 16, 2024
f452208
[ci skip]
bassosimone Apr 16, 2024
119e610
[ci skip]
bassosimone Apr 16, 2024
f3fb1dd
[ci skip]
bassosimone Apr 16, 2024
ce6ec84
[ci skip]
bassosimone Apr 16, 2024
4f63b60
[ci skip]
bassosimone Apr 16, 2024
45e655c
x
bassosimone Apr 16, 2024
8e2a1f3
x
bassosimone Apr 16, 2024
e2aed07
x
bassosimone Apr 16, 2024
08fbf48
[ci skip]
bassosimone Apr 16, 2024
7c6ab4b
[ci skip]
bassosimone Apr 16, 2024
c843241
[ci skip]
bassosimone Apr 16, 2024
7f16577
[ci skip]
bassosimone Apr 16, 2024
4b0c768
[ci skip]
bassosimone Apr 16, 2024
7ea130d
[ci skip]
bassosimone Apr 16, 2024
1cbc109
[ci skip]
bassosimone Apr 16, 2024
7edfbb8
[ci skip]
bassosimone Apr 16, 2024
21f9b90
[ci skip]
bassosimone Apr 16, 2024
8e5fee9
[ci skip]
bassosimone Apr 16, 2024
4f8cf91
[ci skip]
bassosimone Apr 16, 2024
436fb50
[ci skip]
bassosimone Apr 16, 2024
b6aebc2
[ci skip]
bassosimone Apr 16, 2024
77b03bd
[ci skip]
bassosimone Apr 16, 2024
f565e68
[ci skip]
bassosimone Apr 16, 2024
e9eee04
[ci skip]
bassosimone Apr 16, 2024
393968d
[ci skip]
bassosimone Apr 16, 2024
665b961
[ci skip]
bassosimone Apr 16, 2024
fb651c7
[ci skip]
bassosimone Apr 16, 2024
cb0dbfc
[ci skip]
bassosimone Apr 16, 2024
bfc0a1d
[ci skip]
bassosimone Apr 16, 2024
02660de
[ci skip]
bassosimone Apr 16, 2024
f707616
[ci skip]
bassosimone Apr 16, 2024
492ab69
[ci skip]
bassosimone Apr 16, 2024
3b63fbd
[ci skip]
bassosimone Apr 16, 2024
0c06b53
[ci skip]
bassosimone Apr 16, 2024
8691606
[ci skip]
bassosimone Apr 16, 2024
20f800a
[ci skip]
bassosimone Apr 16, 2024
e02c5d4
[ci skip]
bassosimone Apr 16, 2024
dd128d8
[ci skip]
bassosimone Apr 16, 2024
8c5bc60
[ci skip]
bassosimone Apr 16, 2024
6e47258
[ci skip]
bassosimone Apr 16, 2024
018fec4
[ci skip]
bassosimone Apr 16, 2024
c834599
[ci skip]
bassosimone Apr 16, 2024
ccd26c4
[ci skip]
bassosimone Apr 16, 2024
0b32b47
[ci skip]
bassosimone Apr 16, 2024
6066a7f
[ci skip]
bassosimone Apr 16, 2024
6c83c25
[ci skip]
bassosimone Apr 16, 2024
19fc4b5
[ci skip]
bassosimone Apr 16, 2024
856d261
[ci skip]
bassosimone Apr 16, 2024
2b7a881
[ci skip]
bassosimone Apr 16, 2024
b7327e2
[ci skip]
bassosimone Apr 16, 2024
3399fec
[ci skip]
bassosimone Apr 16, 2024
baef14f
[ci skip]
bassosimone Apr 16, 2024
15d28f2
[ci skip]
bassosimone Apr 16, 2024
0baaf9b
[ci skip]
bassosimone Apr 16, 2024
49bbf25
[ci skip]
bassosimone Apr 16, 2024
d739ddd
[ci skip]
bassosimone Apr 16, 2024
4896f68
[ci skip]
bassosimone Apr 16, 2024
8bdbbaf
x
bassosimone Apr 16, 2024
4e3a8af
the design document should now be good
bassosimone Apr 16, 2024
fd81cf7
x
bassosimone Apr 16, 2024
8a93533
x
bassosimone Apr 16, 2024
2949035
remove more code that we probably don't need
bassosimone Apr 16, 2024
c075625
[ci skip]
bassosimone Apr 17, 2024
8d14587
[ci skip]
bassosimone Apr 17, 2024
7a2a360
[ci skip]
bassosimone Apr 17, 2024
dfed510
[ci skip]
bassosimone Apr 17, 2024
be41fa9
[ci skip]
bassosimone Apr 17, 2024
5f7302a
[ci skip]
bassosimone Apr 17, 2024
7443710
[ci skip]
bassosimone Apr 17, 2024
2944ea0
[ci skip]
bassosimone Apr 17, 2024
43c1e7c
[ci skip]
bassosimone Apr 17, 2024
d6159d6
[ci skip]
bassosimone Apr 17, 2024
dcf4a03
[ci skip]
bassosimone Apr 17, 2024
f037eb3
[ci skip]
bassosimone Apr 17, 2024
586c450
[ci skip]
bassosimone Apr 17, 2024
de31fd5
[ci skip]
bassosimone Apr 17, 2024
8a3eef7
[ci skip]
bassosimone Apr 17, 2024
697f6b3
[ci skip]
bassosimone Apr 17, 2024
e652147
[ci skip]
bassosimone Apr 17, 2024
4baca70
[ci skip]
bassosimone Apr 17, 2024
fa1c237
[ci skip]
bassosimone Apr 17, 2024
75eb2df
Merge branch 'master' into issue/2704
bassosimone Apr 17, 2024
fd9c568
Merge branch 'master' into issue/2704
bassosimone Apr 17, 2024
d0f721a
x
bassosimone Apr 17, 2024
7058b7d
x
bassosimone Apr 17, 2024
4e628db
x
bassosimone Apr 17, 2024
3b0e110
x
bassosimone Apr 17, 2024
72e1336
Merge branch 'master' into issue/2704
bassosimone Apr 17, 2024
32178c6
x
bassosimone Apr 17, 2024
e7c7541
x
bassosimone Apr 17, 2024
f16784c
x
bassosimone Apr 17, 2024
28bcd5f
[ci skip]
bassosimone Apr 17, 2024
da06bbb
[ci skip]
bassosimone Apr 17, 2024
67ae4d9
[ci skip]
bassosimone Apr 17, 2024
02ee95d
[ci skip]
bassosimone Apr 17, 2024
3877575
fix: adapt test after remix change
bassosimone Apr 18, 2024
af87c6e
doc: add table of contents
bassosimone Apr 18, 2024
1a50266
doc: rename the goals section to be more clear
bassosimone Apr 18, 2024
139f10c
Update internal/enginenetx/DESIGN.md
bassosimone Apr 26, 2024
1d8a786
Update internal/enginenetx/DESIGN.md
bassosimone Apr 26, 2024
a161fa1
Merge branch 'master' into issue/2704
bassosimone Apr 26, 2024
bffc811
Apply suggestions from @hellais
bassosimone May 7, 2024
e9765df
Merge branch 'master' into issue/2704
bassosimone May 7, 2024
9d2c47f
feat: allow chaining policies after the DNS
bassosimone May 8, 2024
f7509d9
feat: implement the mix-with-interleaving policy
bassosimone May 8, 2024
ab3926e
fix: we actually need to get rid of fallbacks
bassosimone May 8, 2024
d4f60b1
refactor(bridgespolicy.go): use free functions
bassosimone May 8, 2024
b0f88bd
feat: introduce fallback-less v2 policies
bassosimone May 8, 2024
35d667f
Shove all the changes I have together
bassosimone May 8, 2024
2582614
chore: add more debugging info
bassosimone May 9, 2024
957ce1d
x
bassosimone May 9, 2024
e2b02aa
x
bassosimone May 9, 2024
7291b9b
feat: write tests for bridgespolicy
bassosimone May 9, 2024
adf00d0
x
bassosimone May 9, 2024
3b406ff
feat: write tests for mixpolicy
bassosimone May 9, 2024
563f22b
x
bassosimone May 9, 2024
d0727ed
feat: write tests for statsPolicyV2
bassosimone May 9, 2024
124d0f9
x
bassosimone May 9, 2024
e4b1826
x
bassosimone May 9, 2024
8d92599
x
bassosimone May 9, 2024
f28bd50
x
bassosimone May 9, 2024
37f4004
x
bassosimone May 9, 2024
288d500
chore: write tests for userPolicyV2
bassosimone May 9, 2024
8b9856a
x
bassosimone May 9, 2024
3cb8ab5
chore: test the mocks policy
bassosimone May 9, 2024
78fa51f
x
bassosimone May 9, 2024
7f1201c
chore: write tests for test helpers policy
bassosimone May 9, 2024
c6cbc8b
x
bassosimone May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: introduce fallback-less v2 policies
bassosimone committed May 8, 2024
commit b0f88bdfdcf1ba399ae99155453dee8f1a7eb56f
23 changes: 23 additions & 0 deletions internal/enginenetx/bridgespolicy.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,26 @@ func (p *bridgesPolicy) LookupTactics(ctx context.Context, domain, port string)
)
}

// bridgesPolicyV2 is a policy where we use bridges for communicating
// with the OONI backend, i.e., api.ooni.io.
//
// A bridge is an IP address that can route traffic from and to
// the OONI backend and accepts any SNI.
//
// The zero value is invalid; please, init MANDATORY fields.
//
// This is v2 of the bridgesPolicy because the previous implementation
// incorporated mixing logic, while now the mixing happens outside
// of this policy, this giving us much more flexibility.
type bridgesPolicyV2 struct{}

var _ httpsDialerPolicy = &bridgesPolicyV2{}

// LookupTactics implements httpsDialerPolicy.
func (p *bridgesPolicyV2) LookupTactics(ctx context.Context, domain, port string) <-chan *httpsDialerTactic {
return bridgesTacticsForDomain(domain, port)
}

var bridgesPolicyTestHelpersDomains = []string{
"0.th.ooni.org",
"1.th.ooni.org",
@@ -72,6 +92,9 @@ var bridgesPolicyTestHelpersDomains = []string{
"d33d1gs9kpq1c5.cloudfront.net",
}

// TODO(bassosimone): the rewriting of test helper tactics should happen elsewhere
// once we stop using the bridgesPolicy (i.e., version 1)

func maybeRewriteTestHelpersTactics(input <-chan *httpsDialerTactic) <-chan *httpsDialerTactic {
out := make(chan *httpsDialerTactic)

22 changes: 22 additions & 0 deletions internal/enginenetx/statspolicy.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,28 @@ func (p *statsPolicy) LookupTactics(ctx context.Context, domain string, port str
)))
}

// statsPolicyV2 is a policy that schedules tactics already known
// to work based on the previously collected stats.
//
// The zero value of this struct is invalid; please, make sure
// you fill all the fields marked as MANDATORY.
//
// This is v2 of the statsPolicy because the previous implementation
// incorporated mixing logic, while now the mixing happens outside
// of this policy, this giving us much more flexibility.
type statsPolicyV2 struct {
// Stats is the MANDATORY stats manager.
Stats *statsManager
}

var _ httpsDialerPolicy = &statsPolicyV2{}

// LookupTactics implements httpsDialerPolicy.
func (p *statsPolicyV2) LookupTactics(ctx context.Context, domain string, port string) <-chan *httpsDialerTactic {
// avoid emitting nil tactics and duplicate tactics
return streamTacticsFromSlice(statsPolicyFilterStatsTactics(p.Stats.LookupTactics(domain, port)))
}

func statsPolicyFilterStatsTactics(tactics []*statsTactic, good bool) (out []*httpsDialerTactic) {
// when good is false, it means p.Stats.LookupTactics failed
if !good {
78 changes: 78 additions & 0 deletions internal/enginenetx/userpolicy.go
Original file line number Diff line number Diff line change
@@ -123,3 +123,81 @@ func userPolicyRemoveNilEntries(input []*httpsDialerTactic) (output []*httpsDial
}
return
}

// userPolicyV2 is an [httpsDialerPolicy] incorporating verbatim
// a user policy loaded from the engine's key-value store.
//
// This policy is very useful for exploration and experimentation.
//
// This is v2 of the userPolicy because the previous implementation
// incorporated mixing logic, while now the mixing happens outside
// of this policy, this giving us much more flexibility.
type userPolicyV2 struct {
// Root is the root of the user policy loaded from disk.
Root *userPolicyRoot
}

// newUserPolicyV2 attempts to constructs a user policy. The typical error case is the one
// in which there's no httpsDialerUserPolicyKey in the key-value store.
func newUserPolicyV2(kvStore model.KeyValueStore) (*userPolicyV2, error) {
// attempt to read the user policy bytes from the kvstore
data, err := kvStore.Get(userPolicyKey)
if err != nil {
return nil, err
}

// attempt to parse the user policy using human-readable JSON
var root userPolicyRoot
if err := hujsonx.Unmarshal(data, &root); err != nil {
return nil, err
}

// make sure the version is OK
if root.Version != userPolicyVersion {
err := fmt.Errorf(
"%s: %w: expected=%d got=%d",
userPolicyKey,
errUserPolicyWrongVersion,
userPolicyVersion,
root.Version,
)
return nil, err
}

out := &userPolicyV2{Root: &root}
return out, nil
}

var _ httpsDialerPolicy = &userPolicyV2{}

// LookupTactics implements httpsDialerPolicy.
func (ldp *userPolicyV2) LookupTactics(ctx context.Context, domain string, port string) <-chan *httpsDialerTactic {
// create the output channel
out := make(chan *httpsDialerTactic)

go func() {
// make sure we close the output channel
defer close(out)

// check whether an entry exists in the user-provided map, which MAY be nil
// if/when the user has chosen their policy to be as such
tactics, found := ldp.Root.DomainEndpoints[net.JoinHostPort(domain, port)]
if !found {
return
}

// note that we also need to fallback when the tactics contains an empty list
// or a list that only contains nil entries
tactics = userPolicyRemoveNilEntries(tactics)
if len(tactics) <= 0 {
return
}

// emit all the user-configured tactics
for _, tactic := range tactics {
out <- tactic
}
}()

return out
}