MCPcopy
hub / github.com/XTLS/REALITY / dial

Function dial

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

Source from the content-addressed store, hash-verified

592}
593
594func dial(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config) (*Conn, error) {
595 if netDialer.Timeout != 0 {
596 var cancel context.CancelFunc
597 ctx, cancel = context.WithTimeout(ctx, netDialer.Timeout)
598 defer cancel()
599 }
600
601 if !netDialer.Deadline.IsZero() {
602 var cancel context.CancelFunc
603 ctx, cancel = context.WithDeadline(ctx, netDialer.Deadline)
604 defer cancel()
605 }
606
607 rawConn, err := netDialer.DialContext(ctx, network, addr)
608 if err != nil {
609 return nil, err
610 }
611
612 colonPos := strings.LastIndex(addr, ":")
613 if colonPos == -1 {
614 colonPos = len(addr)
615 }
616 hostname := addr[:colonPos]
617
618 if config == nil {
619 config = defaultConfig()
620 }
621 // If no ServerName is set, infer the ServerName
622 // from the hostname we're connecting to.
623 if config.ServerName == "" {
624 // Make a copy to avoid polluting argument or default.
625 c := config.Clone()
626 c.ServerName = hostname
627 config = c
628 }
629
630 conn := Client(rawConn, config)
631 if err := conn.HandshakeContext(ctx); err != nil {
632 rawConn.Close()
633 return nil, err
634 }
635 return conn, nil
636}
637
638// Dial connects to the given network address using net.Dial
639// 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.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…