2021-08-17 10:29:06 +02:00
|
|
|
package websteps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TCPConfig struct {
|
2021-09-05 19:55:28 +02:00
|
|
|
Dialer netxlite.DialerLegacy
|
2021-08-17 10:29:06 +02:00
|
|
|
Endpoint string
|
2021-09-05 18:03:50 +02:00
|
|
|
Resolver netxlite.ResolverLegacy
|
2021-08-17 10:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TCPDo performs the TCP check.
|
|
|
|
func TCPDo(ctx context.Context, config TCPConfig) (net.Conn, error) {
|
|
|
|
if config.Dialer != nil {
|
|
|
|
return config.Dialer.DialContext(ctx, "tcp", config.Endpoint)
|
|
|
|
}
|
|
|
|
resolver := config.Resolver
|
|
|
|
if resolver == nil {
|
|
|
|
resolver = &netxlite.ResolverSystem{}
|
|
|
|
}
|
|
|
|
dialer := NewDialerResolver(resolver)
|
|
|
|
return dialer.DialContext(ctx, "tcp", config.Endpoint)
|
|
|
|
}
|