private Connection connectToSsh(Computer computer, PrintStream logger)
      throws RequestUnsuccessfulException, DigitalOceanException {

    final long timeout = TimeUnit2.MINUTES.toMillis(computer.getCloud().getTimeoutMinutes());
    final long startTime = System.currentTimeMillis();
    final int sleepTime = 10;

    long waitTime;

    while ((waitTime = System.currentTimeMillis() - startTime) < timeout) {

      // Hack to fetch this each time through the loop to get the latest information.
      final Droplet droplet =
          DigitalOcean.getDroplet(
              computer.getCloud().getAuthToken(), computer.getNode().getDropletId());

      if (isDropletStarting(droplet)) {
        logger.println(
            "Waiting for droplet to enter ACTIVE state. Sleeping " + sleepTime + " seconds.");
      } else {
        try {
          final String host = getIpAddress(computer);

          if (Strings.isNullOrEmpty(host) || "0.0.0.0".equals(host)) {
            logger.println(
                "No ip address yet, your host is most likely waiting for an ip address.");
          } else {
            int port = computer.getSshPort();

            Connection conn = getDropletConnection(host, port, logger);
            if (conn != null) {
              return conn;
            }
          }
        } catch (IOException e) {
          // Ignore, we'll retry.
        }
        logger.println("Waiting for SSH to come up. Sleeping " + sleepTime + " seconds.");
      }

      sleep(sleepTime);
    }

    throw new RuntimeException(
        format(
            "Timed out after %d seconds of waiting for ssh to become available (max timeout configured is %s)",
            waitTime / 1000, timeout / 1000));
  }