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)
| 43 | // already been established, this function returns it. Otherwise, a new |
| 44 | // connection is created. |
| 45 | func 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 | // |