MCPcopy
hub / github.com/grpc/grpc-go / Dial

Function Dial

credentials/alts/internal/handshaker/service/service.go:45–73  ·  view source on GitHub ↗

Dial dials the handshake service in the hypervisor. If a connection has already been established, this function returns it. Otherwise, a new connection is created.

(hsAddress string)

Source from the content-addressed store, hash-verified

43// already been established, this function returns it. Otherwise, a new
44// connection is created.
45func Dial(hsAddress string) (*grpc.ClientConn, error) {
46 mu.Lock()
47 defer mu.Unlock()
48
49 hsConn, ok := hsConnMap[hsAddress]
50 if !ok {
51 // Create a new connection to the handshaker service. Note that
52 // this connection stays open until the application is closed.
53 // Disable the service config to avoid unnecessary TXT record lookups that
54 // cause timeouts with some versions of systemd-resolved.
55 var err error
56 opts := []grpc.DialOption{
57 grpc.WithTransportCredentials(insecure.NewCredentials()),
58 grpc.WithDisableServiceConfig(),
59 }
60 if envconfig.ALTSHandshakerKeepaliveParams {
61 opts = append(opts, grpc.WithKeepaliveParams(keepalive.ClientParameters{
62 Timeout: 10 * time.Second,
63 Time: 10 * time.Minute,
64 }))
65 }
66 hsConn, err = grpc.NewClient(hsAddress, opts...)
67 if err != nil {
68 return nil, err
69 }
70 hsConnMap[hsAddress] = hsConn
71 }
72 return hsConn, nil
73}
74
75// CloseForTesting closes all open connections to the handshaker service.
76//

Callers 3

ClientHandshakeMethod · 0.92
ServerHandshakeMethod · 0.92
TestDialMethod · 0.70

Calls 7

WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithDisableServiceConfigFunction · 0.92
WithKeepaliveParamsFunction · 0.92
NewClientFunction · 0.92
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestDialMethod · 0.56