MCPcopy
hub / github.com/sourcegraph/checkup / doChecks

Method doChecks

check/tcp/tcp.go:83–133  ·  view source on GitHub ↗

doChecks executes and returns each attempt.

()

Source from the content-addressed store, hash-verified

81
82// doChecks executes and returns each attempt.
83func (c Checker) doChecks() types.Attempts {
84 var err error
85 var conn net.Conn
86
87 timeout := c.Timeout
88 if timeout == 0 {
89 timeout = 1 * time.Second
90 }
91
92 checks := make(types.Attempts, c.Attempts)
93 for i := 0; i < c.Attempts; i++ {
94 start := time.Now()
95
96 if c.TLSEnabled {
97 // Dialer with timeout
98 dialer := &net.Dialer{
99 Timeout: timeout,
100 }
101
102 // TLS config based on configuration
103 var tlsConfig tls.Config
104 tlsConfig.InsecureSkipVerify = c.TLSSkipVerify
105 if c.TLSCAFile != "" {
106 rootPEM, err := ioutil.ReadFile(c.TLSCAFile)
107 if err != nil || rootPEM == nil {
108 checks[i].Error = "failed to read root certificate"
109 }
110 pool := x509.NewCertPool()
111 ok := pool.AppendCertsFromPEM([]byte(rootPEM))
112 if !ok {
113 checks[i].Error = "failed to parse root certificate"
114 }
115 tlsConfig.RootCAs = pool
116 }
117 if conn, err = tls.DialWithDialer(dialer, "tcp", c.URL, &tlsConfig); err == nil {
118 conn.Close()
119 }
120 } else {
121 if conn, err = net.DialTimeout("tcp", c.URL, timeout); err == nil {
122 conn.Close()
123 }
124 }
125
126 checks[i].RTT = time.Since(start)
127 if err != nil {
128 checks[i].Error = err.Error()
129 continue
130 }
131 }
132 return checks
133}
134
135// conclude takes the data in result from the attempts and
136// computes remaining values needed to fill out the result.

Callers 1

CheckMethod · 0.95

Implementers 6

fakecheckup_test.go
Checkercheck/http/http.go
Checkercheck/dns/dns.go
Checkercheck/exec/exec.go
Checkercheck/tls/tls.go
Checkercheck/tcp/tcp.go

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected