Returns nil if initialization succeeded, else the initialization error. Attempts here will be made to connect one tunnel, if successful, it will connect the available tunnels up to config.HAConnections.
( ctx context.Context, connectedSignal *signal.Signal, )
| 203 | // Attempts here will be made to connect one tunnel, if successful, it will |
| 204 | // connect the available tunnels up to config.HAConnections. |
| 205 | func (s *Supervisor) initialize( |
| 206 | ctx context.Context, |
| 207 | connectedSignal *signal.Signal, |
| 208 | ) error { |
| 209 | availableAddrs := s.edgeIPs.AvailableAddrs() |
| 210 | if s.config.HAConnections > availableAddrs { |
| 211 | s.log.Logger().Info().Msgf("You requested %d HA connections but I can give you at most %d.", s.config.HAConnections, availableAddrs) |
| 212 | s.config.HAConnections = availableAddrs |
| 213 | } |
| 214 | s.tunnelsProtocolFallback[0] = &protocolFallback{ |
| 215 | retry.NewBackoff(s.config.Retries, retry.DefaultBaseTime, true), |
| 216 | s.config.ProtocolSelector.Current(), |
| 217 | false, |
| 218 | } |
| 219 | |
| 220 | go s.startFirstTunnel(ctx, connectedSignal) |
| 221 | |
| 222 | // Wait for response from first tunnel before proceeding to attempt other HA edge tunnels |
| 223 | select { |
| 224 | case <-ctx.Done(): |
| 225 | <-s.tunnelErrors |
| 226 | return ctx.Err() |
| 227 | case tunnelError := <-s.tunnelErrors: |
| 228 | return tunnelError.err |
| 229 | case <-s.gracefulShutdownC: |
| 230 | return errEarlyShutdown |
| 231 | case <-connectedSignal.Wait(): |
| 232 | } |
| 233 | |
| 234 | // At least one successful connection, so start the rest |
| 235 | for i := 1; i < s.config.HAConnections; i++ { |
| 236 | s.tunnelsProtocolFallback[i] = &protocolFallback{ |
| 237 | retry.NewBackoff(s.config.Retries, retry.DefaultBaseTime, true), |
| 238 | // Set the protocol we know the first tunnel connected with. |
| 239 | s.tunnelsProtocolFallback[0].protocol, |
| 240 | false, |
| 241 | } |
| 242 | go s.startTunnel(ctx, i, s.newConnectedTunnelSignal(i)) |
| 243 | time.Sleep(registrationInterval) |
| 244 | } |
| 245 | return nil |
| 246 | } |
| 247 | |
| 248 | // startTunnel starts the first tunnel connection. The resulting error will be sent on |
| 249 | // s.tunnelErrors. It will send a signal via connectedSignal if registration succeed |
no test coverage detected