Skip to content

Commit

Permalink
refactor: rename sessionresolver engineresolver (#1264)
Browse files Browse the repository at this point in the history
I am soon going to start addressing the underlying issue described by
ooni/probe#2531.

But, before doing that, I have noticed that the packages I need to edit
to this end are the following:

```
./internal/engine
./internal/geolocate
./internal/sessionresolver
```

Now, these three packages work in unison to provide an `engine.Session`
and they should *sort* together. However, I would like also to avoid
nesting because I think each of them serves an ~independent purpose, and
geolocate and sessionresolver are possibly building blocks to refactor
or reimplement the engine.

For this reason, I have chosen to rename them such that it is clear they
are the engine and supporting packages.

This diff addresses the second half of the change by renaming the
sessionresolver package.
bassosimone authored Sep 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8c0646a commit 761e79e
Showing 17 changed files with 27 additions and 24 deletions.
10 changes: 5 additions & 5 deletions internal/engine/session.go
Original file line number Diff line number Diff line change
@@ -14,14 +14,14 @@ import (
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/checkincache"
"github.com/ooni/probe-cli/v3/internal/enginelocate"
"github.com/ooni/probe-cli/v3/internal/engineresolver"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/platform"
"github.com/ooni/probe-cli/v3/internal/probeservices"
"github.com/ooni/probe-cli/v3/internal/registry"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/sessionresolver"
"github.com/ooni/probe-cli/v3/internal/tunnel"
"github.com/ooni/probe-cli/v3/internal/version"
)
@@ -64,7 +64,7 @@ type Session struct {
logger model.Logger
proxyURL *url.URL
queryProbeServicesCount *atomic.Int64
resolver *sessionresolver.Resolver
resolver *engineresolver.Resolver
selectedProbeServiceHook func(*model.OOAPIService)
selectedProbeService *model.OOAPIService
softwareName string
@@ -132,8 +132,8 @@ type sessionProbeServicesClientForCheckIn interface {
//
// 5. Create a compound resolver for the session that will attempt
// to use a bunch of DoT/DoH servers before falling back to the system
// resolver if nothing else works (see the sessionresolver pkg). This
// sessionresolver will be using the configured proxy, if any.
// resolver if nothing else works (see the engineresolver pkg). This
// engineresolver will be using the configured proxy, if any.
//
// 6. Create the default HTTP transport that we should be using when
// we communicate with the OONI backends. This transport will be
@@ -208,7 +208,7 @@ func NewSession(ctx context.Context, config SessionConfig) (*Session, error) {
}
}
sess.proxyURL = proxyURL
sess.resolver = &sessionresolver.Resolver{
sess.resolver = &engineresolver.Resolver{
ByteCounter: sess.byteCounter,
KVStore: config.KVStore,
Logger: sess.logger,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package sessionresolver contains the resolver used by the session. This
// Package engineresolver contains the resolver used by the OONI engine. This
// resolver will try to figure out which is the best service for running
// domain name resolutions and will consistently use it.
//
@@ -21,4 +21,4 @@
// We also support a socks5 proxy. When such a proxy is configured,
// the code WILL skip http3 resolvers AS WELL AS the system
// resolver, in an attempt to avoid leaking your queries.
package sessionresolver
package engineresolver
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// Error wrapping
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"errors"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"errors"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"context"
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package sessionresolver_test
package engineresolver_test

import (
"context"
"testing"

"github.com/ooni/probe-cli/v3/internal/engineresolver"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/sessionresolver"
)

func TestSessionResolverGood(t *testing.T) {
if testing.Short() {
t.Skip("skip test in short mode")
}
reso := &sessionresolver.Resolver{
reso := &engineresolver.Resolver{
KVStore: &kvstore.Memory{},
}
defer reso.CloseIdleConnections()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// JSON codec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"testing"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// Actual lookup code
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"context"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// Implementation of model.Resolver
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"context"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// High-level code for creating a new child resolver
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"strings"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

//
// Persistent on-disk state
@@ -9,6 +9,9 @@ import (
"sort"
)

// TODO(bassosimone): we may want to change the key and rename or
// remove the old file inside the statedir

// storekey is the key used by the key value store to store
// the state required by this package.
const storekey = "sessionresolver.state"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sessionresolver
package engineresolver

import (
"errors"

0 comments on commit 761e79e

Please sign in to comment.