Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dnsx/dnsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client interface {
LookupNS(ctx context.Context, name string) ([]*net.NS, error)
}

// RoundTripper represent an abstract DNS transport.
// RoundTripper represents an abstract DNS transport.
type RoundTripper interface {
// RoundTrip sends a DNS query and receives the reply.
RoundTrip(query []byte) (reply []byte, err error)
Expand Down
5 changes: 2 additions & 3 deletions httpx/httpx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package httpx contains OONI's net/http extensions. It defines the Client and
// the Transport replacements that we should use in OONI. They emit measurements
// collected at network and HTTP level on a specific channel.
// collected at network and HTTP level using a specific handler.
package httpx

import (
Expand All @@ -20,8 +20,7 @@ type Transport struct {
}

// NewTransport creates a new Transport. The beginning argument is
// the time to use as zero for computing the elapsed time. The ch
// channel is where we'll emit Measurements.
// the time to use as zero for computing the elapsed time.
func NewTransport(beginning time.Time, handler model.Handler) *Transport {
t := new(Transport)
t.dialer = dialerapi.NewDialer(beginning, handler)
Expand Down
14 changes: 7 additions & 7 deletions internal/dialerapi/dialerapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@ type DialHostPortFunc func(
// Dialer defines the dialer API. We implement the most basic form
// of DNS, but more advanced resolutions are possible.
type Dialer struct {
dialerbase.Dialer
Beginning time.Time
DialHostPort DialHostPortFunc
Handler model.Handler
LookupHost LookupHostFunc
StartTLSHandshakeHook func(net.Conn)
TLSConfig *tls.Config
TLSHandshakeTimeout time.Duration
dialer *dialerbase.Dialer
}

// NewDialer creates a new Dialer.
func NewDialer(beginning time.Time, handler model.Handler) (d *Dialer) {
d = &Dialer{
Dialer: dialerbase.Dialer{
Beginning: beginning,
Dialer: net.Dialer{},
Handler: handler,
},
Beginning: beginning,
Handler: handler,
TLSConfig: &tls.Config{},
StartTLSHandshakeHook: func(net.Conn) {},
dialer: dialerbase.NewDialer(
beginning, handler,
),
}
// This is equivalent to ConfigureDNS("system", "...")
r := &net.Resolver{
PreferGo: false,
}
d.LookupHost = r.LookupHost
d.DialHostPort = d.Dialer.DialHostPort
d.DialHostPort = d.dialer.DialHostPort
return
}

Expand Down
9 changes: 9 additions & 0 deletions internal/dialerbase/dialerbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ type Dialer struct {
Handler model.Handler
}

// NewDialer creates a new base dialer
func NewDialer(beginning time.Time, handler model.Handler) *Dialer {
return &Dialer{
Dialer: net.Dialer{},
Beginning: beginning,
Handler: handler,
}
}

// DialHostPort is like net.DialContext but requires a separate host
// and port and returns a measurable net.Conn-like struct.
func (d *Dialer) DialHostPort(
Expand Down
19 changes: 10 additions & 9 deletions internal/dialerbase/dialerbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package dialerbase_test
import (
"context"
"testing"
"time"

"github.com/ooni/netx/handlers"
"github.com/ooni/netx/internal/dialerbase"
)

func TestIntegrationSuccess(t *testing.T) {
dialer := dialerbase.Dialer{
Handler: handlers.NoHandler,
}
dialer := dialerbase.NewDialer(
time.Now(), handlers.NoHandler,
)
conn, err := dialer.DialHostPort(
context.Background(), "tcp", "8.8.8.8", "53", 17,
)
Expand All @@ -22,9 +23,9 @@ func TestIntegrationSuccess(t *testing.T) {
}

func TestIntegrationErrorDomain(t *testing.T) {
dialer := dialerbase.Dialer{
Handler: handlers.NoHandler,
}
dialer := dialerbase.NewDialer(
time.Now(), handlers.NoHandler,
)
conn, err := dialer.DialHostPort(
context.Background(), "tcp", "dns.google.com", "53", 17,
)
Expand All @@ -37,9 +38,9 @@ func TestIntegrationErrorDomain(t *testing.T) {
}

func TestIntegrationErrorNoConnect(t *testing.T) {
dialer := dialerbase.Dialer{
Handler: handlers.NoHandler,
}
dialer := dialerbase.NewDialer(
time.Now(), handlers.NoHandler,
)
ctx, cancel := context.WithTimeout(context.Background(), 1)
defer cancel()
conn, err := dialer.DialHostPort(
Expand Down
14 changes: 7 additions & 7 deletions netx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func NewDialer(handler model.Handler) *Dialer {
//
// For example:
//
// d.SetResolver("system", "")
// d.SetResolver("godns", "")
// d.SetResolver("udp", "8.8.8.8:53")
// d.SetResolver("tcp", "8.8.8.8:53")
// d.SetResolver("dot", "dns.quad9.net")
// d.SetResolver("doh", "https://cloudflare-dns.com/dns-query")
// d.ConfigureDNS("system", "")
// d.ConfigureDNS("godns", "")
// d.ConfigureDNS("udp", "8.8.8.8:53")
// d.ConfigureDNS("tcp", "8.8.8.8:53")
// d.ConfigureDNS("dot", "dns.quad9.net")
// d.ConfigureDNS("doh", "https://cloudflare-dns.com/dns-query")
//
// ConfigureDNS is currently only executed when Go chooses to
// use the pure Go implementation of the DNS. This means that it
Expand Down Expand Up @@ -108,7 +108,7 @@ func (d *Dialer) NewResolver(network, address string) (dnsx.Client, error) {
}

// SetCABundle configures the dialer to use a specific CA bundle. This
// function is not goroutine safe. Make sure you call it befor starting
// function is not goroutine safe. Make sure you call it before starting
// to use this specific dialer.
func (d *Dialer) SetCABundle(path string) error {
return d.dialer.SetCABundle(path)
Expand Down