...
1
2
3
4
5
6
7
8
9
10 package topology
11
12 import (
13 "context"
14 "crypto/tls"
15 "net"
16 )
17
18 type tlsConn interface {
19 net.Conn
20
21
22 Handshake() error
23 ConnectionState() tls.ConnectionState
24 }
25
26 var _ tlsConn = (*tls.Conn)(nil)
27
28 type tlsConnectionSource interface {
29 Client(net.Conn, *tls.Config) tlsConn
30 }
31
32 type tlsConnectionSourceFn func(net.Conn, *tls.Config) tlsConn
33
34 var _ tlsConnectionSource = (tlsConnectionSourceFn)(nil)
35
36 func (t tlsConnectionSourceFn) Client(nc net.Conn, cfg *tls.Config) tlsConn {
37 return t(nc, cfg)
38 }
39
40 var defaultTLSConnectionSource tlsConnectionSourceFn = func(nc net.Conn, cfg *tls.Config) tlsConn {
41 return tls.Client(nc, cfg)
42 }
43
44
45
46 func clientHandshake(ctx context.Context, client tlsConn) error {
47 errChan := make(chan error, 1)
48 go func() {
49 errChan <- client.Handshake()
50 }()
51
52 select {
53 case err := <-errChan:
54 return err
55 case <-ctx.Done():
56 return ctx.Err()
57 }
58 }
59
View as plain text