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:
parent
b7a6dbe47b
commit
06ee0e55a9
30 changed files with 312 additions and 517 deletions
|
|
@ -8,15 +8,15 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// ShapingDialer ensures we don't use too much bandwidth
|
||||
// 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 {
|
||||
type shapingDialer struct {
|
||||
Dialer
|
||||
}
|
||||
|
||||
// DialContext implements Dialer.DialContext
|
||||
func (d ShapingDialer) 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 {
|
||||
|
|
@ -29,12 +29,12 @@ type shapingConn struct {
|
|||
net.Conn
|
||||
}
|
||||
|
||||
func (c shapingConn) Read(p []byte) (int, error) {
|
||||
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) {
|
||||
func (c *shapingConn) Write(p []byte) (int, error) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
return c.Conn.Write(p)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue