From 761e79e21fd4c04bb6585755c2394db8ef140b92 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 14 Sep 2023 11:15:46 +0200 Subject: [PATCH] refactor: rename sessionresolver engineresolver (#1264) I am soon going to start addressing the underlying issue described by https://github.com/ooni/probe/issues/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. --- internal/engine/session.go | 10 +++++----- internal/{sessionresolver => engineresolver}/doc.go | 4 ++-- .../{sessionresolver => engineresolver}/errwrapper.go | 2 +- .../errwrapper_test.go | 2 +- .../{sessionresolver => engineresolver}/factory.go | 2 +- .../factory_test.go | 2 +- .../integration_test.go | 6 +++--- .../{sessionresolver => engineresolver}/jsoncodec.go | 2 +- .../jsoncodec_test.go | 2 +- internal/{sessionresolver => engineresolver}/lookup.go | 2 +- .../{sessionresolver => engineresolver}/lookup_test.go | 2 +- .../{sessionresolver => engineresolver}/resolver.go | 2 +- .../resolver_test.go | 2 +- .../resolvermaker.go | 2 +- .../resolvermaker_test.go | 2 +- internal/{sessionresolver => engineresolver}/state.go | 5 ++++- .../{sessionresolver => engineresolver}/state_test.go | 2 +- 17 files changed, 27 insertions(+), 24 deletions(-) rename internal/{sessionresolver => engineresolver}/doc.go (91%) rename internal/{sessionresolver => engineresolver}/errwrapper.go (96%) rename internal/{sessionresolver => engineresolver}/errwrapper_test.go (94%) rename internal/{sessionresolver => engineresolver}/factory.go (99%) rename internal/{sessionresolver => engineresolver}/factory_test.go (99%) rename internal/{sessionresolver => engineresolver}/integration_test.go (82%) rename internal/{sessionresolver => engineresolver}/jsoncodec.go (97%) rename internal/{sessionresolver => engineresolver}/jsoncodec_test.go (97%) rename internal/{sessionresolver => engineresolver}/lookup.go (98%) rename internal/{sessionresolver => engineresolver}/lookup_test.go (97%) rename internal/{sessionresolver => engineresolver}/resolver.go (99%) rename internal/{sessionresolver => engineresolver}/resolver_test.go (99%) rename internal/{sessionresolver => engineresolver}/resolvermaker.go (99%) rename internal/{sessionresolver => engineresolver}/resolvermaker_test.go (99%) rename internal/{sessionresolver => engineresolver}/state.go (94%) rename internal/{sessionresolver => engineresolver}/state_test.go (99%) diff --git a/internal/engine/session.go b/internal/engine/session.go index 423369c5a0..014ae90508 100644 --- a/internal/engine/session.go +++ b/internal/engine/session.go @@ -14,6 +14,7 @@ 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" @@ -21,7 +22,6 @@ import ( "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, diff --git a/internal/sessionresolver/doc.go b/internal/engineresolver/doc.go similarity index 91% rename from internal/sessionresolver/doc.go rename to internal/engineresolver/doc.go index 266312bb28..a1681fc640 100644 --- a/internal/sessionresolver/doc.go +++ b/internal/engineresolver/doc.go @@ -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 diff --git a/internal/sessionresolver/errwrapper.go b/internal/engineresolver/errwrapper.go similarity index 96% rename from internal/sessionresolver/errwrapper.go rename to internal/engineresolver/errwrapper.go index 8f43a6640a..f5e2f24bde 100644 --- a/internal/sessionresolver/errwrapper.go +++ b/internal/engineresolver/errwrapper.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver // // Error wrapping diff --git a/internal/sessionresolver/errwrapper_test.go b/internal/engineresolver/errwrapper_test.go similarity index 94% rename from internal/sessionresolver/errwrapper_test.go rename to internal/engineresolver/errwrapper_test.go index 1db791e5d2..3b99f7084f 100644 --- a/internal/sessionresolver/errwrapper_test.go +++ b/internal/engineresolver/errwrapper_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "errors" diff --git a/internal/sessionresolver/factory.go b/internal/engineresolver/factory.go similarity index 99% rename from internal/sessionresolver/factory.go rename to internal/engineresolver/factory.go index 2b7cc3c12c..125b13c08c 100644 --- a/internal/sessionresolver/factory.go +++ b/internal/engineresolver/factory.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "errors" diff --git a/internal/sessionresolver/factory_test.go b/internal/engineresolver/factory_test.go similarity index 99% rename from internal/sessionresolver/factory_test.go rename to internal/engineresolver/factory_test.go index 3cfb0b4b67..c0d1c709b6 100644 --- a/internal/sessionresolver/factory_test.go +++ b/internal/engineresolver/factory_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "context" diff --git a/internal/sessionresolver/integration_test.go b/internal/engineresolver/integration_test.go similarity index 82% rename from internal/sessionresolver/integration_test.go rename to internal/engineresolver/integration_test.go index 0b4231b680..798c60ce2c 100644 --- a/internal/sessionresolver/integration_test.go +++ b/internal/engineresolver/integration_test.go @@ -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() diff --git a/internal/sessionresolver/jsoncodec.go b/internal/engineresolver/jsoncodec.go similarity index 97% rename from internal/sessionresolver/jsoncodec.go rename to internal/engineresolver/jsoncodec.go index d884204961..f618464747 100644 --- a/internal/sessionresolver/jsoncodec.go +++ b/internal/engineresolver/jsoncodec.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver // // JSON codec diff --git a/internal/sessionresolver/jsoncodec_test.go b/internal/engineresolver/jsoncodec_test.go similarity index 97% rename from internal/sessionresolver/jsoncodec_test.go rename to internal/engineresolver/jsoncodec_test.go index 77d90c08c0..f1436671dd 100644 --- a/internal/sessionresolver/jsoncodec_test.go +++ b/internal/engineresolver/jsoncodec_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "testing" diff --git a/internal/sessionresolver/lookup.go b/internal/engineresolver/lookup.go similarity index 98% rename from internal/sessionresolver/lookup.go rename to internal/engineresolver/lookup.go index 4fad123db1..adc3909e6b 100644 --- a/internal/sessionresolver/lookup.go +++ b/internal/engineresolver/lookup.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver // // Actual lookup code diff --git a/internal/sessionresolver/lookup_test.go b/internal/engineresolver/lookup_test.go similarity index 97% rename from internal/sessionresolver/lookup_test.go rename to internal/engineresolver/lookup_test.go index 2895eeaa75..5bb5daa0a5 100644 --- a/internal/sessionresolver/lookup_test.go +++ b/internal/engineresolver/lookup_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "context" diff --git a/internal/sessionresolver/resolver.go b/internal/engineresolver/resolver.go similarity index 99% rename from internal/sessionresolver/resolver.go rename to internal/engineresolver/resolver.go index 5a249d3a76..4647061d70 100644 --- a/internal/sessionresolver/resolver.go +++ b/internal/engineresolver/resolver.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver // // Implementation of model.Resolver diff --git a/internal/sessionresolver/resolver_test.go b/internal/engineresolver/resolver_test.go similarity index 99% rename from internal/sessionresolver/resolver_test.go rename to internal/engineresolver/resolver_test.go index 74fc2c23aa..5565dfc138 100644 --- a/internal/sessionresolver/resolver_test.go +++ b/internal/engineresolver/resolver_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "context" diff --git a/internal/sessionresolver/resolvermaker.go b/internal/engineresolver/resolvermaker.go similarity index 99% rename from internal/sessionresolver/resolvermaker.go rename to internal/engineresolver/resolvermaker.go index db337fec95..6f5fe363bd 100644 --- a/internal/sessionresolver/resolvermaker.go +++ b/internal/engineresolver/resolvermaker.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver // // High-level code for creating a new child resolver diff --git a/internal/sessionresolver/resolvermaker_test.go b/internal/engineresolver/resolvermaker_test.go similarity index 99% rename from internal/sessionresolver/resolvermaker_test.go rename to internal/engineresolver/resolvermaker_test.go index 847bfcaf4f..9889c0f977 100644 --- a/internal/sessionresolver/resolvermaker_test.go +++ b/internal/engineresolver/resolvermaker_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "strings" diff --git a/internal/sessionresolver/state.go b/internal/engineresolver/state.go similarity index 94% rename from internal/sessionresolver/state.go rename to internal/engineresolver/state.go index 513c320add..70524d2282 100644 --- a/internal/sessionresolver/state.go +++ b/internal/engineresolver/state.go @@ -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" diff --git a/internal/sessionresolver/state_test.go b/internal/engineresolver/state_test.go similarity index 99% rename from internal/sessionresolver/state_test.go rename to internal/engineresolver/state_test.go index 0ac1a784ee..526710ac04 100644 --- a/internal/sessionresolver/state_test.go +++ b/internal/engineresolver/state_test.go @@ -1,4 +1,4 @@ -package sessionresolver +package engineresolver import ( "errors"