4eeadd06a5
* refactor: move more commands to internal/cmd Part of https://github.com/ooni/probe/issues/1335. We would like all commands to be at the same level of engine rather than inside engine (now that we can do it). * fix: update .gitignore * refactor: also move jafar outside engine * We should be good now?
43 lines
989 B
Go
43 lines
989 B
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
|
)
|
|
|
|
// CtrlTCPResult is the result of the TCP check performed by the test helper.
|
|
type CtrlTCPResult = webconnectivity.ControlTCPConnectResult
|
|
|
|
// TCPResultPair contains the endpoint and the corresponding result.
|
|
type TCPResultPair struct {
|
|
Endpoint string
|
|
Result CtrlTCPResult
|
|
}
|
|
|
|
// TCPConfig configures the TCP connect check.
|
|
type TCPConfig struct {
|
|
Dialer netx.Dialer
|
|
Endpoint string
|
|
Out chan TCPResultPair
|
|
Wg *sync.WaitGroup
|
|
}
|
|
|
|
// TCPDo performs the TCP check.
|
|
func TCPDo(ctx context.Context, config *TCPConfig) {
|
|
defer config.Wg.Done()
|
|
conn, err := config.Dialer.DialContext(ctx, "tcp", config.Endpoint)
|
|
if conn != nil {
|
|
conn.Close()
|
|
}
|
|
config.Out <- TCPResultPair{
|
|
Endpoint: config.Endpoint,
|
|
Result: CtrlTCPResult{
|
|
Failure: newfailure(err),
|
|
Status: err == nil,
|
|
},
|
|
}
|
|
}
|