2022-06-06 14:27:25 +02:00
|
|
|
package netx
|
|
|
|
|
|
|
|
//
|
|
|
|
// Dialer from Config.
|
|
|
|
//
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/bytecounter"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewDialer creates a new Dialer from the specified config.
|
|
|
|
func NewDialer(config Config) model.Dialer {
|
|
|
|
if config.FullResolver == nil {
|
2022-06-06 15:16:30 +02:00
|
|
|
// TODO(https://github.com/ooni/probe/issues/2121#issuecomment-1147424810)
|
2022-06-06 14:27:25 +02:00
|
|
|
config.FullResolver = NewResolver(config)
|
|
|
|
}
|
|
|
|
logger := model.ValidLoggerOrDefault(config.Logger)
|
|
|
|
d := netxlite.NewDialerWithResolver(
|
|
|
|
logger, config.FullResolver, config.Saver.NewConnectObserver(),
|
|
|
|
config.ReadWriteSaver.NewReadWriteObserver(),
|
|
|
|
)
|
2022-06-08 23:10:06 +02:00
|
|
|
d = netxlite.MaybeWrapWithProxyDialer(d, config.ProxyURL)
|
2022-06-06 14:27:25 +02:00
|
|
|
d = bytecounter.MaybeWrapWithContextAwareDialer(config.ContextByteCounting, d)
|
|
|
|
return d
|
|
|
|
}
|