refactor: only use shaping dialer for ndt7 and dash (#754)

See https://github.com/ooni/probe/issues/2112 for context.

While there, run `go fix -fix buildtag ./...`
This commit is contained in:
Simone Basso
2022-05-24 18:23:42 +02:00
committed by GitHub
parent b68b8e1e8f
commit 6924d1ad81
17 changed files with 126 additions and 65 deletions
+8 -2
View File
@@ -259,8 +259,14 @@ func (m Measurer) Run(
httpClient := &http.Client{
Transport: netx.NewHTTPTransport(netx.Config{
ContextByteCounting: true,
DialSaver: saver,
Logger: sess.Logger(),
// Implements shaping if the user builds using `-tags shaping`
// See https://github.com/ooni/probe/issues/2112
Dialer: netxlite.NewMaybeShapingDialer(netx.NewDialer(netx.Config{
ContextByteCounting: true,
DialSaver: saver,
Logger: sess.Logger(),
})),
Logger: sess.Logger(),
}),
}
defer httpClient.CloseIdleConnections()
+3
View File
@@ -42,6 +42,9 @@ func (mgr dialManager) dialWithTestName(ctx context.Context, testName string) (*
Logger: mgr.logger,
ProxyURL: mgr.proxyURL,
}, reso)
// Implements shaping if the user builds using `-tags shaping`
// See https://github.com/ooni/probe/issues/2112
dlr = netxlite.NewMaybeShapingDialer(dlr)
// We force using our bundled CA pool, which should fix
// https://github.com/ooni/probe/issues/2031
tlsConfig := &tls.Config{
-1
View File
@@ -67,6 +67,5 @@ func New(config *Config, resolver model.Resolver) model.Dialer {
if config.ContextByteCounting {
d = &byteCounterDialer{Dialer: d}
}
d = &shapingDialer{Dialer: d}
return d
}
+1 -5
View File
@@ -18,11 +18,7 @@ func TestNewCreatesTheExpectedChain(t *testing.T) {
ProxyURL: &url.URL{},
ReadWriteSaver: saver,
}, netxlite.DefaultResolver)
shd, ok := dlr.(*shapingDialer)
if !ok {
t.Fatal("not a shapingDialer")
}
bcd, ok := shd.Dialer.(*byteCounterDialer)
bcd, ok := dlr.(*byteCounterDialer)
if !ok {
t.Fatal("not a byteCounterDialer")
}
@@ -1,24 +0,0 @@
//go:build !shaping
// +build !shaping
package dialer
import (
"context"
"net"
"github.com/ooni/probe-cli/v3/internal/model"
)
// shapingDialer ensures we don't use too much bandwidth
// when using integration tests at GitHub. To select
// the implementation with shaping use `-tags shaping`.
type shapingDialer struct {
model.Dialer
}
// DialContext implements Dialer.DialContext
func (d *shapingDialer) DialContext(
ctx context.Context, network, address string) (net.Conn, error) {
return d.Dialer.DialContext(ctx, network, address)
}
@@ -1,43 +0,0 @@
//go:build shaping
// +build shaping
package dialer
import (
"context"
"net"
"time"
"github.com/ooni/probe-cli/v3/internal/model"
)
// shapingDialer ensures we don't use too much bandwidth
// when using integration tests at GitHub. To select
// the implementation with shaping use `-tags shaping`.
type shapingDialer struct {
model.Dialer
}
// DialContext implements Dialer.DialContext
func (d *shapingDialer) DialContext(
ctx context.Context, network, address string) (net.Conn, error) {
conn, err := d.Dialer.DialContext(ctx, network, address)
if err != nil {
return nil, err
}
return &shapingConn{Conn: conn}, nil
}
type shapingConn struct {
net.Conn
}
func (c *shapingConn) Read(p []byte) (int, error) {
time.Sleep(100 * time.Millisecond)
return c.Conn.Read(p)
}
func (c *shapingConn) Write(p []byte) (int, error) {
time.Sleep(100 * time.Millisecond)
return c.Conn.Write(p)
}
@@ -1,22 +0,0 @@
package dialer
import (
"net/http"
"testing"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestShapingDialerGood(t *testing.T) {
d := &shapingDialer{Dialer: netxlite.DefaultDialer}
txp := &http.Transport{DialContext: d.DialContext}
client := &http.Client{Transport: txp}
resp, err := client.Get("https://www.google.com/")
if err != nil {
t.Fatal(err)
}
if resp == nil {
t.Fatal("expected nil response here")
}
resp.Body.Close()
}
-1
View File
@@ -1,5 +1,4 @@
//go:build !ooni_psiphon_config
// +build !ooni_psiphon_config
package engine
@@ -1,5 +1,4 @@
//go:build !ooni_psiphon_config
// +build !ooni_psiphon_config
package engine
-1
View File
@@ -1,5 +1,4 @@
//go:build ooni_psiphon_config
// +build ooni_psiphon_config
package engine
-1
View File
@@ -1,5 +1,4 @@
//go:build ooni_psiphon_config
// +build ooni_psiphon_config
package engine