MCPcopy
hub / github.com/cloudflare/cloudflared / DialEdge

Function DialEdge

edgediscovery/dial.go:13–42  ·  view source on GitHub ↗

DialEdge makes a TLS connection to a Cloudflare edge node

(
	ctx context.Context,
	timeout time.Duration,
	tlsConfig *tls.Config,
	edgeTCPAddr *net.TCPAddr,
	localIP net.IP,
)

Source from the content-addressed store, hash-verified

11
12// DialEdge makes a TLS connection to a Cloudflare edge node
13func DialEdge(
14 ctx context.Context,
15 timeout time.Duration,
16 tlsConfig *tls.Config,
17 edgeTCPAddr *net.TCPAddr,
18 localIP net.IP,
19) (net.Conn, error) {
20 // Inherit from parent context so we can cancel (Ctrl-C) while dialing
21 dialCtx, dialCancel := context.WithTimeout(ctx, timeout)
22 defer dialCancel()
23
24 dialer := net.Dialer{}
25 if localIP != nil {
26 dialer.LocalAddr = &net.TCPAddr{IP: localIP, Port: 0}
27 }
28 edgeConn, err := dialer.DialContext(dialCtx, "tcp", edgeTCPAddr.String())
29 if err != nil {
30 return nil, newDialError(err, "DialContext error")
31 }
32
33 tlsEdgeConn := tls.Client(edgeConn, tlsConfig)
34 tlsEdgeConn.SetDeadline(time.Now().Add(timeout))
35
36 if err = tlsEdgeConn.Handshake(); err != nil {
37 return nil, newDialError(err, "TLS handshake with edge error")
38 }
39 // clear the deadline on the conn; http2 has its own timeouts
40 tlsEdgeConn.SetDeadline(time.Time{})
41 return tlsEdgeConn, nil
42}
43
44// DialError is an error returned from DialEdge
45type DialError struct {

Callers 1

serveConnectionMethod · 0.92

Calls 6

newDialErrorFunction · 0.85
DialContextMethod · 0.65
StringMethod · 0.65
AddMethod · 0.65
ClientMethod · 0.45
SetDeadlineMethod · 0.45

Tested by

no test coverage detected