This pull request consists of several small and obvious cleanups in the netx directory. See https://github.com/ooni/probe/issues/2121
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package netx
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
"github.com/ooni/probe-cli/v3/internal/tracex"
|
|
)
|
|
|
|
// dialerConfig contains the settings for New.
|
|
type dialerConfig struct {
|
|
// ContextByteCounting optionally configures context-based
|
|
// byte counting. By default we don't do that.
|
|
//
|
|
// Use WithExperimentByteCounter and WithSessionByteCounter
|
|
// to assign byte counters to a context. The code will use
|
|
// corresponding, private functions to access the configured
|
|
// byte counters and will notify them about I/O events.
|
|
//
|
|
// 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.
|
|
ContextByteCounting bool
|
|
|
|
// DialSaver is the optional saver for dialing events. If not
|
|
// set, we will not save any dialing event.
|
|
DialSaver *tracex.Saver
|
|
|
|
// Logger is the optional logger. If not set, there
|
|
// will be no logging from the new dialer.
|
|
Logger model.DebugLogger
|
|
|
|
// ProxyURL is the optional proxy URL.
|
|
ProxyURL *url.URL
|
|
|
|
// ReadWriteSaver is like DialSaver but for I/O events.
|
|
ReadWriteSaver *tracex.Saver
|
|
}
|
|
|
|
// newDialer creates a new Dialer from the specified config and resolver.
|
|
func newDialer(config *dialerConfig, resolver model.Resolver) model.Dialer {
|
|
var logger model.DebugLogger = model.DiscardLogger
|
|
if config.Logger != nil {
|
|
logger = config.Logger
|
|
}
|
|
d := netxlite.NewDialerWithResolver(
|
|
logger, resolver, config.DialSaver.NewConnectObserver(),
|
|
config.ReadWriteSaver.NewReadWriteObserver(),
|
|
)
|
|
d = &netxlite.MaybeProxyDialer{ProxyURL: config.ProxyURL, Dialer: d}
|
|
if config.ContextByteCounting {
|
|
d = &bytecounter.ContextAwareDialer{Dialer: d}
|
|
}
|
|
return d
|
|
}
|