refactor(netx/dialer): hide implementation complexity (#372)

* refactor(netx/dialer): hide implementation complexity

This follows the blueprint of `module.Config` and `nodule.New`
described at https://github.com/ooni/probe/issues/1591.

* fix: ndt7 bug where we were not using the right resolver

* fix(legacy/netx): clarify irrelevant implementation change

* fix: improve comments

* fix(hhfm): do not use dialer.New b/c it breaks it

Unclear to me why this is happening. Still, improve upon the
previous situation by adding a timeout.

It does not seem a priority to look into this issue now.
This commit is contained in:
Simone Basso
2021-06-09 09:42:31 +02:00
committed by GitHub
parent b7a6dbe47b
commit 06ee0e55a9
30 changed files with 312 additions and 517 deletions
+4 -3
View File
@@ -18,7 +18,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
@@ -312,7 +311,7 @@ type JSONHeaders struct {
// guarantee that the connection is used for a single request and that
// such a request does not contain any body.
type Dialer struct {
Dialer netx.Dialer // used for testing
Dialer dialer.Dialer // used for testing
Headers map[string]string
}
@@ -321,7 +320,9 @@ type Dialer struct {
func (d Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
child := d.Dialer
if child == nil {
child = dialer.Default
// TODO(bassosimone): figure out why using dialer.New here
// causes the experiment to fail with eof_error
child = &net.Dialer{Timeout: 15 * time.Second}
}
conn, err := child.DialContext(ctx, network, address)
if err != nil {
+1 -21
View File
@@ -13,7 +13,6 @@ import (
"github.com/apex/log"
"github.com/google/go-cmp/cmp"
engine "github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/hhfm"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/internal/mockable"
@@ -55,7 +54,7 @@ func TestSuccess(t *testing.T) {
t.Fatal("invalid Agent")
}
if tk.Failure != nil {
t.Fatal("invalid Failure")
t.Fatal("invalid Failure", *tk.Failure)
}
if len(tk.Requests) != 1 {
t.Fatal("invalid Requests")
@@ -557,25 +556,6 @@ func TestTransactCannotReadBody(t *testing.T) {
}
}
func newsession(t *testing.T) model.ExperimentSession {
sess, err := engine.NewSession(context.Background(), engine.SessionConfig{
AvailableProbeServices: []model.Service{{
Address: "https://ams-pg-test.ooni.org",
Type: "https",
}},
Logger: log.Log,
SoftwareName: "ooniprobe-engine",
SoftwareVersion: "0.0.1",
})
if err != nil {
t.Fatal(err)
}
if err := sess.MaybeLookupBackends(); err != nil {
t.Fatal(err)
}
return sess
}
func TestTestKeys_FillTampering(t *testing.T) {
type fields struct {
Agent string