refactor(netxlite): hide details without breaking the rest of the tree (#454)
## Description This PR continues the refactoring of `netx` under the following principles: 1. do not break the rest of the tree and do not engage in extensive tree-wide refactoring yet 2. move under `netxlite` clearly related subpackages (e.g., `iox`, `netxmocks`) 3. move into `internal/netxlite/internal` stuff that is clearly private of `netxlite` 4. hide implementation details in `netxlite` pending new factories 5. refactor `tls` code in `netxlite` to clearly separate `crypto/tls` code from `utls` code After each commit, I run `go test -short -race ./...` locally. Each individual commit explains what it does. I will squash, but this operation will preserve the original commit titles, so this will give further insight on each step. ## Commits * refactor: rename netxmocks -> netxlite/mocks Part of https://github.com/ooni/probe/issues/1591 * refactor: rename quicx -> netxlite/quicx See https://github.com/ooni/probe/issues/1591 * refactor: rename iox -> netxlite/iox Regenerate sources and make sure the tests pass. See https://github.com/ooni/probe/issues/1591. * refactor(iox): move MockableReader to netxlite/mocks See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): generator is an implementation detail See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): separate tls and utls code See https://github.com/ooni/probe/issues/1591 * refactor(netxlite): hide most types but keep old names as legacy With this change we avoid breaking the rest of the tree, but we start hiding some implementation details a bit. Factories will follow. See https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
ae799c4942
commit
2e0118d1a6
137 changed files with 1244 additions and 1173 deletions
|
|
@ -12,17 +12,17 @@ type Dialer interface {
|
|||
DialContext(ctx context.Context, network, address string) (net.Conn, error)
|
||||
}
|
||||
|
||||
// DefaultDialer is the Dialer we use by default.
|
||||
var DefaultDialer = &net.Dialer{
|
||||
// defaultDialer is the Dialer we use by default.
|
||||
var defaultDialer = &net.Dialer{
|
||||
Timeout: 15 * time.Second,
|
||||
KeepAlive: 15 * time.Second,
|
||||
}
|
||||
|
||||
var _ Dialer = DefaultDialer
|
||||
var _ Dialer = defaultDialer
|
||||
|
||||
// DialerResolver is a dialer that uses the configured Resolver to resolver a
|
||||
// dialerResolver is a dialer that uses the configured Resolver to resolver a
|
||||
// domain name to IP addresses, and the configured Dialer to connect.
|
||||
type DialerResolver struct {
|
||||
type dialerResolver struct {
|
||||
// Dialer is the underlying Dialer.
|
||||
Dialer Dialer
|
||||
|
||||
|
|
@ -30,10 +30,10 @@ type DialerResolver struct {
|
|||
Resolver Resolver
|
||||
}
|
||||
|
||||
var _ Dialer = &DialerResolver{}
|
||||
var _ Dialer = &dialerResolver{}
|
||||
|
||||
// DialContext implements Dialer.DialContext.
|
||||
func (d *DialerResolver) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
func (d *dialerResolver) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
onlyhost, onlyport, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -59,15 +59,15 @@ func (d *DialerResolver) DialContext(ctx context.Context, network, address strin
|
|||
}
|
||||
|
||||
// lookupHost performs a domain name resolution.
|
||||
func (d *DialerResolver) lookupHost(ctx context.Context, hostname string) ([]string, error) {
|
||||
func (d *dialerResolver) lookupHost(ctx context.Context, hostname string) ([]string, error) {
|
||||
if net.ParseIP(hostname) != nil {
|
||||
return []string{hostname}, nil
|
||||
}
|
||||
return d.Resolver.LookupHost(ctx, hostname)
|
||||
}
|
||||
|
||||
// DialerLogger is a Dialer with logging.
|
||||
type DialerLogger struct {
|
||||
// dialerLogger is a Dialer with logging.
|
||||
type dialerLogger struct {
|
||||
// Dialer is the underlying dialer.
|
||||
Dialer Dialer
|
||||
|
||||
|
|
@ -75,10 +75,10 @@ type DialerLogger struct {
|
|||
Logger Logger
|
||||
}
|
||||
|
||||
var _ Dialer = &DialerLogger{}
|
||||
var _ Dialer = &dialerLogger{}
|
||||
|
||||
// DialContext implements Dialer.DialContext
|
||||
func (d *DialerLogger) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
func (d *dialerLogger) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d.Logger.Debugf("dial %s/%s...", address, network)
|
||||
start := time.Now()
|
||||
conn, err := d.Dialer.DialContext(ctx, network, address)
|
||||
|
|
|
|||
Loading…
Reference in a new issue