Skip to content

Commit

Permalink
refactor(enginenetx): make beacons API private (#1303)
Browse files Browse the repository at this point in the history
Now that we've more or less reached the point where we wanted to be with
ooni/probe#2531, let's spend some time to
refactor the implementation, now that we know very well how to works,
such that modifying it in the future would be easier.

The first order of business here seems to hide implementation details
and get rid of too many HTTPSDialer prefixes which only cause confusion
when looking at the available structs.
  • Loading branch information
bassosimone authored Sep 26, 2023
1 parent c1a367c commit 1be13d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions internal/enginenetx/beacons.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
"time"
)

// BeaconsPolicy is a policy where we use beacons for communicating
// beaconsPolicy is a policy where we use beacons for communicating
// with the OONI backend, i.e., api.ooni.io.
//
// A beacon 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.
type BeaconsPolicy struct {
type beaconsPolicy struct {
// Fallback is the MANDATORY fallback policy.
Fallback HTTPSDialerPolicy
}

var _ HTTPSDialerPolicy = &BeaconsPolicy{}
var _ HTTPSDialerPolicy = &beaconsPolicy{}

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

go func() {
Expand All @@ -47,7 +47,7 @@ func (p *BeaconsPolicy) LookupTactics(ctx context.Context, domain, port string)
return out
}

func (p *BeaconsPolicy) tacticsForDomain(domain, port string) <-chan *HTTPSDialerTactic {
func (p *beaconsPolicy) tacticsForDomain(domain, port string) <-chan *HTTPSDialerTactic {
out := make(chan *HTTPSDialerTactic)

go func() {
Expand Down Expand Up @@ -81,14 +81,14 @@ func (p *BeaconsPolicy) tacticsForDomain(domain, port string) <-chan *HTTPSDiale
return out
}

func (p *BeaconsPolicy) beaconsAddrs() (out []string) {
func (p *beaconsPolicy) beaconsAddrs() (out []string) {
return append(
out,
"162.55.247.208",
)
}

func (p *BeaconsPolicy) beaconsDomains() (out []string) {
func (p *beaconsPolicy) beaconsDomains() (out []string) {
// See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40273
return append(
out,
Expand Down
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 @@ import (
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{
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
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{
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
Expand Down Expand Up @@ -83,7 +83,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{
policy := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{
Logger: model.DiscardLogger,
Resolver: &mocks.Resolver{
Expand Down
2 changes: 1 addition & 1 deletion internal/enginenetx/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func NewNetwork(
// newHTTPSDialerPolicy contains the logic to select the [HTTPSDialerPolicy] to use.
func newHTTPSDialerPolicy(kvStore model.KeyValueStore, logger model.Logger, resolver model.Resolver) HTTPSDialerPolicy {
// create a composed fallback TLS dialer policy
fallback := &BeaconsPolicy{
fallback := &beaconsPolicy{
Fallback: &HTTPSDialerNullPolicy{logger, resolver},
}

Expand Down

0 comments on commit 1be13d0

Please sign in to comment.