cleanup(netx): remove more legacy names and functions (#658)
This diff addresses two items of https://github.com/ooni/probe/issues/1956: > - [ ] we can remove legacy names from `./internal/engine/netx/resolver/legacy.go` > > - [ ] we can remove `DialTLSContext` from `./internal/engine/netx/resolver/tls_test.go` More cleanups may follow.
This commit is contained in:
parent
423a3feacc
commit
554ae47c5a
|
@ -116,7 +116,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSPowerdns(t *testing.T) {
|
||||||
if configuration.HTTPConfig.BaseResolver == nil {
|
if configuration.HTTPConfig.BaseResolver == nil {
|
||||||
t.Fatal("not the BaseResolver we expected")
|
t.Fatal("not the BaseResolver we expected")
|
||||||
}
|
}
|
||||||
sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver)
|
sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSPowerdns(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS)
|
dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSGoogle(t *testing.T) {
|
||||||
if configuration.HTTPConfig.BaseResolver == nil {
|
if configuration.HTTPConfig.BaseResolver == nil {
|
||||||
t.Fatal("not the BaseResolver we expected")
|
t.Fatal("not the BaseResolver we expected")
|
||||||
}
|
}
|
||||||
sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver)
|
sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSGoogle(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS)
|
dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSCloudflare(t *testing.T)
|
||||||
if configuration.HTTPConfig.BaseResolver == nil {
|
if configuration.HTTPConfig.BaseResolver == nil {
|
||||||
t.Fatal("not the BaseResolver we expected")
|
t.Fatal("not the BaseResolver we expected")
|
||||||
}
|
}
|
||||||
sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver)
|
sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSCloudflare(t *testing.T)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS)
|
dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ func TestConfigurerNewConfigurationResolverUDP(t *testing.T) {
|
||||||
if configuration.HTTPConfig.BaseResolver == nil {
|
if configuration.HTTPConfig.BaseResolver == nil {
|
||||||
t.Fatal("not the BaseResolver we expected")
|
t.Fatal("not the BaseResolver we expected")
|
||||||
}
|
}
|
||||||
sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver)
|
sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ func TestConfigurerNewConfigurationResolverUDP(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
udptxp, ok := stxp.RoundTripper.(*resolver.DNSOverUDP)
|
udptxp, ok := stxp.DNSTransport.(*netxlite.DNSOverUDP)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the DNS transport we expected")
|
t.Fatal("not the DNS transport we expected")
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,15 +305,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
|
||||||
case "https":
|
case "https":
|
||||||
config.TLSConfig.NextProtos = []string{"h2", "http/1.1"}
|
config.TLSConfig.NextProtos = []string{"h2", "http/1.1"}
|
||||||
c.httpClient = &http.Client{Transport: NewHTTPTransport(config)}
|
c.httpClient = &http.Client{Transport: NewHTTPTransport(config)}
|
||||||
var txp resolver.RoundTripper = resolver.NewDNSOverHTTPSWithHostOverride(
|
var txp model.DNSTransport = netxlite.NewDNSOverHTTPSWithHostOverride(
|
||||||
c.httpClient, URL, hostOverride)
|
c.httpClient, URL, hostOverride)
|
||||||
if config.ResolveSaver != nil {
|
if config.ResolveSaver != nil {
|
||||||
txp = resolver.SaverDNSTransport{
|
txp = resolver.SaverDNSTransport{
|
||||||
RoundTripper: txp,
|
DNSTransport: txp,
|
||||||
Saver: config.ResolveSaver,
|
Saver: config.ResolveSaver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Resolver = resolver.NewSerialResolver(txp)
|
c.Resolver = netxlite.NewSerialResolver(txp)
|
||||||
return c, nil
|
return c, nil
|
||||||
case "udp":
|
case "udp":
|
||||||
dialer := NewDialer(config)
|
dialer := NewDialer(config)
|
||||||
|
@ -321,15 +321,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
var txp resolver.RoundTripper = resolver.NewDNSOverUDP(
|
var txp model.DNSTransport = netxlite.NewDNSOverUDP(
|
||||||
dialer, endpoint)
|
dialer, endpoint)
|
||||||
if config.ResolveSaver != nil {
|
if config.ResolveSaver != nil {
|
||||||
txp = resolver.SaverDNSTransport{
|
txp = resolver.SaverDNSTransport{
|
||||||
RoundTripper: txp,
|
DNSTransport: txp,
|
||||||
Saver: config.ResolveSaver,
|
Saver: config.ResolveSaver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Resolver = resolver.NewSerialResolver(txp)
|
c.Resolver = netxlite.NewSerialResolver(txp)
|
||||||
return c, nil
|
return c, nil
|
||||||
case "dot":
|
case "dot":
|
||||||
config.TLSConfig.NextProtos = []string{"dot"}
|
config.TLSConfig.NextProtos = []string{"dot"}
|
||||||
|
@ -338,15 +338,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
var txp resolver.RoundTripper = resolver.NewDNSOverTLS(
|
var txp model.DNSTransport = netxlite.NewDNSOverTLS(
|
||||||
tlsDialer.DialTLSContext, endpoint)
|
tlsDialer.DialTLSContext, endpoint)
|
||||||
if config.ResolveSaver != nil {
|
if config.ResolveSaver != nil {
|
||||||
txp = resolver.SaverDNSTransport{
|
txp = resolver.SaverDNSTransport{
|
||||||
RoundTripper: txp,
|
DNSTransport: txp,
|
||||||
Saver: config.ResolveSaver,
|
Saver: config.ResolveSaver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Resolver = resolver.NewSerialResolver(txp)
|
c.Resolver = netxlite.NewSerialResolver(txp)
|
||||||
return c, nil
|
return c, nil
|
||||||
case "tcp":
|
case "tcp":
|
||||||
dialer := NewDialer(config)
|
dialer := NewDialer(config)
|
||||||
|
@ -354,15 +354,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
var txp resolver.RoundTripper = resolver.NewDNSOverTCP(
|
var txp model.DNSTransport = netxlite.NewDNSOverTCP(
|
||||||
dialer.DialContext, endpoint)
|
dialer.DialContext, endpoint)
|
||||||
if config.ResolveSaver != nil {
|
if config.ResolveSaver != nil {
|
||||||
txp = resolver.SaverDNSTransport{
|
txp = resolver.SaverDNSTransport{
|
||||||
RoundTripper: txp,
|
DNSTransport: txp,
|
||||||
Saver: config.ResolveSaver,
|
Saver: config.ResolveSaver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Resolver = resolver.NewSerialResolver(txp)
|
c.Resolver = netxlite.NewSerialResolver(txp)
|
||||||
return c, nil
|
return c, nil
|
||||||
default:
|
default:
|
||||||
return c, errors.New("unsupported resolver scheme")
|
return c, errors.New("unsupported resolver scheme")
|
||||||
|
|
|
@ -591,11 +591,11 @@ func TestNewDNSClientPowerdnsDoH(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
if _, ok := r.Transport().(*resolver.DNSOverHTTPS); !ok {
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPS); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -607,11 +607,11 @@ func TestNewDNSClientGoogleDoH(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
if _, ok := r.Transport().(*resolver.DNSOverHTTPS); !ok {
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPS); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -623,11 +623,11 @@ func TestNewDNSClientCloudflareDoH(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
if _, ok := r.Transport().(*resolver.DNSOverHTTPS); !ok {
|
if _, ok := r.Transport().(*netxlite.DNSOverHTTPS); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -640,7 +640,7 @@ func TestNewDNSClientCloudflareDoHSaver(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ func TestNewDNSClientCloudflareDoHSaver(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
if _, ok := txp.RoundTripper.(*resolver.DNSOverHTTPS); !ok {
|
if _, ok := txp.DNSTransport.(*netxlite.DNSOverHTTPS); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -660,11 +660,11 @@ func TestNewDNSClientUDP(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
if _, ok := r.Transport().(*resolver.DNSOverUDP); !ok {
|
if _, ok := r.Transport().(*netxlite.DNSOverUDP); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -677,7 +677,7 @@ func TestNewDNSClientUDPDNSSaver(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -685,7 +685,7 @@ func TestNewDNSClientUDPDNSSaver(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
if _, ok := txp.RoundTripper.(*resolver.DNSOverUDP); !ok {
|
if _, ok := txp.DNSTransport.(*netxlite.DNSOverUDP); !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dnsclient.CloseIdleConnections()
|
dnsclient.CloseIdleConnections()
|
||||||
|
@ -697,11 +697,11 @@ func TestNewDNSClientTCP(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
txp, ok := r.Transport().(*resolver.DNSOverTCP)
|
txp, ok := r.Transport().(*netxlite.DNSOverTCP)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,7 @@ func TestNewDNSClientTCPDNSSaver(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -726,7 +726,7 @@ func TestNewDNSClientTCPDNSSaver(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dotcp, ok := txp.RoundTripper.(*resolver.DNSOverTCP)
|
dotcp, ok := txp.DNSTransport.(*netxlite.DNSOverTCP)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -742,11 +742,11 @@ func TestNewDNSClientDoT(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
txp, ok := r.Transport().(*resolver.DNSOverTCP)
|
txp, ok := r.Transport().(*netxlite.DNSOverTCP)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
|
@ -763,7 +763,7 @@ func TestNewDNSClientDoTDNSSaver(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r, ok := dnsclient.Resolver.(*resolver.SerialResolver)
|
r, ok := dnsclient.Resolver.(*netxlite.SerialResolver)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the resolver we expected")
|
t.Fatal("not the resolver we expected")
|
||||||
}
|
}
|
||||||
|
@ -771,7 +771,7 @@ func TestNewDNSClientDoTDNSSaver(t *testing.T) {
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
dotls, ok := txp.RoundTripper.(*resolver.DNSOverTCP)
|
dotls, ok := txp.DNSTransport.(*netxlite.DNSOverTCP)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("not the transport we expected")
|
t.Fatal("not the transport we expected")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ package resolver_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver"
|
|
||||||
"github.com/ooni/probe-cli/v3/internal/model"
|
"github.com/ooni/probe-cli/v3/internal/model"
|
||||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||||
)
|
)
|
||||||
|
@ -70,50 +70,50 @@ func TestNewResolverSystem(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverUDPAddress(t *testing.T) {
|
func TestNewResolverUDPAddress(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverUDP(netxlite.DefaultDialer, "8.8.8.8:53"))
|
netxlite.NewDNSOverUDP(netxlite.DefaultDialer, "8.8.8.8:53"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverUDPDomain(t *testing.T) {
|
func TestNewResolverUDPDomain(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverUDP(netxlite.DefaultDialer, "dns.google.com:53"))
|
netxlite.NewDNSOverUDP(netxlite.DefaultDialer, "dns.google.com:53"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverTCPAddress(t *testing.T) {
|
func TestNewResolverTCPAddress(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverTCP(new(net.Dialer).DialContext, "8.8.8.8:53"))
|
netxlite.NewDNSOverTCP(new(net.Dialer).DialContext, "8.8.8.8:53"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverTCPDomain(t *testing.T) {
|
func TestNewResolverTCPDomain(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverTCP(new(net.Dialer).DialContext, "dns.google.com:53"))
|
netxlite.NewDNSOverTCP(new(net.Dialer).DialContext, "dns.google.com:53"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverDoTAddress(t *testing.T) {
|
func TestNewResolverDoTAddress(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverTLS(resolver.DialTLSContext, "8.8.8.8:853"))
|
netxlite.NewDNSOverTLS(new(tls.Dialer).DialContext, "8.8.8.8:853"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverDoTDomain(t *testing.T) {
|
func TestNewResolverDoTDomain(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverTLS(resolver.DialTLSContext, "dns.google.com:853"))
|
netxlite.NewDNSOverTLS(new(tls.Dialer).DialContext, "dns.google.com:853"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewResolverDoH(t *testing.T) {
|
func TestNewResolverDoH(t *testing.T) {
|
||||||
reso := resolver.NewSerialResolver(
|
reso := netxlite.NewSerialResolver(
|
||||||
resolver.NewDNSOverHTTPS(http.DefaultClient, "https://cloudflare-dns.com/dns-query"))
|
netxlite.NewDNSOverHTTPS(http.DefaultClient, "https://cloudflare-dns.com/dns-query"))
|
||||||
testresolverquick(t, reso)
|
testresolverquick(t, reso)
|
||||||
testresolverquickidna(t, reso)
|
testresolverquickidna(t, reso)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package resolver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ooni/probe-cli/v3/internal/model"
|
|
||||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Variables that other packages expect to find here but have been
|
|
||||||
// moved into the internal/netxlite package.
|
|
||||||
var (
|
|
||||||
NewSerialResolver = netxlite.NewSerialResolver
|
|
||||||
NewDNSOverUDP = netxlite.NewDNSOverUDP
|
|
||||||
NewDNSOverTCP = netxlite.NewDNSOverTCP
|
|
||||||
NewDNSOverTLS = netxlite.NewDNSOverTLS
|
|
||||||
NewDNSOverHTTPS = netxlite.NewDNSOverHTTPS
|
|
||||||
NewDNSOverHTTPSWithHostOverride = netxlite.NewDNSOverHTTPSWithHostOverride
|
|
||||||
)
|
|
||||||
|
|
||||||
// Types that other packages expect to find here but have been
|
|
||||||
// moved into the internal/netxlite package.
|
|
||||||
type (
|
|
||||||
DNSOverHTTPS = netxlite.DNSOverHTTPS
|
|
||||||
DNSOverTCP = netxlite.DNSOverTCP
|
|
||||||
DNSOverUDP = netxlite.DNSOverUDP
|
|
||||||
MiekgEncoder = netxlite.DNSEncoderMiekg
|
|
||||||
MiekgDecoder = netxlite.DNSDecoderMiekg
|
|
||||||
RoundTripper = model.DNSTransport
|
|
||||||
SerialResolver = netxlite.SerialResolver
|
|
||||||
Dialer = model.Dialer
|
|
||||||
DialContextFunc = netxlite.DialContextFunc
|
|
||||||
)
|
|
|
@ -41,7 +41,7 @@ func (r SaverResolver) LookupHost(ctx context.Context, hostname string) ([]strin
|
||||||
|
|
||||||
// SaverDNSTransport is a DNS transport that saves events
|
// SaverDNSTransport is a DNS transport that saves events
|
||||||
type SaverDNSTransport struct {
|
type SaverDNSTransport struct {
|
||||||
RoundTripper
|
model.DNSTransport
|
||||||
Saver *trace.Saver
|
Saver *trace.Saver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func (txp SaverDNSTransport) RoundTrip(ctx context.Context, query []byte) ([]byt
|
||||||
Proto: txp.Network(),
|
Proto: txp.Network(),
|
||||||
Time: start,
|
Time: start,
|
||||||
})
|
})
|
||||||
reply, err := txp.RoundTripper.RoundTrip(ctx, query)
|
reply, err := txp.DNSTransport.RoundTrip(ctx, query)
|
||||||
stop := time.Now()
|
stop := time.Now()
|
||||||
txp.Saver.Write(trace.Event{
|
txp.Saver.Write(trace.Event{
|
||||||
Address: txp.Address(),
|
Address: txp.Address(),
|
||||||
|
@ -71,4 +71,4 @@ func (txp SaverDNSTransport) RoundTrip(ctx context.Context, query []byte) ([]byt
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ model.Resolver = SaverResolver{}
|
var _ model.Resolver = SaverResolver{}
|
||||||
var _ RoundTripper = SaverDNSTransport{}
|
var _ model.DNSTransport = SaverDNSTransport{}
|
||||||
|
|
|
@ -114,7 +114,7 @@ func TestSaverDNSTransportFailure(t *testing.T) {
|
||||||
expected := errors.New("no such host")
|
expected := errors.New("no such host")
|
||||||
saver := &trace.Saver{}
|
saver := &trace.Saver{}
|
||||||
txp := resolver.SaverDNSTransport{
|
txp := resolver.SaverDNSTransport{
|
||||||
RoundTripper: resolver.FakeTransport{
|
DNSTransport: resolver.FakeTransport{
|
||||||
Err: expected,
|
Err: expected,
|
||||||
},
|
},
|
||||||
Saver: saver,
|
Saver: saver,
|
||||||
|
@ -164,7 +164,7 @@ func TestSaverDNSTransportSuccess(t *testing.T) {
|
||||||
expected := []byte("def")
|
expected := []byte("def")
|
||||||
saver := &trace.Saver{}
|
saver := &trace.Saver{}
|
||||||
txp := resolver.SaverDNSTransport{
|
txp := resolver.SaverDNSTransport{
|
||||||
RoundTripper: resolver.FakeTransport{
|
DNSTransport: resolver.FakeTransport{
|
||||||
Data: expected,
|
Data: expected,
|
||||||
},
|
},
|
||||||
Saver: saver,
|
Saver: saver,
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package resolver
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
|
||||||
"net"
|
|
||||||
)
|
|
||||||
|
|
||||||
func DialTLSContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
||||||
connch := make(chan net.Conn)
|
|
||||||
errch := make(chan error, 1)
|
|
||||||
go func() {
|
|
||||||
conn, err := tls.Dial(network, address, new(tls.Config))
|
|
||||||
if err != nil {
|
|
||||||
errch <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
conn.Close()
|
|
||||||
case connch <- conn:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil, ctx.Err()
|
|
||||||
case conn := <-connch:
|
|
||||||
return conn, nil
|
|
||||||
case err := <-errch:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user