refactor(jafar): remove unnecessary dep on netx (#497)

This commit is contained in:
Simone Basso 2021-09-09 18:01:20 +02:00 committed by GitHub
parent 1d79d70b43
commit b5826a0c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -9,8 +9,6 @@ import (
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"strings" "strings"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
) )
const product = "jafar/0.1.0" const product = "jafar/0.1.0"
@ -27,7 +25,7 @@ type CensoringProxy struct {
// the Host header of a request. dnsNetwork and dnsAddress are // the Host header of a request. dnsNetwork and dnsAddress are
// settings to configure the upstream, non censored DNS. // settings to configure the upstream, non censored DNS.
func NewCensoringProxy( func NewCensoringProxy(
keywords []string, uncensored netx.HTTPRoundTripper, keywords []string, uncensored http.RoundTripper,
) *CensoringProxy { ) *CensoringProxy {
return &CensoringProxy{keywords: keywords, transport: uncensored} return &CensoringProxy{keywords: keywords, transport: uncensored}
} }

View File

@ -9,9 +9,13 @@ import (
"strings" "strings"
"github.com/miekg/dns" "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. // CensoringResolver is a censoring resolver.
type CensoringResolver struct { type CensoringResolver struct {
blocked []string blocked []string
@ -27,7 +31,7 @@ type CensoringResolver struct {
// and TLS proxies will pick them up. dnsNetwork and dnsAddress are the // and TLS proxies will pick them up. dnsNetwork and dnsAddress are the
// settings to configure the upstream, non censored DNS. // settings to configure the upstream, non censored DNS.
func NewCensoringResolver( func NewCensoringResolver(
blocked, hijacked, ignored []string, uncensored netx.Resolver, blocked, hijacked, ignored []string, uncensored Resolver,
) *CensoringResolver { ) *CensoringResolver {
return &CensoringResolver{ return &CensoringResolver{
blocked: blocked, blocked: blocked,

View File

@ -12,9 +12,13 @@ import (
"sync" "sync"
"github.com/apex/log" "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 // CensoringProxy is a censoring TLS proxy
type CensoringProxy struct { type CensoringProxy struct {
keywords []string keywords []string
@ -27,7 +31,7 @@ type CensoringProxy struct {
// the SNII record of a ClientHello. dnsNetwork and dnsAddress are // the SNII record of a ClientHello. dnsNetwork and dnsAddress are
// settings to configure the upstream, non censored DNS. // settings to configure the upstream, non censored DNS.
func NewCensoringProxy( func NewCensoringProxy(
keywords []string, uncensored netx.Dialer, keywords []string, uncensored Dialer,
) *CensoringProxy { ) *CensoringProxy {
return &CensoringProxy{ return &CensoringProxy{
keywords: keywords, keywords: keywords,

View File

@ -174,8 +174,6 @@ func TestForwardWriteError(t *testing.T) {
type mockedConnReadOkay struct { type mockedConnReadOkay struct {
net.Conn net.Conn
localIP net.IP
remoteIP net.IP
} }
func (c *mockedConnReadOkay) Read(b []byte) (int, error) { func (c *mockedConnReadOkay) Read(b []byte) (int, error) {