Skip to content

Commit

Permalink
fix(enginenetx): give priority to DNS (#1592)
Browse files Browse the repository at this point in the history
This implements the changes requested in
#1552. We rearrange the chains
such that the DNS has priority and extended policies come after it. Part
of ooni/probe#2704.

---------

Co-authored-by: Arturo Filastò <[email protected]>
  • Loading branch information
bassosimone and hellais authored May 9, 2024
1 parent 79895e0 commit 17e74f4
Show file tree
Hide file tree
Showing 2 changed files with 482 additions and 48 deletions.
43 changes: 35 additions & 8 deletions internal/enginenetx/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func NewNetwork(
// Note that:
//
// - we're enabling compression, which is desiredable since this transport
// is not made for measuring and compression is good(TM);
// is not made for measuring and compression is good(TM), also note that
// when the request uses Accept-Encoding, this kind of automatic management
// of compression is disabled, so there is no conflict.
//
// - if proxyURL is nil, the proxy option is equivalent to disabling
// the proxy, otherwise it means that we're using the ooni/oohttp library
Expand Down Expand Up @@ -152,16 +154,41 @@ func newHTTPSDialerPolicy(
return &dnsPolicy{logger, resolver}
}

// create a composed fallback TLS dialer policy
fallback := &statsPolicy{
Fallback: &bridgesPolicy{Fallback: &dnsPolicy{logger, resolver}},
Stats: stats,
// create a policy interleaving stats policies and bridges policies
statsOrBridges := &mixPolicyInterleave{
Primary: &statsPolicyV2{
Stats: stats,
},
Fallback: &bridgesPolicyV2{},
Factor: 3,
}

// make sure we honor a user-provided policy
policy, err := newUserPolicy(kvStore, fallback)
// wrap the DNS policy with a policy that extends tactics for test
// helpers so that we also try using different SNIs.
dnsExt := &testHelpersPolicy{
Child: &dnsPolicy{logger, resolver},
}

// compose dnsExt and statsOrBridges such that dnsExt has
// priority in the selection of tactics
composed := &mixPolicyInterleave{
Primary: dnsExt,
Fallback: statsOrBridges,
Factor: 3,
}

// attempt to load a user-provided dialing policy
primary, err := newUserPolicyV2(kvStore)

// on error, just use composed
if err != nil {
return fallback
return composed
}

// otherwise, finish creating the dialing policy
policy := &mixPolicyEitherOr{
Primary: primary,
Fallback: composed,
}

return policy
Expand Down
Loading

0 comments on commit 17e74f4

Please sign in to comment.