refactor(netxlite): add more functions to resolver (#455)

We would like to refactor the code so that a DoH resolver owns the
connections of its underlying HTTP client.

To do that, we need first to incorporate CloseIdleConnections
into the Resolver model. Then, we need to add the same function
to all netxlite types that wrap a Resolver type.

At the same time, we want the rest of the code for now to continue
with the simpler definition of a Resolver, now called ResolverLegacy.

We will eventually propagate this change to the rest of the tree
and simplify the way in which we manage Resolvers.

To make this possible, we introduce a new factory function that
adapts a ResolverLegacy to become a Resolver.

See https://github.com/ooni/probe/issues/1591.
This commit is contained in:
Simone Basso
2021-09-05 18:03:50 +02:00
committed by GitHub
parent 2e0118d1a6
commit a3654f60b7
22 changed files with 279 additions and 119 deletions
@@ -27,7 +27,7 @@ type Explorer interface {
// DefaultExplorer is the default Explorer.
type DefaultExplorer struct {
resolver netxlite.Resolver
resolver netxlite.ResolverLegacy
}
// Explore returns a list of round trips sorted so that the first
@@ -24,7 +24,7 @@ type Generator interface {
type DefaultGenerator struct {
dialer netxlite.Dialer
quicDialer netxlite.QUICContextDialer
resolver netxlite.Resolver
resolver netxlite.ResolverLegacy
transport http.RoundTripper
}
@@ -31,7 +31,7 @@ type InitChecker interface {
// DefaultInitChecker is the default InitChecker.
type DefaultInitChecker struct {
resolver netxlite.Resolver
resolver netxlite.ResolverLegacy
}
// InitialChecks checks whether the URL is valid and whether the
@@ -24,7 +24,7 @@ type Config struct {
checker InitChecker
explorer Explorer
generator Generator
resolver netxlite.Resolver
resolver netxlite.ResolverLegacy
}
// Measure performs the three consecutive steps of the testhelper algorithm:
@@ -87,10 +87,12 @@ func newDNSFailedResponse(err error, URL string) *ControlResponse {
}
// newResolver creates a new DNS resolver instance
func newResolver() netxlite.Resolver {
func newResolver() netxlite.ResolverLegacy {
childResolver, err := netx.NewDNSClient(netx.Config{Logger: log.Log}, "doh://google")
runtimex.PanicOnError(err, "NewDNSClient failed")
var r netxlite.Resolver = childResolver
r = &netxlite.ResolverIDNA{Resolver: r}
var r netxlite.ResolverLegacy = childResolver
r = &netxlite.ResolverIDNA{
Resolver: netxlite.NewResolverLegacyAdapter(r),
}
return r
}