2021-08-17 10:29:06 +02:00
|
|
|
package websteps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2022-01-07 18:33:37 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-08-17 10:29:06 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TCPConfig struct {
|
2022-01-07 18:33:37 +01:00
|
|
|
Dialer model.Dialer
|
2021-08-17 10:29:06 +02:00
|
|
|
Endpoint string
|
2022-01-07 18:33:37 +01:00
|
|
|
Resolver model.Resolver
|
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)
|
|
|
|
}
|