refactor(ndt7): use netxlite rather than netx (#768)
This diff required us to move some code around, but no major change actually happened, except better tests. While there, I also slightly refactored ndt7's implementation and removed the ProxyURL setting, which was actually unused. See https://github.com/ooni/probe/issues/2121
This commit is contained in:
parent
314c3c934d
commit
3265bc670a
12 changed files with 189 additions and 159 deletions
52
internal/bytecounter/dialer.go
Normal file
52
internal/bytecounter/dialer.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package bytecounter
|
||||
|
||||
//
|
||||
// model.Dialer wrappers
|
||||
//
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// ContextAwareDialer is a model.Dialer that attempts to count bytes using
|
||||
// the MaybeWrapWithContextByteCounters function.
|
||||
//
|
||||
// Bug
|
||||
//
|
||||
// This implementation cannot properly account for the bytes that are sent by
|
||||
// persistent connections, because they stick to the counters set when the
|
||||
// connection was established. This typically means we miss the bytes sent and
|
||||
// received when submitting a measurement. Such bytes are specifically not
|
||||
// seen by the experiment specific byte counter.
|
||||
//
|
||||
// For this reason, this implementation may be heavily changed/removed
|
||||
// in the future (<- this message is now ~two years old, though).
|
||||
type ContextAwareDialer struct {
|
||||
Dialer model.Dialer
|
||||
}
|
||||
|
||||
// NewContextAwareDialer creates a new ContextAwareDialer.
|
||||
func NewContextAwareDialer(dialer model.Dialer) *ContextAwareDialer {
|
||||
return &ContextAwareDialer{Dialer: dialer}
|
||||
}
|
||||
|
||||
var _ model.Dialer = &ContextAwareDialer{}
|
||||
|
||||
// DialContext implements Dialer.DialContext
|
||||
func (d *ContextAwareDialer) DialContext(
|
||||
ctx context.Context, network, address string) (net.Conn, error) {
|
||||
conn, err := d.Dialer.DialContext(ctx, network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conn = MaybeWrapWithContextByteCounters(ctx, conn)
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// CloseIdleConnections implements Dialer.CloseIdleConnections.
|
||||
func (d *ContextAwareDialer) CloseIdleConnections() {
|
||||
d.Dialer.CloseIdleConnections()
|
||||
}
|
||||
Loading…
Reference in a new issue