diff --git a/internal/engine/experiment/urlgetter/configurer_test.go b/internal/engine/experiment/urlgetter/configurer_test.go index 1de0b06..f84638c 100644 --- a/internal/engine/experiment/urlgetter/configurer_test.go +++ b/internal/engine/experiment/urlgetter/configurer_test.go @@ -116,7 +116,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSPowerdns(t *testing.T) { if configuration.HTTPConfig.BaseResolver == nil { t.Fatal("not the BaseResolver we expected") } - sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver) + sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -124,7 +124,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSPowerdns(t *testing.T) { if !ok { t.Fatal("not the DNS transport we expected") } - dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS) + dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS) if !ok { t.Fatal("not the DNS transport we expected") } @@ -192,7 +192,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSGoogle(t *testing.T) { if configuration.HTTPConfig.BaseResolver == nil { t.Fatal("not the BaseResolver we expected") } - sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver) + sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -200,7 +200,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSGoogle(t *testing.T) { if !ok { t.Fatal("not the DNS transport we expected") } - dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS) + dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS) if !ok { t.Fatal("not the DNS transport we expected") } @@ -268,7 +268,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSCloudflare(t *testing.T) if configuration.HTTPConfig.BaseResolver == nil { t.Fatal("not the BaseResolver we expected") } - sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver) + sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -276,7 +276,7 @@ func TestConfigurerNewConfigurationResolverDNSOverHTTPSCloudflare(t *testing.T) if !ok { t.Fatal("not the DNS transport we expected") } - dohtxp, ok := stxp.RoundTripper.(*resolver.DNSOverHTTPS) + dohtxp, ok := stxp.DNSTransport.(*netxlite.DNSOverHTTPS) if !ok { t.Fatal("not the DNS transport we expected") } @@ -344,7 +344,7 @@ func TestConfigurerNewConfigurationResolverUDP(t *testing.T) { if configuration.HTTPConfig.BaseResolver == nil { t.Fatal("not the BaseResolver we expected") } - sr, ok := configuration.HTTPConfig.BaseResolver.(*resolver.SerialResolver) + sr, ok := configuration.HTTPConfig.BaseResolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -352,7 +352,7 @@ func TestConfigurerNewConfigurationResolverUDP(t *testing.T) { if !ok { t.Fatal("not the DNS transport we expected") } - udptxp, ok := stxp.RoundTripper.(*resolver.DNSOverUDP) + udptxp, ok := stxp.DNSTransport.(*netxlite.DNSOverUDP) if !ok { t.Fatal("not the DNS transport we expected") } diff --git a/internal/engine/netx/netx.go b/internal/engine/netx/netx.go index a515407..1b7e822 100644 --- a/internal/engine/netx/netx.go +++ b/internal/engine/netx/netx.go @@ -305,15 +305,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride, case "https": config.TLSConfig.NextProtos = []string{"h2", "http/1.1"} c.httpClient = &http.Client{Transport: NewHTTPTransport(config)} - var txp resolver.RoundTripper = resolver.NewDNSOverHTTPSWithHostOverride( + var txp model.DNSTransport = netxlite.NewDNSOverHTTPSWithHostOverride( c.httpClient, URL, hostOverride) if config.ResolveSaver != nil { txp = resolver.SaverDNSTransport{ - RoundTripper: txp, + DNSTransport: txp, Saver: config.ResolveSaver, } } - c.Resolver = resolver.NewSerialResolver(txp) + c.Resolver = netxlite.NewSerialResolver(txp) return c, nil case "udp": dialer := NewDialer(config) @@ -321,15 +321,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride, if err != nil { return c, err } - var txp resolver.RoundTripper = resolver.NewDNSOverUDP( + var txp model.DNSTransport = netxlite.NewDNSOverUDP( dialer, endpoint) if config.ResolveSaver != nil { txp = resolver.SaverDNSTransport{ - RoundTripper: txp, + DNSTransport: txp, Saver: config.ResolveSaver, } } - c.Resolver = resolver.NewSerialResolver(txp) + c.Resolver = netxlite.NewSerialResolver(txp) return c, nil case "dot": config.TLSConfig.NextProtos = []string{"dot"} @@ -338,15 +338,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride, if err != nil { return c, err } - var txp resolver.RoundTripper = resolver.NewDNSOverTLS( + var txp model.DNSTransport = netxlite.NewDNSOverTLS( tlsDialer.DialTLSContext, endpoint) if config.ResolveSaver != nil { txp = resolver.SaverDNSTransport{ - RoundTripper: txp, + DNSTransport: txp, Saver: config.ResolveSaver, } } - c.Resolver = resolver.NewSerialResolver(txp) + c.Resolver = netxlite.NewSerialResolver(txp) return c, nil case "tcp": dialer := NewDialer(config) @@ -354,15 +354,15 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride, if err != nil { return c, err } - var txp resolver.RoundTripper = resolver.NewDNSOverTCP( + var txp model.DNSTransport = netxlite.NewDNSOverTCP( dialer.DialContext, endpoint) if config.ResolveSaver != nil { txp = resolver.SaverDNSTransport{ - RoundTripper: txp, + DNSTransport: txp, Saver: config.ResolveSaver, } } - c.Resolver = resolver.NewSerialResolver(txp) + c.Resolver = netxlite.NewSerialResolver(txp) return c, nil default: return c, errors.New("unsupported resolver scheme") diff --git a/internal/engine/netx/netx_test.go b/internal/engine/netx/netx_test.go index f8987c1..9d03a99 100644 --- a/internal/engine/netx/netx_test.go +++ b/internal/engine/netx/netx_test.go @@ -591,11 +591,11 @@ func TestNewDNSClientPowerdnsDoH(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { 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") } dnsclient.CloseIdleConnections() @@ -607,11 +607,11 @@ func TestNewDNSClientGoogleDoH(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { 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") } dnsclient.CloseIdleConnections() @@ -623,11 +623,11 @@ func TestNewDNSClientCloudflareDoH(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { 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") } dnsclient.CloseIdleConnections() @@ -640,7 +640,7 @@ func TestNewDNSClientCloudflareDoHSaver(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -648,7 +648,7 @@ func TestNewDNSClientCloudflareDoHSaver(t *testing.T) { if !ok { 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") } dnsclient.CloseIdleConnections() @@ -660,11 +660,11 @@ func TestNewDNSClientUDP(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { 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") } dnsclient.CloseIdleConnections() @@ -677,7 +677,7 @@ func TestNewDNSClientUDPDNSSaver(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -685,7 +685,7 @@ func TestNewDNSClientUDPDNSSaver(t *testing.T) { if !ok { 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") } dnsclient.CloseIdleConnections() @@ -697,11 +697,11 @@ func TestNewDNSClientTCP(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } - txp, ok := r.Transport().(*resolver.DNSOverTCP) + txp, ok := r.Transport().(*netxlite.DNSOverTCP) if !ok { t.Fatal("not the transport we expected") } @@ -718,7 +718,7 @@ func TestNewDNSClientTCPDNSSaver(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -726,7 +726,7 @@ func TestNewDNSClientTCPDNSSaver(t *testing.T) { if !ok { t.Fatal("not the transport we expected") } - dotcp, ok := txp.RoundTripper.(*resolver.DNSOverTCP) + dotcp, ok := txp.DNSTransport.(*netxlite.DNSOverTCP) if !ok { t.Fatal("not the transport we expected") } @@ -742,11 +742,11 @@ func TestNewDNSClientDoT(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } - txp, ok := r.Transport().(*resolver.DNSOverTCP) + txp, ok := r.Transport().(*netxlite.DNSOverTCP) if !ok { t.Fatal("not the transport we expected") } @@ -763,7 +763,7 @@ func TestNewDNSClientDoTDNSSaver(t *testing.T) { if err != nil { t.Fatal(err) } - r, ok := dnsclient.Resolver.(*resolver.SerialResolver) + r, ok := dnsclient.Resolver.(*netxlite.SerialResolver) if !ok { t.Fatal("not the resolver we expected") } @@ -771,7 +771,7 @@ func TestNewDNSClientDoTDNSSaver(t *testing.T) { if !ok { t.Fatal("not the transport we expected") } - dotls, ok := txp.RoundTripper.(*resolver.DNSOverTCP) + dotls, ok := txp.DNSTransport.(*netxlite.DNSOverTCP) if !ok { t.Fatal("not the transport we expected") } diff --git a/internal/engine/netx/resolver/integration_test.go b/internal/engine/netx/resolver/integration_test.go index 3896317..27f4262 100644 --- a/internal/engine/netx/resolver/integration_test.go +++ b/internal/engine/netx/resolver/integration_test.go @@ -2,12 +2,12 @@ package resolver_test import ( "context" + "crypto/tls" "net" "net/http" "testing" "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/netxlite" ) @@ -70,50 +70,50 @@ func TestNewResolverSystem(t *testing.T) { } func TestNewResolverUDPAddress(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverUDP(netxlite.DefaultDialer, "8.8.8.8:53")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverUDP(netxlite.DefaultDialer, "8.8.8.8:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverUDPDomain(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverUDP(netxlite.DefaultDialer, "dns.google.com:53")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverUDP(netxlite.DefaultDialer, "dns.google.com:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverTCPAddress(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverTCP(new(net.Dialer).DialContext, "8.8.8.8:53")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverTCP(new(net.Dialer).DialContext, "8.8.8.8:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverTCPDomain(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverTCP(new(net.Dialer).DialContext, "dns.google.com:53")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverTCP(new(net.Dialer).DialContext, "dns.google.com:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverDoTAddress(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverTLS(resolver.DialTLSContext, "8.8.8.8:853")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverTLS(new(tls.Dialer).DialContext, "8.8.8.8:853")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverDoTDomain(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverTLS(resolver.DialTLSContext, "dns.google.com:853")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverTLS(new(tls.Dialer).DialContext, "dns.google.com:853")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverDoH(t *testing.T) { - reso := resolver.NewSerialResolver( - resolver.NewDNSOverHTTPS(http.DefaultClient, "https://cloudflare-dns.com/dns-query")) + reso := netxlite.NewSerialResolver( + netxlite.NewDNSOverHTTPS(http.DefaultClient, "https://cloudflare-dns.com/dns-query")) testresolverquick(t, reso) testresolverquickidna(t, reso) } diff --git a/internal/engine/netx/resolver/legacy.go b/internal/engine/netx/resolver/legacy.go deleted file mode 100644 index bd47c0c..0000000 --- a/internal/engine/netx/resolver/legacy.go +++ /dev/null @@ -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 -) diff --git a/internal/engine/netx/resolver/saver.go b/internal/engine/netx/resolver/saver.go index 26388d1..0c034dc 100644 --- a/internal/engine/netx/resolver/saver.go +++ b/internal/engine/netx/resolver/saver.go @@ -41,7 +41,7 @@ func (r SaverResolver) LookupHost(ctx context.Context, hostname string) ([]strin // SaverDNSTransport is a DNS transport that saves events type SaverDNSTransport struct { - RoundTripper + model.DNSTransport Saver *trace.Saver } @@ -55,7 +55,7 @@ func (txp SaverDNSTransport) RoundTrip(ctx context.Context, query []byte) ([]byt Proto: txp.Network(), Time: start, }) - reply, err := txp.RoundTripper.RoundTrip(ctx, query) + reply, err := txp.DNSTransport.RoundTrip(ctx, query) stop := time.Now() txp.Saver.Write(trace.Event{ Address: txp.Address(), @@ -71,4 +71,4 @@ func (txp SaverDNSTransport) RoundTrip(ctx context.Context, query []byte) ([]byt } var _ model.Resolver = SaverResolver{} -var _ RoundTripper = SaverDNSTransport{} +var _ model.DNSTransport = SaverDNSTransport{} diff --git a/internal/engine/netx/resolver/saver_test.go b/internal/engine/netx/resolver/saver_test.go index ad762ff..ecd1764 100644 --- a/internal/engine/netx/resolver/saver_test.go +++ b/internal/engine/netx/resolver/saver_test.go @@ -114,7 +114,7 @@ func TestSaverDNSTransportFailure(t *testing.T) { expected := errors.New("no such host") saver := &trace.Saver{} txp := resolver.SaverDNSTransport{ - RoundTripper: resolver.FakeTransport{ + DNSTransport: resolver.FakeTransport{ Err: expected, }, Saver: saver, @@ -164,7 +164,7 @@ func TestSaverDNSTransportSuccess(t *testing.T) { expected := []byte("def") saver := &trace.Saver{} txp := resolver.SaverDNSTransport{ - RoundTripper: resolver.FakeTransport{ + DNSTransport: resolver.FakeTransport{ Data: expected, }, Saver: saver, diff --git a/internal/engine/netx/resolver/tls_test.go b/internal/engine/netx/resolver/tls_test.go deleted file mode 100644 index 3280e46..0000000 --- a/internal/engine/netx/resolver/tls_test.go +++ /dev/null @@ -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 - } -}