MCPcopy Create free account
hub / github.com/XTLS/Go / dial

Function dial

tls.go:120–162  ·  view source on GitHub ↗
(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config)

Source from the content-addressed store, hash-verified

118}
119
120func dial(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config) (*Conn, error) {
121 if netDialer.Timeout != 0 {
122 var cancel context.CancelFunc
123 ctx, cancel = context.WithTimeout(ctx, netDialer.Timeout)
124 defer cancel()
125 }
126
127 if !netDialer.Deadline.IsZero() {
128 var cancel context.CancelFunc
129 ctx, cancel = context.WithDeadline(ctx, netDialer.Deadline)
130 defer cancel()
131 }
132
133 rawConn, err := netDialer.DialContext(ctx, network, addr)
134 if err != nil {
135 return nil, err
136 }
137
138 colonPos := strings.LastIndex(addr, ":")
139 if colonPos == -1 {
140 colonPos = len(addr)
141 }
142 hostname := addr[:colonPos]
143
144 if config == nil {
145 config = defaultConfig()
146 }
147 // If no ServerName is set, infer the ServerName
148 // from the hostname we're connecting to.
149 if config.ServerName == "" {
150 // Make a copy to avoid polluting argument or default.
151 c := config.Clone()
152 c.ServerName = hostname
153 config = c
154 }
155
156 conn := Client(rawConn, config)
157 if err := conn.HandshakeContext(ctx); err != nil {
158 rawConn.Close()
159 return nil, err
160 }
161 return conn, nil
162}
163
164// Dial connects to the given network address using net.Dial
165// and then initiates a TLS handshake, returning the resulting

Callers 2

DialWithDialerFunction · 0.85
DialContextMethod · 0.85

Calls 6

defaultConfigFunction · 0.85
ClientFunction · 0.85
DialContextMethod · 0.80
CloneMethod · 0.80
HandshakeContextMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…