forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialer.go
27 lines (24 loc) · 828 Bytes
/
dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 {
// TODO(https://github.com/ooni/probe/issues/2121#issuecomment-1147424810)
config.FullResolver = NewResolver(config)
}
logger := model.ValidLoggerOrDefault(config.Logger)
d := netxlite.NewDialerWithResolver(
logger, config.FullResolver, config.Saver.NewConnectObserver(),
config.ReadWriteSaver.NewReadWriteObserver(),
)
d = netxlite.MaybeWrapWithProxyDialer(d, config.ProxyURL)
d = bytecounter.MaybeWrapWithContextAwareDialer(config.ContextByteCounting, d)
return d
}