public static void estimateKeyDerivationTime() {
   // This is run in the background after startup. If we haven't recorded it before, do a key
   // derivation to see
   // how long it takes. This helps us produce better progress feedback, as on Windows we don't
   // currently have a
   // native Scrypt impl and the Java version is ~3 times slower, plus it depends a lot on CPU
   // speed.
   checkGuiThread();
   estimatedKeyDerivationTime = Main.instance.prefs.getExpectedKeyDerivationTime();
   if (estimatedKeyDerivationTime == null) {
     new Thread(
             () -> {
               log.info("Doing background test key derivation");
               KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS);
               long start = System.currentTimeMillis();
               scrypt.deriveKey("test password");
               long msec = System.currentTimeMillis() - start;
               log.info("Background test key derivation took {}msec", msec);
               Platform.runLater(
                   () -> {
                     estimatedKeyDerivationTime = Duration.ofMillis(msec);
                     Main.instance.prefs.setExpectedKeyDerivationTime(estimatedKeyDerivationTime);
                   });
             })
         .start();
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    DecimalFormat decimalFormat = new DecimalFormat("00");
    System.out.println(decimalFormat.format(7));

    //        f3();

    Instant timestamp = Instant.ofEpochMilli(System.currentTimeMillis());
    System.out.println(timestamp);

    Instant current = Clock.system(ZoneId.of("Asia/Shanghai")).instant();
    System.out.println(ZoneId.of("Asia/Shanghai").getRules());
    System.out.println(current);
    //        System.out.println(System.currentTimeMillis());
    //        System.out.println(Instant.now().getEpochSecond());
  }
  public static ZonedDateTime getNextSchedule() {
    ZonedDateTime next_schedule;

    // Determine type of schedule
    if (ConfigHandler.backupInterval > 0) // Interval
    {
      next_schedule =
          ZonedDateTime.ofInstant(
              Instant.ofEpochMilli(
                  System.currentTimeMillis() + (ConfigHandler.backupInterval * 60 * 1000)),
              ZoneId.systemDefault());
    } else // Schedule
    {
      if (ConfigHandler.backupSchedule.length == 0) {
        return null;
      }

      LocalTime now = LocalTime.now();
      LocalTime next_time = null;
      LocalDate day = LocalDate.now();
      TreeSet<LocalTime> times = new TreeSet<>();

      for (String s : ConfigHandler.backupSchedule) {
        times.add(LocalTime.parse(s, DateTimeFormatter.ofPattern("H:mm")));
      }

      for (LocalTime t : times) // try to find next scheduled time for today
      {
        if (t.compareTo(now) == 1) {
          next_time = t;
          break;
        }
      }

      if (next_time
          == null) // if we couldn't find one for today take the first schedule time for tomorrow
      {
        day = day.plusDays(1);
        next_time = times.first();
      }

      next_schedule = ZonedDateTime.of(day, next_time, ZoneId.systemDefault());
    }

    return next_schedule;
  }