MCPcopy
hub / github.com/passteque/gluetun / tcpTLSCheck

Function tcpTLSCheck

internal/healthcheck/checker.go:189–225  ·  view source on GitHub ↗
(ctx context.Context, dialer *net.Dialer, targetAddress string)

Source from the content-addressed store, hash-verified

187}
188
189func tcpTLSCheck(ctx context.Context, dialer *net.Dialer, targetAddress string) error {
190 // TODO use mullvad API if current provider is Mullvad
191
192 address, err := makeAddressToDial(targetAddress)
193 if err != nil {
194 return err
195 }
196
197 const dialNetwork = "tcp4"
198 connection, err := dialer.DialContext(ctx, dialNetwork, address)
199 if err != nil {
200 return fmt.Errorf("dialing: %w", err)
201 }
202
203 if strings.HasSuffix(address, ":443") {
204 host, _, err := net.SplitHostPort(address)
205 if err != nil {
206 return fmt.Errorf("splitting host and port: %w", err)
207 }
208 tlsConfig := &tls.Config{
209 MinVersion: tls.VersionTLS12,
210 ServerName: host,
211 }
212 tlsConnection := tls.Client(connection, tlsConfig)
213 err = tlsConnection.HandshakeContext(ctx)
214 if err != nil {
215 return fmt.Errorf("running TLS handshake: %w", err)
216 }
217 }
218
219 err = connection.Close()
220 if err != nil {
221 return fmt.Errorf("closing connection: %w", err)
222 }
223
224 return nil
225}
226
227func makeAddressToDial(address string) (addressToDial string, err error) {
228 host, port, err := net.SplitHostPort(address)

Callers 2

fullPeriodicCheckMethod · 0.85
startupCheckMethod · 0.85

Calls 3

makeAddressToDialFunction · 0.85
CloseMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected