From b5826a0c446874e611748431406ac962d6ffceae Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 9 Sep 2021 18:01:20 +0200 Subject: [PATCH] refactor(jafar): remove unnecessary dep on netx (#497) --- internal/cmd/jafar/httpproxy/httpproxy.go | 4 +--- internal/cmd/jafar/resolver/resolver.go | 8 ++++++-- internal/cmd/jafar/tlsproxy/tlsproxy.go | 8 ++++++-- internal/cmd/jafar/tlsproxy/tlsproxy_test.go | 2 -- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/cmd/jafar/httpproxy/httpproxy.go b/internal/cmd/jafar/httpproxy/httpproxy.go index 5a7aa6b..eac5025 100644 --- a/internal/cmd/jafar/httpproxy/httpproxy.go +++ b/internal/cmd/jafar/httpproxy/httpproxy.go @@ -9,8 +9,6 @@ import ( "net/http/httputil" "net/url" "strings" - - "github.com/ooni/probe-cli/v3/internal/engine/netx" ) const product = "jafar/0.1.0" @@ -27,7 +25,7 @@ type CensoringProxy struct { // the Host header of a request. dnsNetwork and dnsAddress are // settings to configure the upstream, non censored DNS. func NewCensoringProxy( - keywords []string, uncensored netx.HTTPRoundTripper, + keywords []string, uncensored http.RoundTripper, ) *CensoringProxy { return &CensoringProxy{keywords: keywords, transport: uncensored} } diff --git a/internal/cmd/jafar/resolver/resolver.go b/internal/cmd/jafar/resolver/resolver.go index 2b4baf9..44eba27 100644 --- a/internal/cmd/jafar/resolver/resolver.go +++ b/internal/cmd/jafar/resolver/resolver.go @@ -9,9 +9,13 @@ import ( "strings" "github.com/miekg/dns" - "github.com/ooni/probe-cli/v3/internal/engine/netx" ) +// Resolver resolves domain names. +type Resolver interface { + LookupHost(ctx context.Context, hostname string) ([]string, error) +} + // CensoringResolver is a censoring resolver. type CensoringResolver struct { blocked []string @@ -27,7 +31,7 @@ type CensoringResolver struct { // and TLS proxies will pick them up. dnsNetwork and dnsAddress are the // settings to configure the upstream, non censored DNS. func NewCensoringResolver( - blocked, hijacked, ignored []string, uncensored netx.Resolver, + blocked, hijacked, ignored []string, uncensored Resolver, ) *CensoringResolver { return &CensoringResolver{ blocked: blocked, diff --git a/internal/cmd/jafar/tlsproxy/tlsproxy.go b/internal/cmd/jafar/tlsproxy/tlsproxy.go index 52915cc..91cede5 100644 --- a/internal/cmd/jafar/tlsproxy/tlsproxy.go +++ b/internal/cmd/jafar/tlsproxy/tlsproxy.go @@ -12,9 +12,13 @@ import ( "sync" "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/engine/netx" ) +// Dialer establishes network connections +type Dialer interface { + DialContext(ctx context.Context, network, address string) (net.Conn, error) +} + // CensoringProxy is a censoring TLS proxy type CensoringProxy struct { keywords []string @@ -27,7 +31,7 @@ type CensoringProxy struct { // the SNII record of a ClientHello. dnsNetwork and dnsAddress are // settings to configure the upstream, non censored DNS. func NewCensoringProxy( - keywords []string, uncensored netx.Dialer, + keywords []string, uncensored Dialer, ) *CensoringProxy { return &CensoringProxy{ keywords: keywords, diff --git a/internal/cmd/jafar/tlsproxy/tlsproxy_test.go b/internal/cmd/jafar/tlsproxy/tlsproxy_test.go index 5282ed9..8c01d33 100644 --- a/internal/cmd/jafar/tlsproxy/tlsproxy_test.go +++ b/internal/cmd/jafar/tlsproxy/tlsproxy_test.go @@ -174,8 +174,6 @@ func TestForwardWriteError(t *testing.T) { type mockedConnReadOkay struct { net.Conn - localIP net.IP - remoteIP net.IP } func (c *mockedConnReadOkay) Read(b []byte) (int, error) {