Skip to content

Commit

Permalink
refactor(enginenetx): make dns-policy API private (ooni#1309)
Browse files Browse the repository at this point in the history
The dns-policy API is the API where we use the DNS to generate tactics
for dialing. Now we have made it private.

Also, we have renamed files. Most of this package is related to HTTPS
dialing anyway, so we don't need to be that obsessive and add the
HTTPSDialer / httpsdialer prefix everywhere.

While there, also hide and move the "null" stats tracker, which is
clearly a private implementation detail.

Part of ooni/probe#2531
  • Loading branch information
bassosimone authored and Murphy-OrangeMud committed Feb 13, 2024
1 parent f6b3843 commit 06820c9
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 196 deletions.
6 changes: 3 additions & 3 deletions internal/enginenetx/beacons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestBeaconsPolicy(t *testing.T) {
t.Run("for domains for which we don't have beacons and DNS failure", func(t *testing.T) {
expected := errors.New("mocked error")
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Fallback: &dnsPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
Expand All @@ -38,7 +38,7 @@ func TestBeaconsPolicy(t *testing.T) {

t.Run("for domains for which we don't have beacons and DNS success", func(t *testing.T) {
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Fallback: &dnsPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestBeaconsPolicy(t *testing.T) {
t.Run("for the api.ooni.io domain", func(t *testing.T) {
expected := errors.New("mocked error")
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Fallback: &dnsPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package enginenetx

//
// HTTPS dialing policy where we generate tactics in the usual way
// by using a DNS resolver and using SNI == VerifyHostname
//

import (
"context"

"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)

// HTTPSDialerNullPolicy is the default "null" policy where we use the
// dnsPolicy is the default TLS dialing policy where we use the
// given resolver and the domain as the SNI.
//
// The zero value is invalid; please, init all MANDATORY fields.
//
// We say that this is the "null" policy because this is what you would get
// by default if you were not using any policy.
//
// This policy uses an Happy-Eyeballs-like algorithm. Dial attempts are
// staggered by httpsDialerHappyEyeballsDelay.
type HTTPSDialerNullPolicy struct {
// This policy uses an Happy-Eyeballs-like algorithm.
type dnsPolicy struct {
// Logger is the MANDATORY logger.
Logger model.Logger

// Resolver is the MANDATORY resolver.
Resolver model.Resolver
}

var _ HTTPSDialerPolicy = &HTTPSDialerNullPolicy{}
var _ HTTPSDialerPolicy = &dnsPolicy{}

// LookupTactics implements HTTPSDialerPolicy.
func (p *HTTPSDialerNullPolicy) LookupTactics(
func (p *dnsPolicy) LookupTactics(
ctx context.Context, domain, port string) <-chan *HTTPSDialerTactic {
out := make(chan *HTTPSDialerTactic)

Expand Down Expand Up @@ -67,33 +68,3 @@ func (p *HTTPSDialerNullPolicy) LookupTactics(

return out
}

// HTTPSDialerNullStatsTracker is the "null" [HTTPSDialerStatsTracker].
type HTTPSDialerNullStatsTracker struct{}

var _ HTTPSDialerStatsTracker = &HTTPSDialerNullStatsTracker{}

// OnStarting implements HTTPSDialerStatsTracker.
func (*HTTPSDialerNullStatsTracker) OnStarting(tactic *HTTPSDialerTactic) {
// nothing
}

// OnSuccess implements HTTPSDialerStatsTracker.
func (*HTTPSDialerNullStatsTracker) OnSuccess(tactic *HTTPSDialerTactic) {
// nothing
}

// OnTCPConnectError implements HTTPSDialerStatsTracker.
func (*HTTPSDialerNullStatsTracker) OnTCPConnectError(ctx context.Context, tactic *HTTPSDialerTactic, err error) {
// nothing
}

// OnTLSHandshakeError implements HTTPSDialerStatsTracker.
func (*HTTPSDialerNullStatsTracker) OnTLSHandshakeError(ctx context.Context, tactic *HTTPSDialerTactic, err error) {
// nothing
}

// OnTLSVerifyError implements HTTPSDialerStatsTracker.
func (*HTTPSDialerNullStatsTracker) OnTLSVerifyError(tactic *HTTPSDialerTactic, err error) {
// nothing
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestHTTPSDialerNullPolicy(t *testing.T) {
t.Run("LookupTactics with canceled context", func(t *testing.T) {
var called int

policy := &HTTPSDialerNullPolicy{
policy := &dnsPolicy{
Logger: &mocks.Logger{
MockDebugf: func(format string, v ...interface{}) {
called++
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestHTTPSDialerNullPolicy(t *testing.T) {
})

t.Run("we short circuit IP addresses", func(t *testing.T) {
policy := &HTTPSDialerNullPolicy{
policy := &dnsPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{}, // empty so we crash if we hit the resolver
}
Expand Down
File renamed without changes.
117 changes: 0 additions & 117 deletions internal/enginenetx/httpsdialer_internal_test.go

This file was deleted.

Loading

0 comments on commit 06820c9

Please sign in to comment.